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
| Parameter | Type | Description |
|---|---|---|
entityHandle | number | The 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
| Parameter | Type | Description |
|---|---|---|
entityHandle | number | The 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
| Parameter | Type | Description |
|---|---|---|
entityHandle | number | The 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
| Parameter | Type | Description |
|---|---|---|
channelName | string | The channel name. |
onReceived | (sender, payload) => void | The 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
| Parameter | Type | Description |
|---|---|---|
playerId | number | The target player ID. |
channelName | string | The channel name. |
payload | string | The message payload. |
Returns
void
BroadcastMessage()
static BroadcastMessage(channelName, payload): void;
Broadcasts a message to all players on a named channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
channelName | string | The channel name. |
payload | string | The 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
| Parameter | Type | Description |
|---|---|---|
initialValue | T | The initial state value. |
onStateChange? | (state) => void | The 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
| Parameter | Type | Description |
|---|---|---|
func | F | The function to synchronize. |
Returns
The synchronized function.
(...args): void;
Parameters
| Parameter | Type |
|---|---|
...args | Parameters<F> |
Returns
void
OnUserJoined()
static OnUserJoined(onUserJoined): Promise<void>;
Registers a callback for user join events.
Parameters
| Parameter | Type | Description |
|---|---|---|
onUserJoined | (user) => void | The 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
| Parameter | Type | Description |
|---|---|---|
onUserLeft | (user) => void | The callback invoked when a user leaves. |
Returns
Promise<void>
A promise that resolves when the callback has been registered.