Skip to content

Commit 092fca7

Browse files
committed
Consolidate docstring comments for Cursors
1 parent 7b3d121 commit 092fca7

File tree

1 file changed

+33
-233
lines changed

1 file changed

+33
-233
lines changed

src/Cursors.ts

Lines changed: 33 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { RealtimeMessage } from './utilities/types.js';
1212
import { ERR_NOT_ENTERED_SPACE } from './Errors.js';
1313

1414
/**
15-
* The property names of `CursorsEventMap` are the names of the events emitted by { @link Cursors }.
15+
* The property names of `CursorsEventMap` are the names of the events emitted by {@link Cursors}.
1616
*/
1717
export interface CursorsEventMap {
1818
/**
@@ -24,48 +24,25 @@ export interface CursorsEventMap {
2424
const CURSORS_CHANNEL_TAG = '::$cursors';
2525

2626
/**
27-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L9-L17) -->
28-
* The live cursors feature enables you to track the cursors of members within a space in realtime.
27+
* [Live cursors](https://ably.com/docs/spaces/cursors) enable you to track the cursors of members within a {@link Space | space} in realtime.
2928
*
3029
* Cursor events are emitted whenever a member moves their mouse within a space. In order to optimize the efficiency and frequency of updates, cursor position events are automatically batched. The batching interval may be customized in order to further optimize for increased performance versus the number of events published.
3130
*
3231
* Live cursor updates are not available as part of the {@link Space.subscribe | space state} and must be subscribed to using {@link Cursors.subscribe | `space.cursors.subscribe()`}.
3332
*
34-
* > **Important**
35-
* >
36-
* > Live cursors are a great way of providing contextual awareness as to what members are looking at within an application. However, too many cursors moving across a page can often be a distraction rather than an enhancement. As such, Ably recommends a maximum of 20 members simultaneously streaming their cursors in a space at any one time for an optimal end-user experience.
37-
*
38-
* <!-- END WEBSITE DOCUMENTATION -->
39-
*
40-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L254-L262) -->
41-
* ## Live cursor foundations
42-
*
43-
* The Spaces SDK is built upon existing Ably functionality available in Ably’s Core SDKs. Understanding which core features are used to provide the abstractions in the Spaces SDK enables you to manage space state and build additional functionality into your application.
44-
*
45-
* Live cursors build upon the functionality of the Pub/Sub Channels [presence](https://ably.com/docs/presence-occupancy/presence) feature.
46-
*
47-
* Due to the high frequency at which updates are streamed for cursor movements, live cursors utilizes its own [channel](https://ably.com/docs/channels). The other features of the Spaces SDK, such as avatar stacks, member locations and component locking all share a single channel. For this same reason, cursor position updates are not included in the {@link Space.subscribe | space state } and may only be subscribed to via the {@link Space.cursors | `cursors` } property.
48-
*
49-
* The channel is only created when a member calls `space.cursors.set()`. The live cursors channel object can be accessed through `space.cursors.channel`. To monitor the [underlying state of the cursors channel](https://ably.com/docs/channels#states), the channel object can be accessed through `space.cursors.channel`.
50-
*
51-
* <!-- END WEBSITE DOCUMENTATION -->
52-
*
53-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
54-
* Handles tracking of member cursors within a space. Inherits from {@link EventEmitter}.
55-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
5633
*/
5734
export default class Cursors extends EventEmitter<CursorsEventMap> {
5835
private readonly cursorBatching: CursorBatching;
5936
private readonly cursorDispensing: CursorDispensing;
6037
private readonly cursorHistory: CursorHistory;
6138
/**
62-
* The {@link SpaceOptions.cursors | cursors options} passed to {@link default.get | `Spaces.get()`}, with default values filled in.
39+
* The {@link SpaceOptions.cursors | cursors options} passed to {@link default.get | `Spaces.get()`}.
6340
*/
6441
readonly options: CursorsOptions;
6542
private readonly channelName: string;
6643

6744
/**
68-
* The [ably-js](https://github.com/ably/ably-js) realtime channel instance that this `Cursors` instance uses for transmitting and receiving data.
45+
* The [realtime channel](https://ably.com/docs/channels) instance that this `Cursors` instance uses for transmitting and receiving data.
6946
*/
7047
public channel?: Types.RealtimeChannelPromise;
7148

@@ -84,32 +61,13 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
8461
}
8562

8663
/**
87-
* Schedules a cursor update event to be sent that will cause the following events to fire
64+
* Set the position of a member's cursor and emit an {@link CursorUpdate | `update`} event.
8865
*
89-
* @return {void}
90-
*
91-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L21-L74) -->
92-
* Set the position of a member’s cursor using the `set()` method. A position must contain an X-axis value and a Y-axis value to set the cursor position on a 2D plane. Calling `set()` will emit a cursor event so that other members are informed of the cursor movement in realtime.
93-
*
94-
* A member must have been { @link Space.enter | entered } into the space to set their cursor position.
95-
*
96-
* The `set()` method takes the following parameters:
66+
* A position must contain an X-axis value and a Y-axis value to set the cursor position on a 2D plane. Data may optionally be passed containing additional information such as the color the cursor should be displayed as, or the ID of the element the member is dragging.
9767
*
98-
* | Parameter | Description | Type |
99-
* |------------|---------------------------------------------------------------------------------------------------------------------|--------|
100-
* | position.x | The position of the member’s cursor on the X-axis. | Number |
101-
* | position.y | The position of the member’s cursor on the Y-axis. | Number |
102-
* | data | An optional arbitrary JSON-serializable object containing additional information about the cursor, such as a color. | Object |
68+
* A member must have been {@link Space.enter | entered} into the space to set their cursor position.
10369
*
104-
* > **Note**
105-
* >
106-
* > The `data` parameter can be used to stream additional information related to a cursor’s movement, such as:
107-
* >
108-
* > - The color that other member’s should display a cursor as.
109-
* > - The ID of an element that a user may be dragging for drag and drop functionality.
110-
* > - Details of any cursor annotations.
111-
* >
112-
* > Be aware that as live cursor updates are batched it is not advisable to publish data unrelated to cursor position in the `data` parameter. Use a [pub/sub channel](https://ably.com/docs/channels) instead.
70+
* @return {void}
11371
*
11472
* The following is an example of a member setting their cursor position by adding an event listener to obtain their cursor coordinates and then publishing their position using the `set()` method:
11573
*
@@ -118,44 +76,6 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
11876
* space.cursors.set({ position: { x: clientX, y: clientY }, data: { color: 'red' } });
11977
* });
12078
* ```
121-
* The following is an example payload of a cursor event. Cursor events are uniquely identifiable by the `connectionId` of a cursor.
122-
*
123-
* ```json
124-
* {
125-
* "hd9743gjDc": {
126-
* "connectionId": "hd9743gjDc",
127-
* "clientId": "clemons#142",
128-
* "position": {
129-
* "x": 864,
130-
* "y": 32
131-
* },
132-
* "data": {
133-
* "color": "red"
134-
* }
135-
* }
136-
* }
137-
* ```
138-
* The following are the properties of a cursor event payload:
139-
*
140-
* > **Moved documentation**
141-
* >
142-
* > This documentation has been moved to {@link CursorUpdate} and {@link CursorPosition}.
143-
*
144-
* <!-- END WEBSITE DOCUMENTATION -->
145-
*
146-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
147-
* Set the position of a cursor. If a member has not yet entered the space, this method will error.
148-
*
149-
* A event payload returned contains an object with 2 properties. `position` is an object with 2 required properties, `x` and `y`. These represent the position of the cursor on a 2D plane. A second optional property, `data` can also be passed. This is an object of any shape and is meant for data associated with the cursor movement (like drag or hover calculation results):
150-
*
151-
* Example usage:
152-
*
153-
* ```ts
154-
* window.addEventListener('mousemove', ({ clientX, clientY }) => {
155-
* space.cursors.set({ position: { x: clientX, y: clientY }, data: { color: "red" } });
156-
* });
157-
* ```
158-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
15979
*
16080
* @param cursor An object describing the cursor update that should be emitted.
16181
*/
@@ -216,12 +136,11 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
216136
/**
217137
* {@label WITH_EVENTS}
218138
*
219-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L78-L90) -->
220-
* Subscribe to cursor events by registering a listener. Cursor events are emitted whenever a member moves their cursor by calling `set()`. Use the `subscribe()` method on the `cursors` object of a space to receive updates.
139+
* Subscribe to cursor events by registering a listener. Cursor events are emitted whenever a member {@link Cursors.set | sets} their cursor position.
221140
*
222141
* > **Note**
223142
* >
224-
* > The rate at which cursor events are published is controlled by the `outboundBatchInterval` property set in the {@link CursorsOptions | cursor options } of a space.
143+
* > The rate at which cursor events are published is controlled by the {@link CursorsOptions.outboundBatchInterval | `outboundBatchInterval`} property set in the `CursorsOptions` of a space.
225144
*
226145
* The following is an example of subscribing to cursor events:
227146
*
@@ -230,24 +149,9 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
230149
* console.log(cursorUpdate);
231150
* });
232151
* ```
233-
* <!-- END WEBSITE DOCUMENTATION -->
234-
*
235-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
236-
* Listen to `CursorUpdate` events. See {@link EventEmitter} for overloaded usage.
237-
*
238-
* Available events:
239-
*
240-
* - ##### **update**
241152
*
242-
* Emits an event when a new cursor position is set. The argument supplied to the event listener is a {@link CursorUpdate}.
243-
*
244-
* ```ts
245-
* space.cursors.subscribe('update', (cursorUpdate: CursorUpdate) => {});
246-
* ```
247-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
248-
*
249-
* @param eventOrEvents The event name or an array of event names.
250-
* @param listener The listener to add.
153+
* @param eventOrEvents An event name, or an array of event names.
154+
* @param listener An event listener.
251155
*
252156
* @typeParam K A type which allows one or more names of the properties of the {@link CursorsEventMap} type.
253157
*/
@@ -256,9 +160,9 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
256160
listener?: EventListener<CursorsEventMap, K>,
257161
): void;
258162
/**
259-
* Behaves the same as { @link subscribe:WITH_EVENTS | the overload which accepts one or more event names }, but subscribes to _all_ events.
163+
* Subscribe to cursor updates by registering a listener for all events.
260164
*
261-
* @param listener The listener to add.
165+
* @param listener An event listener.
262166
*/
263167
subscribe(listener?: EventListener<CursorsEventMap, keyof CursorsEventMap>): void;
264168
subscribe<K extends keyof CursorsEventMap>(
@@ -289,31 +193,16 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
289193
/**
290194
* {@label WITH_EVENTS}
291195
*
292-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L94-L106) -->
293196
* Unsubscribe from cursor events to remove previously registered listeners.
294197
*
295-
* The following is an example of removing a listener for cursor update events:
198+
* The following is an example of removing a listener for cursor {@link CursorUpdate | `update`} events:
296199
*
297200
* ```javascript
298201
* space.cursors.unsubscribe(`update`, listener);
299202
* ```
300-
* Or remove all listeners:
301-
*
302-
* ```javascript
303-
* space.cursors.unsubscribe();
304-
* ```
305-
* <!-- END WEBSITE DOCUMENTATION -->
306-
*
307-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
308-
* Remove all event listeners, all event listeners for an event, or specific listeners. See {@link EventEmitter} for detailed usage.
309-
*
310-
* ```ts
311-
* space.cursors.unsubscribe('update');
312-
* ```
313-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
314203
*
315-
* @param eventOrEvents The event name or an array of event names.
316-
* @param listener The listener to remove.
204+
* @param eventOrEvents An event name, or an array of event names.
205+
* @param listener An event listener.
317206
*
318207
* @typeParam K A type which allows one or more names of the properties of the {@link CursorsEventMap} type.
319208
*/
@@ -322,9 +211,15 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
322211
listener?: EventListener<CursorsEventMap, K>,
323212
): void;
324213
/**
325-
* Behaves the same as { @link unsubscribe:WITH_EVENTS | the overload which accepts one or more event names }, but subscribes to _all_ events.
214+
* Unsubscribe from all events to remove previously registered listeners.
326215
*
327-
* @param listener The listener to remove.
216+
* The following is an example of removing a listener for all events:
217+
*
218+
* ```javascript
219+
* space.cursors.unsubscribe(listener);
220+
* ```
221+
*
222+
* @param listener An event listener.
328223
*/
329224
unsubscribe(listener?: EventListener<CursorsEventMap, keyof CursorsEventMap>): void;
330225
unsubscribe<K extends keyof CursorsEventMap>(
@@ -352,18 +247,14 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
352247
}
353248

