Skip to content
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

Add missing method to class definitions #62

Merged
merged 2 commits into from
May 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions docs/class-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,32 @@ Leave the space. This removes the member from the space and notifies other space
Used for subscribing to realtime events within the space.

##### membersUpdate

Fires when a member enters or leaves the space. The argument supplied to the event listener callback is the current array of all [SpaceMember](#spacemember) objects within the space.

##### enter

Fires when a member enters the space. The argument supplied to the event listener callback is the [SpaceMember](#spacemember) which entered the space.

##### leave

Fires when a member leaves the space. The argument supplied to the event listener callback is the [SpaceMember](#spacemember) which left the space.
Note that the leave event will only fire once the [offlineTimeout](#offlinetimeout) has passed.

#### getMembers()

Returns an array of all [SpaceMember](#spacemember) objects currently in the space, including any members who have left and not yet timed out. (_see: [SpaceOptions.offlineTimeout](#offlinetimeout)_)

#### getSelf()

Gets the [SpaceMember](#spacemember) object which relates to the local client.

#### locations

Get the [Locations](#locations-1) object for this space.

#### cursors

Get the [Cursors](#cursors-1) object for this space.

### SpaceMember
Expand All @@ -91,38 +98,41 @@ A SpaceMember represents a member within a Space instance.
This could be the local client or other remote clients which are connected to the same space.

| Property | Type |
|-------------|-----------------------------------|
| ----------- | --------------------------------- |
| clientId | string |
| isConnected | bool |
| profileData | Object |
| location | Any |
| lastEvent | {name: string, timestamp: number} |


### Locations

Handles the tracking of member locations within a space.

#### set(location)

Set your current location. Location can be any JSON-serializable object. Fires a [locationUpdate](#locationupdate) event for all connected clients in this space.

| Property | Type |
|----------|------|
| -------- | ---- |
| location | Any |

#### on(event, callback)

Used for subscribing to location specific updates. Currently, only one event is supported:

##### locationUpdate

Fires when a member updates their location. The argument supplied to the event listener is an object with the following fields:

| Property | Type |
|------------------|-----------------------------|
| ---------------- | --------------------------- |
| member | [SpaceMember](#spacemember) |
| currentLocation | Any |
| previousLocation | Any |

#### off(event, callback)

Used for unsubscribing from location-specific updates.

With no arguments, unsubscribes from all location updates.
Expand All @@ -134,69 +144,88 @@ With an event or list of events as the first argument, unsubscribes from all loc
With an event or list of events as the first argument AND a callback as the second argument, unsubscribes from all location updates matching that(those) event(s) which also use the same callback as a listener.

#### createTracker(locationTrackerPredicate)

Used to create a tracker for a specific location using a predicate for the [locationUpdate](#locationUpdate) change event. Returns a [LocationTracker][#LocationTracker].

##### locationUpdatePredicate(locationUpdate)

A predicate function called with an locationUpdate event. Return a boolean for events that should be emitted via the tracker.

### LocationTracker

Handles the tracking of a specific location within a space.

#### on(callback)

Used for subscribing to a listener once the locations class has emitted a `locationUpdate` event, filtered by the [locationUpdatePredicate](#locationupdatepredicatelocationupdate).

#### off(callback)

Used for unsubscribing from a listener.

#### members()

Used to retrieve a list of members in the Space for whom the [locationUpdatePredicate](#locationupdatepredicatelocationupdate) would return `true` based on their current location.

### Cursors

#### get(name)

Get a [Cursor](#cursor) with a specific name. Names are unique per space.

| Property | Type |
|----------|--------|
| -------- | ------ |
| name | string |

#### getAll(name)

Get the last position of all cursors in this space, for each connection. Pass a cursor name to only get the last position of that cursor for each connection.

| Property | Type |
| -------- | ------ |
| name | string |

#### on(event, callback)

Used for subscribing to all cursor updates. Currently, only one event is supported:

##### positionsUpdate

Fires when a cursors position is updated. The argument supplied is an object of one or more cursors by name and their respective cursor movements since the last update.

| Property | Type |
|------------------|-----------------------------------------------------|
| positions | Record<string, [CursorPosition](#cursorposition)[]> |
| Property | Type |
| --------- | --------------------------------------------------- |
| positions | Record<string, [CursorPosition](#cursorposition)[]> |

### Cursor

An individual cursor.

#### setPosition(position)

Set the position of this cursor. The position will be updated for each other member of the space via a Cursors [positionsUpdate](#positionsupdate) or Cursor [positionUpdate](#positionupdate).

| Property | Type |
|----------|-----------------------------------|
| -------- | --------------------------------- |
| position | [CursorPosition](#cursorposition) |

#### on(event, callback)

Used for subscribing to a specific cursors updates. Currently, only one event is supported:

##### positionUpdate

Fires when this cursors location is updated. Contains an array of cursor positions since the last update.

| Property | Type |
|-----------|-------------------------------------|
| --------- | ----------------------------------- |
| positions | [CursorPosition](#cursorposition)[] |


### CursorPosition

Represents the position of a cursor.

| Property | Type |
|----------|--------|
| -------- | ------ |
| x | number |
| y | number |