Skip to main content

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:

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

See: SessionEvents for more details.

Extends

Implements

Properties

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

UUID


session_id

Get Signature

get session_id(): UUID

Defined in: livelink.js/sources/session/Session.ts:231

The unique identifier of the session.

Returns

UUID


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

ParameterTypeDescription
params{ scene_id: UUID; token: string; is_transient: 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.

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

ParameterTypeDescription
params{ scene_id: UUID; token: string; session_selector: (__namedParameters: { sessions: SessionInfo[]; }) => null | SessionInfo; }
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[]; }) => null | SessionInfoA 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

ParameterTypeDescription
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<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

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

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.