354249
/**
355-
* <!-- This is to avoid duplication of the website documentation. -->
356-
* See the documentation for {@link getAll}.
357250
*
358-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
359-
* Get the last `CursorUpdate` object for self.
251+
* Retrieve the cursor position of the current member in a one-off call.
360252
*
361-
* Example:
253+
* The following is an example of retrieving a member's own cursor position:
362254
*
363-
* ```ts
255+
* ```javascript
364256
* const selfPosition = await space.cursors.getSelf();
365257
* ```
366-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
367258
*/
368259
async getSelf(): Promise<CursorUpdate | null> {
369260
const self = await this.space.members.getSelf();
@@ -374,18 +265,13 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
374265
}
375266

376267
/**
377-
* <!-- This is to avoid duplication of the website documentation. -->
378-
* See the documentation for {@link getAll}.
379-
*
380-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
381-
* Get the last `CursorUpdate` object for everyone else but yourself.
268+
* Retrieve the cursor position of all members other than the member themselves in a one-off call.
382269
*
383-
* Example:
270+
* The following is an example of retrieving the cursor positions of all members, except the member themselves:
384271
*
385-
* ```ts
272+
* ```javascript
386273
* const otherPositions = await space.cursors.getOthers();
387274
* ```
388-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
389275
*/
390276
async getOthers(): Promise<Record<string, null | CursorUpdate>> {
391277
const self = await this.space.members.getSelf();
@@ -398,99 +284,13 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
398284
}
399285

