Options
All
  • Public
  • Public/Protected
  • All
Menu

Tools for p2p multiplayer.

namespace

Index

Functions

  • connect(id: string): void
  • Connects to another p2p client.

    Parameters

    • id: string

      The other client's ID.

    Returns void

  • disconnectFromAll(): void
  • Disconnects from all peers and the broker server.

    Returns void

  • disconnectFromAllPeers(): void
  • Disconnects from all other p2p clients.

    Returns void

  • disconnectFromBroker(): void
  • Disconnects from the broker server, leaving the connections intact.

    Returns void

  • disconnectFromPeer(id: string): void
  • Disconnects from another p2p client.

    Parameters

    • id: string

      The other client's ID.

    Returns void

  • getConnectedPeer(): string
  • Get the ID of the peer that triggered onConnection.

    Returns 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
  • Returns the own current peer ID.

    see

    Peer.id

    Returns string

  • getDisconnectedPeer(): string
  • Get the ID of the peer that triggered onDisconnect.

    Returns string

  • getEvent(name: string): Event
  • Get an event, and creates it if it doesn't exist.

    Parameters

    • name: string

    Returns Event

  • 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

  • getLastError(): string
  • Returns the latest error message.

    Returns string

  • isReady(): boolean
  • Returns true once PeerJS finished initialization.

    see

    ready

    Returns boolean

  • onConnection(): boolean
  • Returns true once if a remote peer just initiated a connection.

    Returns boolean

  • onDisconnect(): boolean
  • Returns true once a peer disconnected.

    Returns boolean

  • onError(): boolean
  • Returns true once when there is an error.

    Returns 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