Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / NetworkHandle

Interface: NetworkHandle ​

Defined in: network/types.ts:207

A Behaviour's view of the shared world: this.network, null in a single-player run.

Properties ​

PropertyModifierTypeDescriptionDefined in
connectedreadonlyboolean-network/types.ts:208
sessionIdreadonlystringThis client's id in the room.network/types.ts:210
isHostreadonlybooleanWhether this client simulates the scene's shared objects.network/types.ts:212
isOwnerreadonlybooleanWhether this client simulates this entity.network/types.ts:214
playersreadonlystring[]Everyone in the room, by session id.network/types.ts:216
voicereadonlyVoiceHandle | nullVoice chat, when the project has it on.network/types.ts:218
colocationreadonlyColocationHandle | nullLining up players in one room, when the scene has colocation on.network/types.ts:220
holderreadonlystringWho is holding this entity right now, or empty.network/types.ts:239

Methods ​

playerName() ​

ts
playerName(id): string;

Defined in: network/types.ts:222

A player's name: what they set, else "Player 2" and so on.

Parameters ​

ParameterType
idstring

Returns ​

string


setName() ​

ts
setName(name): void;

Defined in: network/types.ts:224

The name others see over this player's head.

Parameters ​

ParameterType
namestring

Returns ​

void


send() ​

ts
send(name, payload?): void;

Defined in: network/types.ts:226

Send to the room. Others hear it in onMessage, unless a server hook keeps it.

Parameters ​

ParameterType
namestring
payload?unknown

Returns ​

void


onMessage() ​

ts
onMessage(name, handler): () => void;

Defined in: network/types.ts:228

Listen for a message. Returns the way to stop.

Parameters ​

ParameterType
namestring
handler(payload, from) => void

Returns ​

() => void


playSlot() ​

ts
playSlot(id, options?): boolean;

Defined in: network/types.ts:233

Play a sound-bank slot here and for everyone in the room. Returns whether it sounded: a slot's chance and cooldown can keep it quiet, and then no one hears it.

Parameters ​

ParameterType
idstring
options?PlaySlotOptions

Returns ​

boolean


spawn() ​

ts
spawn(prefab, options?): void;

Defined in: network/types.ts:235

Spawn a prefab everyone sees, owned by this client.

Parameters ​

ParameterType
prefab| string | { path: string; }
options?NetSpawnOptions

Returns ​

void


despawn() ​

ts
despawn(entityId?): void;

Defined in: network/types.ts:237

Remove a shared entity this client owns (this one by default).

Parameters ​

ParameterType
entityId?number

Returns ​

void


take() ​

ts
take(): boolean;

Defined in: network/types.ts:245

Ask to move this scene object yourself, as a grab does: it becomes yours once the room agrees. Returns false when it can't be asked for, such as a spawned object or one someone else is holding.

Returns ​

boolean


drop() ​

ts
drop(): void;

Defined in: network/types.ts:247

Stop holding it. It stays yours until someone else takes it.

Returns ​

void


setProp() ​

ts
setProp(key, value): void;

Defined in: network/types.ts:249

Change a shared value on this entity. Only its owner can.

Parameters ​

ParameterType
keystring
valueNetValue

Returns ​

void


getProp() ​

ts
getProp(key): NetValue | undefined;

Defined in: network/types.ts:250

Parameters ​

ParameterType
keystring

Returns ​

NetValue | undefined