400286
/**
401-
* <!-- BEGIN WEBSITE DOCUMENTATION (https://github.com/ably/docs/blob/cb5de6a6a40abdcb0d9d5af825928dd62dc1ca64/content/spaces/cursors.textile?plain=1#L126-L211) -->
402-
* Cursor positions can be retrieved in one-off calls. These are local calls that retrieve the latest position of cursors retained in memory by the SDK.
287+
* Retrieve the cursor position of all members in a one-off call. This is useful for retrieving the initial position of members's cursors.
403288
*
404-
* The following is an example of retrieving a member’s own cursor position:
405-
*
406-
* ```javascript
407-
* const myCursor = await space.cursors.getSelf();
408-
* ```
409-
* The following is an example payload returned by `space.cursors.getSelf()`:
410-
*
411-
* ```json
412-
* {
413-
* “clientId”: “DzOBJqgGXzyUBb816Oa6i”,
414-
* “connectionId”: “__UJBKZchX”,
415-
* "position": {
416-
* "x": 864,
417-
* "y": 32
418-
* }
419-
* }
420-
* ```
421-
* The following is an example of retrieving the cursor positions for all members other than the member themselves:
422-
*
423-
* ```javascript
424-
* const othersCursors = await space.cursors.getOthers();
425-
* ```
426-
* The following is an example payload returned by `space.cursors.getOthers()`:
427-
*
428-
* ```json
429-
* {
430-
* "3ej3q7yZZz": {
431-
* "clientId": "yyXidHatpP3hJpMpXZi8W",
432-
* "connectionId": "3ej3q7yZZz",
433-
* "position": {
434-
* "x": 12,
435-
* "y": 3
436-
* }
437-
* },
438-
* "Z7CA3-1vlR": {
439-
* "clientId": "b18mj5B5hm-govdFEYRyb",
440-
* "connectionId": "Z7CA3-1vlR",
441-
* "position": {
442-
* "x": 502,
443-
* "y": 43
444-
* }
445-
* }
446-
* }
447-
* ```
448-
* The following is an example of retrieving the cursor positions for all members, including the member themselves. `getAll()` is useful for retrieving the initial position of members’ cursors.
289+
* The following is an example of retrieving the cursor positions for all members:
449290
*
450291
* ```javascript
451292
* const allCursors = await space.cursors.getAll();
452293
* ```
453-
* The following is an example payload returned by `space.cursors.getAll()`:
454-
*
455-
* ```json
456-
* {
457-
* "3ej3q7yZZz": {
458-
* "clientId": "yyXidHatpP3hJpMpXZi8W",
459-
* "connectionId": "3ej3q7yZZz",
460-
* "position": {
461-
* "x": 12,
462-
* "y": 3
463-
* }
464-
* },
465-
* "Z7CA3-1vlR": {
466-
* "clientId": "b18mj5B5hm-govdFEYRyb",
467-
* "connectionId": "Z7CA3-1vlR",
468-
* "position": {
469-
* "x": 502,
470-
* "y": 43
471-
* }
472-
* },
473-
* "__UJBKZchX": {
474-
* “clientId”: “DzOBJqgGXzyUBb816Oa6i”,
475-
* “connectionId”: “__UJBKZchX”,
476-
* "position": {
477-
* "x": 864,
478-
* "y": 32
479-
* }
480-
* }
481-
* }
482-
* ```
483-
* <!-- END WEBSITE DOCUMENTATION -->
484-
*
485-
* <!-- BEGIN CLASS-DEFINITIONS DOCUMENTATION -->
486-
* Get the last `CursorUpdate` object for all the members.
487-
*
488-
* Example:
489-
*
490-
* ```ts
491-
* const allLatestPositions = await space.cursors.getAll();
492-
* ```
493-
* <!-- END CLASS-DEFINITIONS DOCUMENTATION -->
494294
*/
495295
async getAll(): Promise<Record<string, null | CursorUpdate>> {
496296
const channel = this.getChannel();

0 commit comments

Comments
 (0)