mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Merge pull request #1358 from mluto/clientvars-hook
Make the creation of clientVars hookable
This commit is contained in:
commit
5eb09f981b
2 changed files with 101 additions and 69 deletions
|
@ -175,6 +175,27 @@ function handleMessage ( hook, context, callback ) {
|
|||
};
|
||||
```
|
||||
|
||||
## clientVars
|
||||
Called from: src/node/handler/PadMessageHandler.js
|
||||
|
||||
Things in context:
|
||||
|
||||
1. clientVars - the basic `clientVars` built by the core
|
||||
2. pad - the pad this session is about
|
||||
|
||||
This hook will be called once a client connects and the `clientVars` are being sent. Plugins can use this hook to give the client a initial configuriation, like the tracking-id of an external analytics-tool that is used on the client-side. You can also overwrite values from the original `clientVars`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
exports.clientVars = function(hook, context, callback)
|
||||
{
|
||||
// tell the client which year we are in
|
||||
return callback({ "currentYear": new Date().getFullYear() });
|
||||
};
|
||||
```
|
||||
|
||||
This can be accessed on the client-side using `clientVars.currentYear`.
|
||||
|
||||
## getLineHTMLForExport
|
||||
Called from: src/node/utils/ExportHtml.js
|
||||
|
|
|
@ -991,6 +991,15 @@ function handleClientReady(client, message)
|
|||
//Saves in pad2sessions that this session belongs to this pad
|
||||
pad2sessions[padIds.padId].push(client.id);
|
||||
|
||||
//If this is a reconnect, we don't have to send the client the ClientVars again
|
||||
if(message.reconnect == true)
|
||||
{
|
||||
//Save the revision in sessioninfos, we take the revision from the info the client send to us
|
||||
sessioninfos[client.id].rev = message.client_rev;
|
||||
}
|
||||
//This is a normal first connect
|
||||
else
|
||||
{
|
||||
//prepare all values for the wire
|
||||
var atext = Changeset.cloneAText(pad.atext);
|
||||
var attribsForWire = Changeset.prepareForWire(atext.attribs, pad.pool);
|
||||
|
@ -1012,7 +1021,6 @@ function handleClientReady(client, message)
|
|||
"collab_client_vars": {
|
||||
"initialAttributedText": atext,
|
||||
"clientIp": "127.0.0.1",
|
||||
//"clientAgent": "Anonymous Agent",
|
||||
"padId": message.padId,
|
||||
"historicalAuthorData": historicalAuthorData,
|
||||
"apool": apool,
|
||||
|
@ -1055,19 +1063,22 @@ function handleClientReady(client, message)
|
|||
clientVars.userName = authorName;
|
||||
}
|
||||
|
||||
//If this is a reconnect, we don't have to send the client the ClientVars again
|
||||
if(message.reconnect == true)
|
||||
{
|
||||
//Save the revision in sessioninfos, we take the revision from the info the client send to us
|
||||
sessioninfos[client.id].rev = message.client_rev;
|
||||
//call the clientVars-hook so plugins can modify them before they get sent to the client
|
||||
hooks.aCallAll("clientVars", { clientVars: clientVars, pad: pad }, function ( err, messages ) {
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
_.each(messages, function(newVars) {
|
||||
//combine our old object with the new attributes from the hook
|
||||
for(var attr in newVars) {
|
||||
clientVars[attr] = newVars[attr];
|
||||
}
|
||||
//This is a normal first connect
|
||||
else
|
||||
{
|
||||
});
|
||||
|
||||
//Send the clientVars to the Client
|
||||
client.json.send({type: "CLIENT_VARS", data: clientVars});
|
||||
//Save the current revision in sessioninfos, should be the same as in clientVars
|
||||
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
||||
});
|
||||
}
|
||||
|
||||
sessioninfos[client.id].author = author;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue