Events: {
    authenticate: [username: string, info: {
        auth?: string;
        isNewUser: boolean;
    }, reject: ((reason) => void)];
    close: [];
    join: [username: string];
    leave: [username: string];
    link: [username: string];
    listen: [port: number];
    message: [username: string, message: Message];
    unlink: [username: string];
}

Type declaration

  • authenticate: [username: string, info: {
        auth?: string;
        isNewUser: boolean;
    }, reject: ((reason) => void)]

    This event is emitted before a connection tries to link to a user.

    Param: username

    The username that the connection is trying to link to.

    Param: info

    Additional information about the connection trying to link to the user. info.isNewUser -- Whether this username belongs to a user already known to the server (false) or a new user that will be created if linking succeeds (true). info.auth -- An authentication token as a string, if provided by the client. That can be used to verify the authentication of the user. For example a JWT token.

    Param: reject

    A reject callback that, if invoked, will reject the linking to the user with the provided reason.

  • close: []

    This event is emitted once the server has closed.

  • join: [username: string]

    This event is emitted every time a user has joined.

    Param: username

    The username of the user that joined.

  • leave: [username: string]

    This event is emitted every time a user has left.

    Param: username

    The username of the user that left.

  • link: [username: string]

    This event is emitted every time a connection has linked to a user.

    Param: username

    The username of the user that was linked to a connection.

  • listen: [port: number]

    This event is emitted once the server has started listening and is ready to accept connections.

    Param: port

    The port at which the server started listening.

  • message: [username: string, message: Message]

    This event is emitted every time a user sends a message to the server.

    Param: username

    The username of the user that send the message.

    Param: message

    The content of the message that the user sent.

  • unlink: [username: string]

    This event is emitted every time a connection has unlinked from its user.

    Param: username

    The username of the user that was unlinked from its connection.