Functions for working with Client objects
- Source:
Members
(inner) KEY_SPLITTER :string
The value used to separate client information in a PresenceKey
Type:
- string
- Source:
Methods
(static) create(socket) → {Promise.<Client>}
Create a new Client.
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
WS.WebSocket | The socket that the new client is connected on |
- Source:
Returns:
A promise resolving with a new Client
- Type
- Promise.<Client>
Example
Creating a new Client
Client.create(webSocket).then(client => console.log(client));
(static) getPresenceKey(client) → {string}
Get the Redis presence key for a client.
Parameters:
| Name | Type | Description |
|---|---|---|
client |
Client | The client to fetch the presence key for |
- Source:
Returns:
A presence key for a client
- Type
- string
Example
Getting a Redis presence key for a client
Client.getPresenceKey(client);
// 'longhouse/spaces/spaceID/clientId/clientIdentity/2015-06-05T20:51:47.411Z'
(static) parsePresenceKey(presenceKey) → {Client}
Parse a presence key for Client info
Parameters:
| Name | Type | Description |
|---|---|---|
presenceKey |
string | A presence key |
- Source:
Returns:
A client
- Type
- Client
Example
Parsing a presence key
Client.parsePresenceKey('longhouse/spaces/spaceID/clientId/clientIdentity/2015-06-05T20:51:47.411Z');
// { id: 'clientID', identity: 'clientIdentity', spaceID: 'spaceID', joinedAt: '2015-06-05T20:51:47.411Z' }
(static) serialize(client)
Serialize a client for sending to another client.
Parameters:
| Name | Type | Description |
|---|---|---|
client |
Client | The client to serialize |
- Source:
Example
Serializing a client
Client.serialize(client);
// { id: 'clientID', identity: 'clientIdentity', joinedAt: '2015-06-05T20:51:47.411Z' }
Type Definitions
Client
A representation of someone connected to a space over a WebSocket connection
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string | The UUID identifying this client |
|
requestID |
string |
<nullable> |
The ID of the request this client connected with |
identity |
string | The identity value of this client (e.g. an email) |
|
spaceID |
string | The ID of the space this client is connected to |
|
socket |
WS.WebSocket | The socket the client is connected over |
|
joinedAt |
string | The time at which the client joined |
- Source:
PresenceKey
A key containing information about a connected client
The client information is all in the key, split by forward slashes:
longhouse/spaces/${spaceID}/${id}/${identity}/${joinedAt}
Type:
- string
- Source: