jetlag2d
    Preparing search index...

    Class NetworkDevice

    NetworkDevice interfaces with a server (see the "templates/server" folder) via socket.io to send and receive network events.

    Naming convention: every incoming event handler is onX (assign your own function to react to it); every outgoing action is requestX (for anything the server can accept or reject) or a bare verb that pairs with connect() (disconnect(), sendBroadcast()).

    Index
    onBroadcast: (msg: string) => void = ...

    An event handler for when a remote user sends a message

    onConnected: () => void = ...

    An event handler for when the socket initially connects

    onCreated: (msg: string) => void = ...

    An event handler for when we succeed in making a new room

    onDisconnected: (msg: string) => void = ...

    An event handler for when the socket disconnects

    onErrFormat: (msg: string) => void = ...

    An event handler for errors due to incorrectly formatted requests

    onErrHasRoom: (msg: string) => void = ...

    An event handler for when we request a room but already have one

    onErrHasUser: (msg: string) => void = ...

    An event handler for when we try to log in when we're already logged in

    onErrNoRoom: (msg: string) => void = ...

    An event handler for errors due to not having a room

    onErrNoUser: (msg: string) => void = ...

    An event handler for errors due to not logging in first

    onErrUserTaken: (msg: string) => void = ...

    An event handler for when the server says our username is taken

    onErrVersion: (msg: string) => void = ...

    An event handler for when the server turns us away because it uses a different version of the protocol. The server disconnects right after.

    onJoined: (msg: string) => void = ...

    An event handler for when we succeed in joining an existing room

    onLoggedIn: (msg: string) => void = ...

    An event handler for when a login request succeeds

    onLoggedOut: (msg: string) => void = ...

    An event handler for when a logout request succeeds

    onSent: (msg: string) => void = ...

    An event handler for when a broadcast is sent successfully

    onUserJoined: (msg: string) => void = ...

    An event handler for when a remote user joins the room

    onUserLeft: (msg: string) => void = ...

    An event handler for when a remote user exits the room

    socket: Socket<DefaultEventsMap, DefaultEventsMap> | undefined

    A socket for communicating with the server

    state: NetworkState = NetworkState.Start

    The current state of the network stack

    • Connect to a server and start sending/receiving events

      Parameters

      • serverAddress: string

        The address of the server to connect to

      Returns void

    • Send a message to the server to try to join an existing room

      Parameters

      • roomId: string

        The Id of the room to join

      Returns void

    • Send a message to the server to try to log in

      Parameters

      • userId: string

        The desired userId

      • userName: string

        The desired userName

      Returns void

    • Broadcast a message to all other recipients in the room

      Parameters

      • message: string

        The message to send

      Returns void