Skip to content
On this page

Class: Network

WebSGNetworking.Network

Represents the networking methods available for sending and receiving data in a WebSG script.

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Network()

Properties

onpeerentered

onpeerentered: null | (peer: Peer) => any

Callback for when a peer enters the world.

Param

The peer that entered the world.

Defined in

websg.d.ts:2630


onpeerexited

onpeerexited: null | (peer: Peer) => any

Callback for when a peer exits the world.

Param

The peer that exited the world.

Defined in

websg.d.ts:2636

Accessors

host

get host(): undefined | Peer

The current host Peer in the world. This may change as peers enter and exit the world.

Returns

undefined | Peer

Defined in

websg.d.ts:2604


local

get local(): undefined | Peer

The local user's Peer in the world. This will not be set until the user has entered the world and world.onenter is called

Returns

undefined | Peer

Defined in

websg.d.ts:2610

Methods

broadcast

broadcast(message, reliable?): undefined

Broadcasts data to all connected clients.

Parameters

NameTypeDescription
messagestring | ArrayBuffer-
reliable?booleanWhether or not the data should be sent reliably or unreliably. Defaults to true.

Returns

undefined

Defined in

websg.d.ts:2624


defineReplicator

defineReplicator(factory): Replicator

Defines a new replicator that can be used to spawn and despawn nodes

Parameters

NameTypeDescription
factory() => NodeA function called whenever a new node is spawned.

Returns

Replicator

Defined in

websg.d.ts:2642


listen

listen(): NetworkListener

Creates a new $NetworkListener that can be used to listen for incoming messages from other peers.

Returns

NetworkListener

Defined in

websg.d.ts:2616