dot big bang

Developer API
Menu

Class Session

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Session

Index

Accessors

clientType

  • Indicates whether the local Peer taking part in the Session is either a Player, Interactor or a Spectator.

    Returns SessionClientType

localPeer

  • get localPeer(): Peer
  • Gets the Peer of the Session that corresponds to the local client/machine.

    Returns Peer

peers

  • get peers(): Peer[]
  • The list of all the Peers that are parts of the mutiplayer Session.

    Returns Peer[]

serverPeer

  • get serverPeer(): Peer
  • Gets the Peer of the Session that acts as the server. Each Session has a single Peer marked as server. When the Peer leaves the Session another one is automatically designated. The server is responsible for the networked Entities that come with the loaded Game (i.e. the Entities which isNetworked property is true and isSpawned false). Internally, the server is also in charge of providing new Peers joining the Session with the current state of the Game.

    Returns Peer

serverTime

  • get serverTime(): number
  • Gets the time in seconds since the Game started on the server Peer. This time is sent by the server to the other Peers every 10 seconds and is updated at each frame by the local Peer to make it continuous (it basically applies its own delta time onto the received time). There's no complex synchronization system in place, so the server time on the (non-server) local Peer, might be affected by network jitter and jump back or forth a little bit when the message is received. It is therefore non monotonic. If the server Peer leaves the Session and another one takes over, it picks up the server time when the previous one left it. Note that currently, unlike the game.frameTime property, the serverTime resets to 0 when the Game is restarted in edit mode.

    Returns number

Methods

getPeerById

  • getPeerById(id: string): null | Peer
  • Gets the Peer in the Session with the given id, or null if there's no Peer with such id.

    Parameters

    • id: string

      The id of the Peer to look for.

    Returns null | Peer

sendMessage

  • sendMessage(entity: Entity, messageType: string, messagePayload: any): void
  • Send a message to all connected Peers which, in response, deliver it to all the User/ScriptComponents of the given networked Entity via the onMessage() method if implemented. If the Entity isn't networked, the method does nothing as the Entity doesn't exist on the remote Peers. The message isn't received locally by the Peer that sends it. Any Peer can send a message to any networked Entity (and not just its owner).

    Parameters

    • entity: Entity

      The networked Entity which, on remove Peers, will get the message in its UserScriptComponents.

    • messageType: string

      A user-defined string identifying the message (for eg: "onPickupTaken")

    • messagePayload: any

      A JSON-stringifiable (i.e. with just plain old type properties) user-defined object containing the payload of the message.

    Returns void