collab_client: Pass raw message to handleClientMessage_* hooks

This commit is contained in:
Richard Hansen 2021-12-05 22:32:27 -05:00
parent 9b7108d730
commit 5fe5a87c85
3 changed files with 10 additions and 7 deletions

View file

@ -55,6 +55,8 @@
* New APIs for processing attributes: `ep_etherpad-lite/static/js/attributes` * New APIs for processing attributes: `ep_etherpad-lite/static/js/attributes`
(low-level API) and `ep_etherpad-lite/static/js/AttributeMap` (high-level (low-level API) and `ep_etherpad-lite/static/js/AttributeMap` (high-level
API). API).
* The `handleClientMessage_${name}` client-side hooks are now passed the raw
message object in the new `msg` context property.
* The `import` server-side hook has a new `ImportError` context property. * The `import` server-side hook has a new `ImportError` context property.
* New `exportEtherpad` and `importEtherpad` server-side hooks. * New `exportEtherpad` and `importEtherpad` server-side hooks.
* The `handleMessageSecurity` and `handleMessage` server-side hooks have a new * The `handleMessageSecurity` and `handleMessage` server-side hooks have a new

View file

@ -393,15 +393,10 @@ This hook is called after the content of a node is collected by the usual
methods. The cc object can be used to do a bunch of things that modify the methods. The cc object can be used to do a bunch of things that modify the
content of the pad. See, for example, the heading1 plugin for etherpad original. content of the pad. See, for example, the heading1 plugin for etherpad original.
## handleClientMessage_`name` ## `handleClientMessage_${name}`
Called from: `src/static/js/collab_client.js` Called from: `src/static/js/collab_client.js`
Things in context:
1. payload - the data that got sent with the message (use it for custom message
content)
This hook gets called every time the client receives a message of type `name`. This hook gets called every time the client receives a message of type `name`.
This can most notably be used with the new HTTP API call, "sendClientsMessage", This can most notably be used with the new HTTP API call, "sendClientsMessage",
which sends a custom message type to all clients connected to a pad. You can which sends a custom message type to all clients connected to a pad. You can
@ -410,6 +405,12 @@ also use this to handle existing types.
`collab_client.js` has a pretty extensive list of message types, if you want to `collab_client.js` has a pretty extensive list of message types, if you want to
take a look. take a look.
Context properties:
* `msg`: The raw message object.
* `payload`: The data that got sent with the message. Usually this is
`msg.payload`.
## aceStartLineAndCharForPoint-aceEndLineAndCharForPoint ## aceStartLineAndCharForPoint-aceEndLineAndCharForPoint
Called from: src/static/js/ace2_inner.js Called from: src/static/js/ace2_inner.js

View file

@ -300,7 +300,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
// Similar for NEW_CHANGES // Similar for NEW_CHANGES
if (msg.type === 'NEW_CHANGES') msg.payload = msg; if (msg.type === 'NEW_CHANGES') msg.payload = msg;
hooks.callAll(`handleClientMessage_${msg.type}`, {payload: msg.payload}); hooks.callAll(`handleClientMessage_${msg.type}`, {msg, payload: msg.payload});
}; };
const updateUserInfo = (userInfo) => { const updateUserInfo = (userInfo) => {