Skip to content

Connection

One accepted websocket, on the gateway or the voice gateway: where it was dialled, which session it is bound to, and every message the client sent on it.

Connection.index  :: number

The connection's place in its server's open order, from 1.

Connection.sessionId  :: string?

The session the server bound this connection to by answering it with READY or RESUMED, or the voice Ready or Resumed.

Connection.path  :: string

The upgrade path with one trailing / removed: a resume dial records /resume, a fresh dial /.

Connection.socket  :: HttpWebSocket

The Zune server socket.

Connection.open  :: boolean

False once the server's close callback has run for this connection.

Connection.closeCode  :: number?

The code the server's close callback reported, nil while open.

Connection.received  :: { Received }

Every message the client sent: its opcode, the decoded payload, the raw text or binary buffer, and the world clock's time it arrived.

Connection : sendRaw ( message )  -> boolean

Sends one message as it is, a string as a text frame and a buffer as a binary frame, and returns whether it went. Zune throws once the socket is closing, before the server's close callback clears open, so a send to a closing socket returns false.

Parameters

message: string | buffer

Returns

boolean
Connection : send ( payload )  -> boolean

Sends one payload as JSON text and returns whether it went, as sendRaw does.

Parameters

payload: Payload

Returns

boolean
Connection : close ( code )  -> ()

Closes the connection with code (1000 by default). Closing a socket that is already closing does nothing.

Parameters

code: number?
Connection : receivedOps ( opcode )  -> { Received }

Returns the records of every received payload with opcode, oldest first.

Parameters

opcode: number

Returns

{ Received }
Connection . find ( connections ,  socket )  -> Connection?

Returns the connection in connections that wraps socket, nil when none does.

Parameters

connections: { Connection }
socket: ZuneSocket

Returns

Connection?
Connection . new ( settings )  -> Connection

Wraps a server socket the moment it opens.

Parameters

settings: {
index: number,
path: string,
socket: ZuneSocket,
}

Returns

Connection