-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation tweaks post-API updates #142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ To instantiate the Spaces SDK, create an [Ably client](https://ably.com/docs/get | |
import Spaces from '@ably-labs/spaces'; | ||
import { Realtime } from 'ably'; | ||
|
||
const client = new Realtime.Promise({key: "<API-key>", clientId: "<client-ID>"}); | ||
const client = new Realtime.Promise({ key: "<API-key>", clientId: "<client-ID>" }); | ||
const spaces = new Spaces(client); | ||
``` | ||
You can use [basic authentication](https://ably.com/docs/auth/basic) i.e. the API Key directly for testing purposes, however it is strongly recommended that you use [token authentication](https://ably.com/docs/auth/token) in production environments. | ||
|
@@ -107,7 +107,7 @@ space.subscribe('update', (spaceState) => { | |
}); | ||
|
||
// Enter a space, publishing an update event, including optional profile data | ||
space.enter({ | ||
await space.enter({ | ||
username: 'Claire Lemons', | ||
avatar: 'https://slides-internal.com/users/clemons.png', | ||
}); | ||
|
@@ -136,7 +136,7 @@ The following is an example event payload received by subscribers when a user en | |
|
||
## Space members | ||
|
||
The `members` namespace within a Space is a client-side filtered listener optimized for building avatar stacks. Subscribe to members entering, leaving, being removed from the Space (after a timeout) or updating their profile information. | ||
The `members` namespace contains methods dedicated to building avatar stacks. Subscribe to members entering, leaving, being removed from the Space (after a timeout) or updating their profile information. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't a big fan of the wording here - I think it's not accurate and could lead to confusion (a listener is for an example a function passed to an event listener; that's not what the namespace is, just the |
||
|
||
```ts | ||
// Subscribe to all member events in a space | ||
|
@@ -201,17 +201,17 @@ const othersMemberInfo = await space.members.getOthers(); | |
|
||
## Member locations | ||
|
||
The `locations` namespace within a Space is a client-side filtered listener optimized for building member locations which enable you to track where users are within an application. A location could be a form field, multiple cells in a spreadsheet or a slide in a slide deck editor. | ||
The `locations` namespace contains methods dedicated to building member locations, enabling you to track where users are within an application. A location could be a form field, multiple cells in a spreadsheet or a slide in a slide deck editor. | ||
|
||
```ts | ||
// You need to enter a space before publishing your location | ||
space.enter({ | ||
await space.enter({ | ||
username: 'Claire Lemons', | ||
avatar: 'https://slides-internal.com/users/clemons.png', | ||
}); | ||
|
||
// Publish your location based on the UI element selected | ||
space.locations.set({ slide: '3', component: 'slide-title' }); | ||
await space.locations.set({ slide: '3', component: 'slide-title' }); | ||
|
||
// Subscribe to location events from all members in a space | ||
space.locations.subscribe('update', (locationUpdate) => { | ||
|
@@ -258,22 +258,22 @@ Member locations has methods to get the current snapshot of member state: | |
|
||
```ts | ||
// Get a snapshot of all the member locations | ||
const allLocations = space.locations.getAll(); | ||
const allLocations = await space.locations.getAll(); | ||
|
||
// Get a snapshot of my location | ||
const myLocation = space.locations.getSelf(); | ||
const myLocation = await space.locations.getSelf(); | ||
|
||
// Get a snapshot of everyone else's locations | ||
const othersLocations = space.locations.getOthers(); | ||
const othersLocations = await space.locations.getOthers(); | ||
``` | ||
|
||
## Live cursors | ||
|
||
The `cursors` namespace within a Space is a client-side filtered listener optimized for building live cursors which allows you to track a member's pointer position updates across an application. Events can also include associated data, such as pointer attributes and the IDs of associated UI elements: | ||
The `cursors` namespace contains methods dedicated to building live cursors, allowing you to track a member's pointer position updates across an application. Events can also include associated data, such as pointer attributes and the IDs of associated UI elements: | ||
|
||
```ts | ||
// You need to enter a space before publishing your cursor updates | ||
space.enter({ | ||
await space.enter({ | ||
username: 'Claire Lemons', | ||
avatar: 'https://slides-internal.com/users/clemons.png', | ||
}); | ||
|
@@ -306,11 +306,11 @@ Member cursors has methods to get the current snapshot of member state: | |
|
||
```ts | ||
// Get a snapshot of all the cursors | ||
const allCursors = space.cursors.getAll(); | ||
const allCursors = await space.cursors.getAll(); | ||
|
||
// Get a snapshot of my cursor | ||
const myCursor = space.cursors.getSelf(); | ||
const myCursor = await space.cursors.getSelf(); | ||
|
||
// Get a snapshot of everyone else's cursors | ||
const othersCursors = space.cursors.getOthers(); | ||
const othersCursors = await space.cursors.getOthers(); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,10 +224,10 @@ space.members.unsubscribe('leave'); | |
|
||
#### getSelf() | ||
|
||
Returns a Promise which resolves to the [SpaceMember](#spacemember) object relating to the local connection. Will resolve to `undefined` if the client hasn't entered the space yet. | ||
Returns a Promise which resolves to the [SpaceMember](#spacemember) object relating to the local connection. Will resolve to `null` if the client hasn't entered the space yet. | ||
|
||
```ts | ||
type getSelf = () => Promise<SpaceMember | undefined>; | ||
type getSelf = () => Promise<SpaceMember | null>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a separate PR to make sure we always return |
||
``` | ||
|
||
Example: | ||
|
@@ -355,7 +355,7 @@ space.locations.unsubscribe('update'); | |
Get location for self. | ||
|
||
```ts | ||
type getSelf = () => Promise<Location | undefined>; | ||
type getSelf = () => Promise<Location>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
|
||
Example: | ||
|
@@ -465,41 +465,41 @@ space.cursors.unsubscribe('update'); | |
Get the last `CursorUpdate` object for self. | ||
|
||
```ts | ||
type getSelf = () => <CursorUpdate | undefined>; | ||
type getSelf = () => Promise<CursorUpdate | null>; | ||
``` | ||
|
||
Example: | ||
|
||
```ts | ||
const selfPosition = space.cursors.getSelf(); | ||
const selfPosition = await space.cursors.getSelf(); | ||
``` | ||
|
||
#### getAll() | ||
|
||
Get the last `CursorUpdate` object for all the members. | ||
|
||
```ts | ||
type getAll = () => Record<ConnectionId, CursorUpdate>; | ||
type getAll = () => Promise<Record<string, CursorUpdate | null>>; | ||
``` | ||
|
||
Example: | ||
|
||
```ts | ||
const allLatestPositions = space.cursors.getAll(); | ||
const allLatestPositions = await space.cursors.getAll(); | ||
``` | ||
|
||
#### getOthers() | ||
|
||
Get the last `CursorUpdate` object for everyone else but yourself. | ||
|
||
```ts | ||
type getOthers = () => Record<ConnectionId, CursorUpdate>; | ||
type getOthers = () => Promise<Record<string, CursorUpdate | null>>; | ||
``` | ||
|
||
Example: | ||
|
||
```ts | ||
const otherPositions = space.cursors.getOthers(); | ||
const otherPositions = await space.cursors.getOthers(); | ||
``` | ||
|
||
### Related types | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added these everywhere in docs to make it clear these are async operations and can be waited upon