Interface IConnectionService

This describes an object that manages the connection to Spyre services.

interface IConnectionService {
    get isConnected(): boolean;
    connect(): Promise<void>;
    disconnect(): void;
    init(deviceId: string): void;
    join(matchId: string, meta: Kv<string>, retries: number): Promise<Match>;
    leave(): Promise<void>;
    sendMatchState(matchId: string, opCode: number, payload: string | Uint8Array, retries?: number): Promise<void>;
}

Accessors

  • get isConnected(): boolean
  • True if and only if the client has a live socket connection with Spyre services. A heartbeat keeps this up to date within an epsilon.

    Returns boolean

Methods

  • Connects to the Spyre services. This must be called before any of the services will work.

    Returns Promise<void>

  • Initializes the connection service with a device ID. This must be called before any of the services will work.

    Parameters

    • deviceId: string

      A unique identifier for this device. Generally used with the getDeviceId() function.

    Returns void

  • Joins a match with the given match ID and metadata. The metadata is a key-value map of strings.

    Parameters

    • matchId: string

      The match ID to join.

    • meta: Kv<string>

      A key-value map of strings.

    • retries: number

      The number of times to retry if the join fails.

    Returns Promise<Match>

    A promise that resolves to the match object.

    If the match cannot be joined.

  • Sends a message to the match with the given op code and payload. The payload can be a string or a byte array.

    Parameters

    • matchId: string

      The match ID to send the message to.

    • opCode: number

      The operation code.

    • payload: string | Uint8Array

      The payload to send.

    • Optionalretries: number

      The number of times to retry if the message cannot be sent.

    Returns Promise<void>