Skip to main content

Class: Networking

Provides networking utilities for state synchronization, messaging, and user session events.

For real-time network data updates, including repeated networking calls or network variable updates in an loop, an update frequency of approximately 10 to 20 Hz is recommended.

Constructors

Constructor

new Networking(): Networking;

Returns

Networking

Methods

GetNetworkID()

static GetNetworkID(): string;

Gets the network identifier for the current project session.

Returns

string

The network identifier.


IsLocalMode()

static IsLocalMode(): Promise<boolean>;

Checks whether networking is running in local mode.

Returns

Promise<boolean>

A promise that resolves to true if local mode is enabled, or false otherwise.


IsMasterClient()

static IsMasterClient(): Promise<boolean>;

Checks whether the current client is the master client.

The master client is responsible for session-level authority and may change during a network session. If the current master client leaves, a new master client is automatically selected. In a local session, this method always returns true.

Returns

Promise<boolean>

A promise that resolves to true if the current client is the master client, or false otherwise.


GetClientId()

static GetClientId(): Promise<number>;

Gets the current client ID. Each client in a network session is assigned a unique ID that can be used for identification and session-level networking operations.

In a local session, this method alreays returns 1.

Returns

Promise<number>

A promise that resolves to the current client ID.


GetMasterClientId()

static GetMasterClientId(): Promise<number>;

Gets the master client ID.

In a local session, this method always returns 1.

Returns

Promise<number>

A promise that resolves to the master client ID.


MakeNetworkTransform()

static MakeNetworkTransform(entityHandle): Promise<boolean>;

Makes an entity use a network transform.

The transform is synchronized across clients that have joined the same network session. In a local session, this method has no effect and does not throw an error.

Parameters

ParameterTypeDescription
entityHandlenumberThe Entity to update.

Returns

Promise<boolean>

A promise that resolves to true if the network transform was created, or false otherwise.


IsNetworkTransform()

static IsNetworkTransform(entityHandle): Promise<boolean>;

Checks whether an entity uses a network transform.

Parameters

ParameterTypeDescription
entityHandlenumberThe Entity to inspect.

Returns

Promise<boolean>

A promise that resolves to true if the entity uses a network transform, or false otherwise.


SyncLocalTransform()

static SyncLocalTransform(entityHandle): Promise<boolean>;

Synchronizes the local transform of an entity to the network session.

The client that calls this method updates the local entity transform for all clients in the same network session. In a local session, this method has no effect and does not throw an error.

Parameters

ParameterTypeDescription
entityHandlenumberThe Entity to synchronize.

Returns

Promise<boolean>

A promise that resolves to true if the transform was synchronized, or false otherwise.


NewChannel()

static NewChannel(channelName, onReceived): Promise<void>;

Creates a named message channel.

In a local session, the channel can still be created, but it does not receive messages, including messages sent by the local client.

Parameters

ParameterTypeDescription
channelNamestringThe channel name.
onReceived(sender, payload) => voidThe callback invoked when a message is received.

Returns

Promise<void>

A promise that resolves when the channel has been created.


SendMessageTo()

static SendMessageTo(
playerId,
channelName,
payload): Promise<void>;

Sends a message to a specific player on a named channel.

In a local session, this method has no effect and does not throw an error.

Parameters

ParameterTypeDescription
playerIdnumberThe target player ID.
channelNamestringThe channel name.
payloadstringThe message payload.

Returns

Promise<void>

A promise that resolves when the message has been sent.


BroadcastMessage()

static BroadcastMessage(channelName, payload): Promise<void>;

Broadcasts a message to all players on a named channel.

In a local session, this method has no effect and does not throw an error.

Parameters

ParameterTypeDescription
channelNamestringThe channel name.
payloadstringThe message payload.

Returns

Promise<void>

A promise that resolves when the message has been broadcast.


NewVariable()

static NewVariable<T>(initialValue, onStateChange?): NetworkState<T>;

Creates a synchronized network variable.

The returned state object holds the same value for all clients in the same network session. Changes to value are broadcast to the session. In a local session, the variable is still created, and the local onStateChange callback is invoked when the state value changes.

undefined is not a valid state value. Use null instead when the state needs to represent an intentionally empty value.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
initialValueNonUndefined<T>The initial state value. Must not be undefined.
onStateChange?(state) => voidThe callback invoked when the state value changes. It is also invoked when the initial value is first assigned to the network state.

Returns

NetworkState<T>

The synchronized NetworkState.


NewFunction()

static NewFunction<F>(func): (...args) => void;

Creates a synchronized network function.

Calling the returned function locally broadcasts the call arguments to the network session. In a local session, the function is still created and remains callable by the local client.

Type Parameters

Type Parameter
F extends (...args) => any

Parameters

ParameterTypeDescription
funcFThe function to synchronize.

Returns

The synchronized function.

(...args): void;
Parameters
ParameterType
...argsParameters<F>
Returns

void


OnUserJoined()

static OnUserJoined(onUserJoined): Promise<void>;

Registers a callback for user join events.

Parameters

ParameterTypeDescription
onUserJoined(user) => voidThe callback invoked when a user joins.

Returns

Promise<void>

A promise that resolves when the callback has been registered.


OnUserLeft()

static OnUserLeft(onUserLeft): Promise<void>;

Registers a callback for user leave events.

Parameters

ParameterTypeDescription
onUserLeft(user) => voidThe callback invoked when a user leaves.

Returns

Promise<void>

A promise that resolves when the callback has been registered.