Session
Defined in: livelink.js/sources/session/Session.ts:68
A session running a scene.
A session is a running instance of a 3dverse server rendering a scene that can be joined by multiple clients.
A session can be transient or not. A transient session is temporary and changes made to the entities in the scene are not saved.
Usage
This class is not meant to be instantiated directly. Use the static methods to create or find an existing session.
A session can be created or joined:
- To create a new session, use the Session.create method.
- To find an existing session, use the Session.find method.
- Or if you know the session id, use the Session.findById method.
Authentication
To create or find a session, you need a valid authentication token that has at least read access to the scene the session will use.
See: https://docs.3dverse.com/api/generate-user-token
Events
- ClientJoinedEvent - Fired when a client joins the session.
- ClientLeftEvent - Fired when a client leaves the session.
- InactivityWarningEvent - Fired when the client is inactive for a certain amount of time.
- ActivityDetectedEvent - Fired when the client is active again.
- DisconnectedEvent - Fired when the session is disconnected.
See: SessionEvents for more details.
Extends
TypedEventTarget
<SessionEvents
>
Implements
Properties
Property | Modifier | Type | Default value | Description |
---|---|---|---|---|
info | readonly | SessionInfo | undefined | The information about the session. |
has_been_created | readonly | boolean | undefined | Whether the session has been created or joined by the current client. |
client_id | public | null | UUID | null | The id of the client that is currently connected to the session. |
token | readonly | string | undefined | The authentication token. |
Accessors
scene_id
Get Signature
get scene_id(): UUID
Defined in: livelink.js/sources/session/Session.ts:224
The unique identifier of the scene the session is running.
Returns
session_id
Get Signature
get session_id(): UUID
Defined in: livelink.js/sources/session/Session.ts:231
The unique identifier of the session.
Returns
client_ids
Get Signature
get client_ids(): UUID[]
Defined in: livelink.js/sources/session/Session.ts:238
The unique identifiers of all clients connected to the session.
Returns
UUID
[]
clients
Get Signature
get clients(): Client[]
Defined in: livelink.js/sources/session/Session.ts:245
All the clients connected to the session.
Returns
Client
[]
other_clients
Get Signature
get other_clients(): Client[]
Defined in: livelink.js/sources/session/Session.ts:252
All the clients connected to the session except the current client.
Returns
Client
[]
current_client
Get Signature
get current_client(): null | Client
Defined in: livelink.js/sources/session/Session.ts:259
The current client connected to the session.
Returns
null
| Client
Methods
create()
static create(params: {
scene_id: UUID;
token: string;
is_transient: boolean;
}): Promise<Session>
Defined in: livelink.js/sources/session/Session.ts:81
Create a new session.
Parameters
Parameter | Type | Description |
---|---|---|
params | { scene_id : UUID ; token : string ; is_transient : boolean ; } | |
params.scene_id | UUID | The unique identifier of the scene the session will launch. |
params.token | string | The authentication token. This token must have at least read access to the scene. |
params.is_transient ? | boolean | Whether the session is transient. Transient sessions are temporary and changes are not saved. |
Returns
Promise
<Session
>
A promise that resolves to the created session.
Throws
Error if the session could not be created.
find()
static find(params: {
scene_id: UUID;
token: string;
session_selector: (__namedParameters: {
sessions: SessionInfo[];
}) => null | SessionInfo;
}): Promise<null | Session>
Defined in: livelink.js/sources/session/Session.ts:126
Find an existing session running the specified scene.
Parameters
Parameter | Type | Description |
---|---|---|
params | { scene_id : UUID ; token : string ; session_selector : (__namedParameters : { sessions : SessionInfo []; }) => null | SessionInfo ; } | |
params.scene_id | UUID | The unique identifier of the scene the session must be running. |
params.token | string | The authentication token. This token must have at least read access to the scene. |
params.session_selector | (__namedParameters : { sessions : SessionInfo []; }) => null | SessionInfo | A callback that selects a session from a list of candidate sessions. |
Returns
Promise
<null
| Session
>
A promise that resolves to the found session or null if no session was found or if no session was selected by the session selector.
findById()
static findById(params: {
session_id: UUID;
token: string;
}): Promise<null | Session>
Defined in: livelink.js/sources/session/Session.ts:164
Find an existing session by its unique identifier.
Parameters
Parameter | Type | Description |
---|---|---|
params | { session_id : UUID ; token : string ; } | |
params.session_id | UUID | The unique identifier of the session to find. |
params.token | string | The authentication token. This token must have at least read access to the scene. |
Returns
Promise
<null
| Session
>
A promise that resolves to the found session or null if no session was found.
isJoinable()
isJoinable(): boolean
Defined in: livelink.js/sources/session/Session.ts:306
Whether the session is joinable.
Returns
boolean
getClient()
getClient(params: {
client_id: UUID;
}): null | Client
Defined in: livelink.js/sources/session/Session.ts:359
Get a client by its unique identifier.
Parameters
Parameter | Type | Description |
---|---|---|
params | { client_id : UUID ; } | |
params.client_id | UUID | The unique identifier of the client to look for. |
Returns
null
| Client
The client or null if the client is not found.
evictClient()
evictClient(params: {
client: UUID | Client;
}): Promise<boolean>
Defined in: livelink.js/sources/session/Session.ts:377
Evict a client from the session.
The client will be disconnected.
The token used to create the session must have manage access to the scene.
Note that nothing prevents the client from reconnecting while the session is still running.
Parameters
Parameter | Type | Description |
---|---|---|
params | { client : UUID | Client ; } | |
params.client | UUID | Client | The client to evict, either a Client object or the unique identifier of the client. |
Returns
Promise
<boolean
>
A promise that resolves to true if the client was evicted, false otherwise.