Class: Session<ClientType>
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:97
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/references/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<ClientType>>
Type Parameters
| Type Parameter | Default type |
|---|---|
ClientType extends Client | Client |
Implements
Constructors
Constructor
protected new Session<ClientType>(params: {
token: string;
session_info: SessionInfo;
created: boolean;
is_guest?: boolean;
}): Session<ClientType>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:426
Create a new session.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | { token: string; session_info: SessionInfo; created: boolean; is_guest?: boolean; } | - |
params.token | string | The authentication token. This token must have at least read access to the scene. |
params.session_info | SessionInfo | The information about the session. |
params.created | boolean | Whether the session has been created or found by the current client. |
params.is_guest? | boolean | - |
Returns
Session<ClientType>
Overrides
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 | UUID | null | null | The id of the client that is currently connected to the session. |
token | readonly | string | undefined | The authentication token. |
is_guest | readonly | boolean | false | Whether the authentication token is a guest token. |
Accessors
scene_id
Get Signature
get scene_id(): UUID;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:356
The unique identifier of the scene the session is running.
Returns
session_id
Get Signature
get session_id(): UUID;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:363
The unique identifier of the session.
Returns
client_ids
Get Signature
get client_ids(): UUID[];
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:370
The unique identifiers of all clients connected to the session.
Returns
UUID[]
clients
Get Signature
get clients(): ClientType[];
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:377
All the clients connected to the session.
Returns
ClientType[]
other_clients
Get Signature
get other_clients(): ClientType[];
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:384
All the clients connected to the session except the current client.
Returns
ClientType[]
current_client
Get Signature
get current_client(): ClientType | null;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:391
The current client connected to the session.
Returns
ClientType | null
Methods
addEventListener()
addEventListener<_EventName>(
event_name: _EventName,
listener: (event: SessionEvents<ClientType>[_EventName]) => void,
options?: boolean | AddEventListenerOptions): void;
Defined in: livelink.clients/livelink.base/sources/TypedEventTarget.ts:10
Type Parameters
| Type Parameter |
|---|
_EventName extends | "on-disconnected" | "on-inactivity-warning" | "on-activity-detected" | "on-client-joined" | "on-client-left" |
Parameters
| Parameter | Type |
|---|---|
event_name | _EventName |
listener | (event: SessionEvents<ClientType>[_EventName]) => void |
options? | boolean | AddEventListenerOptions |
Returns
void
Inherited from
TypedEventTarget.addEventListener
removeEventListener()
removeEventListener<_EventName>(
event_name: _EventName,
listener: (event: SessionEvents<ClientType>[_EventName]) => void,
options?: boolean | EventListenerOptions): void;
Defined in: livelink.clients/livelink.base/sources/TypedEventTarget.ts:21
Type Parameters
| Type Parameter |
|---|
_EventName extends | "on-disconnected" | "on-inactivity-warning" | "on-activity-detected" | "on-client-joined" | "on-client-left" |
Parameters
| Parameter | Type |
|---|---|
event_name | _EventName |
listener | (event: SessionEvents<ClientType>[_EventName]) => void |
options? | boolean | EventListenerOptions |
Returns
void
Inherited from
TypedEventTarget.removeEventListener
create()
static create<T>(this: T, params: {
scene_id: UUID;
token: string;
is_transient?: boolean;
options?: Record<string, boolean>;
}): Promise<{
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:133
Create a new session.
Type Parameters
| Type Parameter |
|---|
T extends { prototype: Session<any>; } |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | T | - |
params | { scene_id: UUID; token: string; is_transient?: boolean; options?: Record<string, 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. |
params.options? | Record<string, boolean> | - |
Returns
Promise<{
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}>
A promise that resolves to the created session.
Throws
Error if the session could not be created.
createFromInfo()
static createFromInfo<T>(this: T, params: {
session_info: SessionInfo;
token: string;
}): {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
};
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:181
Create a session instance from a session info, without creating or joining anything server-side.
Type Parameters
| Type Parameter |
|---|
T extends { prototype: Session<any>; } |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | T | - |
params | { session_info: SessionInfo; token: string; } | - |
params.session_info | SessionInfo | The information about the session. |
params.token | string | The authentication token. |
Returns
The session instance.
| Name | Type | Default value | Description |
|---|---|---|---|
info | SessionInfo | - | The information about the session. |
has_been_created | boolean | - | Whether the session has been created or joined by the current client. |
client_id | UUID | null | null | The id of the client that is currently connected to the session. |
token | string | - | The authentication token. |
is_guest | boolean | false | Whether the authentication token is a guest token. |
get scene_id | UUID | - | The unique identifier of the scene the session is running. |
get session_id | UUID | - | The unique identifier of the session. |
get client_ids | UUID[] | - | The unique identifiers of all clients connected to the session. |
get clients | ClientType[] | - | All the clients connected to the session. |
get other_clients | ClientType[] | - | All the clients connected to the session except the current client. |
get current_client | ClientType | null | - | The current client connected to the session. |
addEventListener() | ( event_name: _EventName, listener: (event: SessionEvents<any>[_EventName]) => void, options?: boolean | AddEventListenerOptions) => void | - | |
removeEventListener() | ( event_name: _EventName, listener: (event: SessionEvents<any>[_EventName]) => void, options?: boolean | EventListenerOptions) => void | - | |
isJoinable() | () => boolean | - | Whether the session is joinable. |
getClient() | (params: { client_id: UUID; }) => any | - | Get a client by its unique identifier. |
evictClient() | (params: { client: UUID | Client; }) => Promise<boolean> | - | 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. |
list()
static list(params: {
scene_id: UUID;
token: string;
}): Promise<SessionInfo[]>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:199
List all existing sessions running the specified scene.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | { scene_id: UUID; token: string; } | - |
params.scene_id | UUID | The unique identifier of the scene the sessions must be running. |
params.token | string | The authentication token. |
Returns
Promise<SessionInfo[]>
A promise that resolves to the list of sessions running the scene, or to an empty list if the sessions could not be listed (a non-OK API response is treated as a legitimate impossibility to list the sessions of the scene, not as an error).
find()
static find<T>(this: T, params: {
scene_id: UUID;
token: string;
session_selector: (__namedParameters: {
sessions: SessionInfo[];
}) => SessionInfo | null;
}): Promise<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:227
Find an existing session running the specified scene.
Type Parameters
| Type Parameter |
|---|
T extends { prototype: Session<any>; } |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | T | - |
params | { scene_id: UUID; token: string; session_selector: (__namedParameters: { sessions: SessionInfo[]; }) => SessionInfo | null; } | - |
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[]; }) => SessionInfo | null | A callback that selects a session from a list of candidate sessions. |
Returns
Promise<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>
A promise that resolves to the found session, or null if no session was found: no session is running the scene, the session selector selected none, or the sessions could not be listed (see Session.list).
findById()
static findById<T>(this: T, params: {
session_id: UUID;
token: string;
}): Promise<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:262
Find an existing session by its unique identifier.
Type Parameters
| Type Parameter |
|---|
T extends { prototype: Session<any>; } |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | T | - |
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<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>
A promise that resolves to the found session or null if no session was found.
findByGuestToken()
static findByGuestToken<T>(this: T, params: {
guest_token: string;
}): Promise<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:296
Find the session tied to a guest token.
Type Parameters
| Type Parameter |
|---|
T extends { prototype: Session<any>; } |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | T | - |
params | { guest_token: string; } | - |
params.guest_token | string | The guest token generated by the Generate Guest Token endpoint. |
Returns
Promise<
| {
info: SessionInfo;
has_been_created: boolean;
client_id: UUID | null;
token: string;
is_guest: boolean;
get scene_id(): UUID;
get session_id(): UUID;
get client_ids(): UUID[];
get clients(): ClientType[];
get other_clients(): ClientType[];
get current_client(): ClientType | null;
addEventListener: void;
removeEventListener: void;
isJoinable: boolean;
getClient: any;
evictClient: Promise<boolean>;
}
| null>
A promise that resolves to the found session or null if no session was found.
isJoinable()
isJoinable(): boolean;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:448
Whether the session is joinable.
Returns
boolean
getClient()
getClient(params: {
client_id: UUID;
}): ClientType | null;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:498
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
ClientType | null
The client or null if the client is not found.
evictClient()
evictClient(params: {
client: UUID | Client;
}): Promise<boolean>;
Defined in: livelink.clients/livelink.base/sources/session/Session.ts:516
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.