Skip to content

Commit 829b3a4

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/pages/docs/messages/annotations.mdx

Lines changed: 34 additions & 0 deletions
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);
@@ -246,6 +262,15 @@ Annotations delivered to the `annotations.subscribe()` listener will have an `ac
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)