Skip to main content

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:

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​

See: SessionEvents for more details.

Extends​

Type Parameters​

Type ParameterDefault type
ClientType extends ClientClient

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​

ParameterTypeDescription
params{ token: string; session_info: SessionInfo; created: boolean; is_guest?: boolean; }-
params.tokenstringThe authentication token. This token must have at least read access to the scene.
params.session_infoSessionInfoThe information about the session.
params.createdbooleanWhether the session has been created or found by the current client.
params.is_guest?boolean-

Returns​

Session<ClientType>

Overrides​

TypedEventTarget.constructor

Properties​

PropertyModifierTypeDefault valueDescription
inforeadonlySessionInfoundefinedThe information about the session.
has_been_createdreadonlybooleanundefinedWhether the session has been created or joined by the current client.
client_idpublicUUID | nullnullThe id of the client that is currently connected to the session.
tokenreadonlystringundefinedThe authentication token.
is_guestreadonlybooleanfalseWhether 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​

UUID


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​

UUID


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​

ParameterType
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​

ParameterType
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​

ParameterTypeDescription
thisT-
params{ scene_id: UUID; token: string; is_transient?: boolean; options?: Record<string, boolean>; }-
params.scene_idUUIDThe unique identifier of the scene the session will launch.
params.tokenstringThe authentication token. This token must have at least read access to the scene.
params.is_transient?booleanWhether 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​

ParameterTypeDescription
thisT-
params{ session_info: SessionInfo; token: string; }-
params.session_infoSessionInfoThe information about the session.
params.tokenstringThe authentication token.

Returns​

The session instance.

NameTypeDefault valueDescription
infoSessionInfo-The information about the session.
has_been_createdboolean-Whether the session has been created or joined by the current client.
client_idUUID | nullnullThe id of the client that is currently connected to the session.
tokenstring-The authentication token.
is_guestbooleanfalseWhether the authentication token is a guest token.
get scene_idUUID-The unique identifier of the scene the session is running.
get session_idUUID-The unique identifier of the session.
get client_idsUUID[]-The unique identifiers of all clients connected to the session.
get clientsClientType[]-All the clients connected to the session.
get other_clientsClientType[]-All the clients connected to the session except the current client.
get current_clientClientType | 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​

ParameterTypeDescription
params{ scene_id: UUID; token: string; }-
params.scene_idUUIDThe unique identifier of the scene the sessions must be running.
params.tokenstringThe 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​

ParameterTypeDescription
thisT-
params{ scene_id: UUID; token: string; session_selector: (__namedParameters: { sessions: SessionInfo[]; }) => SessionInfo | null; }-
params.scene_idUUIDThe unique identifier of the scene the session must be running.
params.tokenstringThe authentication token. This token must have at least read access to the scene.
params.session_selector(__namedParameters: { sessions: SessionInfo[]; }) => SessionInfo | nullA 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​

ParameterTypeDescription
thisT-
params{ session_id: UUID; token: string; }-
params.session_idUUIDThe unique identifier of the session to find.
params.tokenstringThe 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​

ParameterTypeDescription
thisT-
params{ guest_token: string; }-
params.guest_tokenstringThe 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​

ParameterTypeDescription
params{ client_id: UUID; }-
params.client_idUUIDThe 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​

ParameterTypeDescription
params{ client: UUID | Client; }-
params.clientUUID | ClientThe 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.