Skip to content

Commit 66505d9

Browse files
committed
fixup! annotations: publish, subscribe, summary and type
1 parent 28709b1 commit 66505d9

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/pages/docs/messages/annotations.mdx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ The value of the `summary` field is an object where the keys are the [annotation
216216

217217
<Code>
218218
```javascript
219+
// Create an Ably Realtime client specifying the clientId that will
220+
// be associated with annotations published by this client
221+
const realtime = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-client-id' });
222+
223+
// Create a channel in a namespace called `annotations`
224+
// which has message annotations enabled
225+
const channel = realtime.channels.get('annotations:example');
226+
219227
await channel.subscribe((message) => {
220228
if (message.action === 'message.summary') {
221229
console.log(message.summary);
@@ -224,6 +232,14 @@ await channel.subscribe((message) => {
224232
```
225233

226234
```nodejs
235+
// Create an Ably Realtime client specifying the clientId that will
236+
// be associated with annotations published by this client
237+
const realtime = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-client-id' });
238+
239+
// Create a channel in a namespace called `annotations`
240+
// which has message annotations enabled
241+
const channel = realtime.channels.get('annotations:example');
242+
227243
await channel.subscribe((message) => {
228244
if (message.action === 'message.summary') {
229245
console.log(message.summary);
@@ -240,12 +256,21 @@ For more details on summary structure and usage, see [annotation summaries](#ann
240256

241257
### Subscribing to individual annotations <a id="subscribe-individual-annotations" />
242258

243-
For more fine-grained visibility, you can also subscribe directly to individual annotation events using the `annotations.subscribe()` method on a channel.
259+
For more fine-grained visibility, you can also subscribe directly to individual annotation events using the `annotations.subscribe()` method on a channel. To subscribe to individual annotations, you must request the `ANNOTATION_SUBSCRIBE` [mode](/docs/channels/options#modes).
244260

245261
Annotations delivered to the `annotations.subscribe()` listener will have an `action` of `annotation.create` or `annotation.delete`.
246262

247263
<Code>
248264
```javascript
265+
// Create an Ably Realtime client specifying the clientId that will
266+
// be associated with annotations published by this client
267+
const realtime = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-client-id' });
268+
269+
// Create a channel in a namespace called `annotations`
270+
// which has message annotations enabled.
271+
// Specify the ANNOTATION_SUBSCRIBE mode to enable annotation subscriptions.
272+
const channel = realtime.channels.get('annotations:example', { modes: ['ANNOTATION_SUBSCRIBE'] });
273+
249274
await channel.annotations.subscribe((annotation) => {
250275
if (annotation.action === 'annotation.create') {
251276
console.log(`New ${annotation.type} annotation with name ${annotation.name} from ${annotation.clientId}`);
@@ -256,6 +281,15 @@ await channel.annotations.subscribe((annotation) => {
256281
```
257282

258283
```nodejs
284+
// Create an Ably Realtime client specifying the clientId that will
285+
// be associated with annotations published by this client
286+
const realtime = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-client-id' });
287+
288+
// Create a channel in a namespace called `annotations`
289+
// which has message annotations enabled.
290+
// Specify the ANNOTATION_SUBSCRIBE mode to enable annotation subscriptions.
291+
const channel = realtime.channels.get('annotations:example', { modes: ['ANNOTATION_SUBSCRIBE'] });
292+
259293
await channel.annotations.subscribe((annotation) => {
260294
if (annotation.action === 'annotation.create') {
261295
console.log(`New ${annotation.type} annotation with name ${annotation.name} from ${annotation.clientId}`);

0 commit comments

Comments
 (0)