Options
All
  • Public
  • Public/Protected
  • All
Menu

Tools for p2p multiplayer.

namespace

Index

Functions

  • connect(id: string): void
  • disconnectFromAll(): void
  • disconnectFromAllPeers(): void
  • disconnectFromBroker(): void
  • disconnectFromPeer(id: string): void
  • forceUseRelayServer(shouldUseRelayServer: boolean): void
  • Forces the usage of a relay (TURN) server, to avoid sharing IP addresses with the other peers.

    Parameters

    • shouldUseRelayServer: boolean

      Whether relay-only should be enabled or disabled.

    Returns void

  • getAllPeers(): string[]
  • getConnectedPeer(): string
  • getConnectionInstance(peerID: string): undefined | DataConnection<NetworkEvent>
  • A JavaScript-only function to get the raw P2P DataConnection. This can be useful for example when you want to use a binary protocol instead of GDevelop variables for high-performance networking.

    Parameters

    • peerID: string

    Returns undefined | DataConnection<NetworkEvent>

  • getCurrentId(): string
  • getDisconnectedPeer(): string
  • getEvent(name: string): IEvent
  • getEventData(eventName: string): string
  • Get some data associated to the last trigger of an event.

    Parameters

    • eventName: string

      The event to get data from.

    Returns string

    • The data as JSON.
  • getEventSender(eventName: string): string
  • Get the id of peer that caused the last trigger of an event.

    Parameters

    • eventName: string

      The event to get the sender from.

    Returns string

  • getEventVariable(eventName: string, variable: Variable): void
  • Get a variable associated to the last trigger of an event.

    Parameters

    • eventName: string

      The event to get the variable from.

    • variable: Variable

      The variable where to store the variable content.

    Returns void

  • getEvents(): Map<string, IEvent>
  • getLastError(): string
  • isReady(): boolean
  • onConnection(): boolean
  • onDisconnect(): boolean
  • onError(): boolean
  • onEvent(eventName: string, defaultDataLoss: boolean): boolean
  • Returns true when the event got triggered by another p2p client.

    Parameters

    • eventName: string
    • defaultDataLoss: boolean

      Is data loss allowed (accelerates event handling when true)?

    Returns boolean

  • overrideId(id: string): void
  • Overrides the default peer ID. Must be called before connecting to a broker. Overriding the ID may have unwanted consequences. Do not use this feature unless you really know what you are doing.

    Parameters

    • id: string

      The peer ID to use when connecting to a broker.

    Returns void

  • sendDataTo(id: string, eventName: string, eventData: string): void
  • Send an event to one specific connected client.

    Parameters

    • id: string

      The ID of the client to send the event to.

    • eventName: string

      The event to trigger.

    • eventData: string

    Returns void

  • sendDataToAll(eventName: string, eventData: string): void
  • Send an event to all connected clients.

    Parameters

    • eventName: string

      The event to trigger.

    • eventData: string

    Returns void

  • sendVariableTo(id: string, eventName: string, variable: Variable): void
  • Send an event to one specific connected client.

    Parameters

    • id: string

      The ID of the client to send the event to.

    • eventName: string

      The event to trigger.

    • variable: Variable

      Additional variable to send with the event.

    Returns void

  • sendVariableToAll(eventName: string, variable: Variable): void
  • Send an event to all connected clients.

    Parameters

    • eventName: string

      The event to trigger.

    • variable: Variable

      Additional variable to send with the event.

    Returns void

  • useCustomBrokerServer(host: string, port: number, path: string, key: string, ssl: boolean): void
  • Connects to a custom broker server.

    Parameters

    • host: string

      The host of the broker server.

    • port: number

      The port of the broker server.

    • path: string

      The path (part of the url after the host) to the broker server.

    • key: string

      Optional password to connect to the broker server.

    • ssl: boolean

      Use ssl?

    Returns void

  • useCustomICECandidate(urls: string, username?: string, credential?: string): void
  • Adds an ICE server candidate, and removes the default ones provided by PeerJs. Must be called before connecting to a broker.

    Parameters

    • urls: string

      The URL of the STUN/TURN server.

    • Optional username: string

      An optional username to send to the server.

    • Optional credential: string

      An optional password to send to the server.

    Returns void

  • useDefaultBrokerServer(): void
  • Use default broker server. This is not recommended for published games, this server should only be used for quick testing in development.

    Returns void

Generated using TypeDoc