Skip to main content

Class: Networking

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

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.

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.

Returns

Promise<number>

A promise that resolves to the current client ID.


GetMasterClientId()

static GetMasterClientId(): Promise<number>;

Gets the master client ID.

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.

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.

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): void;

Creates a named message channel.

Parameters

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

Returns

void


SendMessageTo()

static SendMessageTo(
playerId,
channelName,
payload): void;

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

Parameters

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

Returns

void


BroadcastMessage()

static BroadcastMessage(channelName, payload): void;

Broadcasts a message to all players on a named channel.

Parameters

ParameterTypeDescription
channelNamestringThe channel name.
payloadstringThe message payload.

Returns

void


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.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
initialValueTThe initial state value.
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.

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.