You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/misc/action_cable_protocol.md
+92-5Lines changed: 92 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,7 +168,7 @@ Usually, in this case we can only specify the `since` parameter.
168
168
169
169
In response, the server MUST first confirm the subscription and then execute the history request. If the subscription is rejected, no history request is made.
170
170
171
-
### New message types
171
+
### New message types: `confirm_history` and `reject_history`
172
172
173
173
Two new message types (server-client) are added:
174
174
@@ -177,7 +177,7 @@ Two new message types (server-client) are added:
177
177
178
178
Both messages act as acknowledgments for the `history` command and contain the `identifier` key. The `confirm_history` message is sent to the client to indicate that the requested historical messages for the channel have been successfully sent to the client. The `reject_history` indicates that the server failed to retrieve the requested messages and no historical message have been sent (the client must implement a fallback mechanism to restore the consistency).
179
179
180
-
### Incoming messages extensions
180
+
### History metadata in broadcasted messages
181
181
182
182
Broadcasted messages MAY contain metadata regarding their position in the stream. This information MUST be used with the subsequent `history` requests:
183
183
@@ -195,9 +195,9 @@ Broadcasted messages MAY contain metadata regarding their position in the stream
195
195
}
196
196
```
197
197
198
-
**NOTE:**The messages are not guaranteed to be in order (due to concurrent broadcasts), so, offsets may be non-monotonic. It's the client responsibility to keep track of offsets. Also, there is a small chance that the same message may arrive twice (from broadcast and from the history); to provide exactly-once delivery guarantees, the client MUST keep track of seen offsets and ignore duplicates.
198
+
**NOTE:**Offsets are assumed to be in order (however, some history backends may lift this requirement, check the corresponding documentation). There is a small chance that the same message may arrive twice (from broadcast and from the history); to provide exactly-once delivery guarantees, the client MUST keep track of seen offsets and ignore duplicates.
199
199
200
-
### Handshake extensions
200
+
### Handshake metadata
201
201
202
202
During the handshake, the server MAY send a unique _session id_ along with the welcome message:
203
203
@@ -231,7 +231,7 @@ The optional `restored_ids` field contains the list of channel identifiers that
231
231
232
232
The `pong` command MAY be sent in response to the `ping` message if the server requires pongs. It could be used to improve broken connections detection.
233
233
234
-
### New command: `whisper` <imgclass='pro-badge'src='/assets/new.svg'alt='new' />
234
+
### New command: `whisper`
235
235
236
236
The `whisper` can be used to publish broadcast messages from the client (if the whisper stream has been configured for it) to a particular _channel_.
237
237
@@ -253,3 +253,90 @@ For example:
253
253
```
254
254
255
255
**IMPORTANT**: Unlike actions (`message` command), the data is not JSON-serialized. It's broadcasted to connected clients as is.
256
+
257
+
### New commands: `join` and `leave`
258
+
259
+
Presence commands allow the client to join or leave the presence set for a given channel:
260
+
261
+
```js
262
+
{
263
+
"command":"join",
264
+
"identifier":"<subscription identifier>",
265
+
"presence": {
266
+
"id":"<user id within the presence set>",
267
+
"info":"..."// any object or string
268
+
}
269
+
}
270
+
271
+
{
272
+
"command":"leave",
273
+
"identifier":"<subscription identifier>",
274
+
"presence": {
275
+
"id":"<user id within the presence set>"
276
+
}
277
+
}
278
+
```
279
+
280
+
### New commands: `presence`
281
+
282
+
The presence command is used to request the current presence state for a given channel:
283
+
284
+
```js
285
+
{
286
+
"command":"presence",
287
+
"identifier":"<subscription identifier>",
288
+
}
289
+
```
290
+
291
+
You can also provide the "data" field with some configuration options:
292
+
293
+
```js
294
+
{
295
+
"command":"presence",
296
+
"identifier":"<subscription identifier>",
297
+
"data": {
298
+
"return_records":true// set to false to return only totals, see below
299
+
}
300
+
}
301
+
```
302
+
303
+
### New message type: `presence`
304
+
305
+
Presence messages have the following formats:
306
+
307
+
```js
308
+
{
309
+
"type":"presence",
310
+
"identifier":"<subscription identifier>",
311
+
"message": {
312
+
"id":"<user id within the presence set>",
313
+
"info":"..."// any object or string
314
+
"type":"join"
315
+
}
316
+
}
317
+
318
+
{
319
+
"type":"presence",
320
+
"identifier":"<subscription identifier>",
321
+
"message": {
322
+
"id":"<user id within the presence set>",
323
+
"type":"leave"
324
+
}
325
+
}
326
+
327
+
{
328
+
"type":"presence",
329
+
"identifier":"<subscription identifier>",
330
+
"message": {
331
+
"total":123, // total number of present users
332
+
"records": [
333
+
{
334
+
"id":"...",
335
+
"info":"..."
336
+
},
337
+
...
338
+
], # presence records (missing if return_records is false)
0 commit comments