A socket connection to Nakama server implemented with the DOM's WebSocket API.

Hierarchy

  • DefaultSocket

Implements

Constructors

Properties

_heartbeatTimeoutMs: number
adapter: WebSocketAdapter = ...
cIds: {
    [key: string]: PromiseExecutor;
}

Type declaration

  • [key: string]: PromiseExecutor
host: string
nextCid: number
port: string
sendTimeoutMs: number = DefaultSocket.DefaultSendTimeoutMs
useSSL: boolean = false
verbose: boolean = false
DefaultConnectTimeoutMs: 30000 = 30000
DefaultHeartbeatTimeoutMs: 10000 = 10000
DefaultSendTimeoutMs: 10000 = 10000

Methods

  • Join the matchmaker pool and search for opponents on the server.

    Parameters

    • query: string
    • min_count: number
    • max_count: number
    • Optional string_properties: Record<string, string>
    • Optional numeric_properties: Record<string, number>

    Returns Promise<MatchmakerTicket>

  • Begin matchmaking as a party.

    Parameters

    • party_id: string
    • query: string
    • min_count: number
    • max_count: number
    • Optional string_properties: Record<string, string>
    • Optional numeric_properties: Record<string, number>

    Returns Promise<PartyMatchmakerTicket>

  • End a party, kicking all party members and closing it.

    Parameters

    • party_id: string

    Returns Promise<void>

  • Connect to the server.

    Parameters

    • session: Session
    • createStatus: boolean = false
    • connectTimeoutMs: number = DefaultSocket.DefaultConnectTimeoutMs

    Returns Promise<Session>

  • Disconnect from the server.

    Parameters

    • fireDisconnectEvent: boolean = true

    Returns void

  • Join a chat channel on the server.

    Parameters

    • target: string
    • type: number
    • persistence: boolean
    • hidden: boolean

    Returns Promise<Channel>

  • Join a multiplayer match.

    Parameters

    • Optional match_id: string
    • Optional token: string
    • Optional metadata: {}

      Returns Promise<Match>

    • Leave a chat channel on the server.

      Parameters

      • channel_id: string

      Returns Promise<void>

    • Leave a multiplayer match on the server.

      Parameters

      • matchId: string

      Returns Promise<void>

    • Receive channel message.

      Parameters

      • channelMessage: ChannelMessage

      Returns void

    • Handle disconnect events received from the socket.

      Parameters

      • evt: Event

      Returns void

    • Handle error events received from the socket.

      Parameters

      • evt: Event

      Returns void

    • An application-level heartbeat timeout that fires after the client does not receive a pong from the server after the heartbeat interval. Most browsers maintain an internal heartbeat, in which case its unlikely you'll need to use this callback. However, Chrome does not implement an internal heartbeat. We fire this separately from onclose because heartbeats fail when there's no connectivity, and many browsers don't fire onclose until the closing handshake either succeeds or fails. In any case, be aware that onclose will still fire if there is a heartbeat timeout in a potentially delayed manner.

      Returns void

    • Receive party close events.

      Parameters

      • close: PartyClose

      Returns void

    • Cancel a party matchmaking process using a ticket.

      Parameters

      • party_id: string
      • ticket: string

      Returns Promise<void>

    • Execute an RPC function to the server.

      Parameters

      • Optional id: string
      • Optional payload: string
      • Optional http_key: string

      Returns Promise<ApiRpc>

    • Parameters

      • message: ChannelJoin | ChannelLeave | ChannelMessageSend | ChannelMessageUpdate | ChannelMessageRemove | MatchmakerAdd | MatchmakerRemove | CreateMatch | JoinMatch | LeaveMatch | MatchDataSend | PartyCreate | PartyJoin | PartyLeave | PartyPromote | PartyAccept | PartyClose | PartyDataSend | PartyJoinRequestList | PartyMatchmakerAdd | PartyMatchmakerRemove | PartyRemove | Rpc | Ping | StatusFollow | StatusUnfollow | StatusUpdate
      • sendTimeout: number = DefaultSocket.DefaultSendTimeoutMs

      Returns Promise<any>

    • When no presences are supplied the new match state will be sent to all presences.

      Parameters

      • matchId: string
      • opCode: number
      • data: string | Uint8Array
      • Optional presences: Presence[]
      • Optional reliable: boolean

      Returns Promise<void>

    • Send data to a party.

      Parameters

      • party_id: string
      • op_code: number
      • data: string | Uint8Array

      Returns Promise<void>

    • Unfollow one or more users from their status updates.

      Parameters

      • user_ids: string[]

      Returns Promise<void>

    • Update the status for the current user online.

      Parameters

      • Optional status: string

      Returns Promise<void>

    Generated using TypeDoc