Skip to content

VoiceServer

A localhost voice gateway speaking version 8: Hello on open, Ready on Identify, Session Description on Select Protocol, an ACK echoing t on Heartbeat, and Resumed (or close 4006) on Resume. Ready points the client at a UdpServer. Every message the client sends is recorded with its raw text or binary buffer, and the test scripts the rest: Speaking, Clients Connect, Client Disconnect, or any JSON or binary opcode. Tests can withhold heartbeat ACKs, refuse or hold upgrades (ackHeartbeats, refuseUpgrades, upgradeDelaySeconds).

Summary

VoiceServer.clock  :: Clock

The world clock: received records are stamped with it and waitForOp polls in it.

VoiceServer.udpServer  :: UdpServer

The UDP server whose port Ready announces.

VoiceServer.onStop  :: function?

Called with the handle after it stops.

VoiceServer.server  :: any?

The Zune server handle, nil after it stops.

VoiceServer.port  :: number

The ephemeral port the server bound to.

VoiceServer.url  :: string

The server's URL with its scheme, ws://127.0.0.1:{port}, which VOICE_SERVER_UPDATE carries as endpoint.

VoiceServer.connections  :: { Connection }

Every connection ever opened, in open order; a closed one stays with open = false.

VoiceServer.received  :: { Received }

Every message any connection sent, in arrival order: its opcode, the decoded payload, the raw text or binary buffer, and the clock time it arrived. A binary message decodes to { op = opcode, d = payload buffer }.

VoiceServer.pendingPaths  :: { string }

Paths of accepted upgrades whose connection has not opened yet, oldest first.

VoiceServer.heartbeatIntervalMilliseconds  :: number

The interval Hello and Ready announce, 41250 by default.

VoiceServer.modes  :: { string }

The encryption modes Ready offers; Select Protocol with any other mode is closed with 4016.

VoiceServer.daveProtocolVersion  :: number

The DAVE protocol version Session Description announces, 0 (no end-to-end encryption) by default.

VoiceServer.token  :: string

The voice token VOICE_SERVER_UPDATE hands out and a Resume must carry.

VoiceServer.sessionId  :: string

The voice session id VOICE_STATE_UPDATE hands out and a Resume must carry.

VoiceServer.serverId  :: string?

The server_id the latest Identify carried, which a Resume must match; nil before the first Identify.

VoiceServer.ssrc  :: number

The SSRC Ready assigns, 1234 by default.

VoiceServer.secretKey  :: buffer

The 32-byte key Session Description hands out as secret_key.

VoiceServer.selectedMode  :: string?

The mode the latest accepted Select Protocol chose, nil before one.

VoiceServer.sequence  :: number

The last sequence number the server handed out. Scripted JSON messages carry it as seq, and binary messages carry it as their 2-byte big-endian prefix.

VoiceServer.errors  :: { string }

Every error raised while answering a message, which Zune would otherwise print and swallow.

VoiceServer.ackHeartbeats  :: boolean

Whether a Heartbeat is answered with an ACK; true by default. False makes the client miss its ACKs.

VoiceServer.refuseUpgrades  :: number

How many of the next upgrades to refuse; each refusal fails the client's connect with UpgradeFailed.

VoiceServer.upgradeDelaySeconds  :: number

Clock seconds each upgrade is held before it is answered, 0 for none.

VoiceServer.handshaking  :: boolean

True while an upgrade is held by upgradeDelaySeconds.

VoiceServer : sendJson ( opcode ,  data )  -> ()

Sends { op = opcode, d = data, seq } as JSON to every open connection under the next sequence number.

Parameters

opcode: number
data: any
VoiceServer : sendBinary ( opcode ,  payload )  -> ()

Sends a binary message to every open connection: the next sequence number as 2 big-endian bytes, the opcode as 1 byte, then payload.

Parameters

opcode: number
payload: buffer
VoiceServer : sendSpeaking ( userId ,  ssrc ,  speaking )  -> ()

Sends Speaking (op 5) for userId on ssrc with the speaking flags.

Parameters

userId: string
ssrc: number
speaking: number
VoiceServer : sendClientsConnect ( userIds )  -> ()

Sends Clients Connect (op 11) listing userIds.

Parameters

userIds: { string }
VoiceServer : sendClientDisconnect ( userId )  -> ()

Sends Client Disconnect (op 13) for userId.

Parameters

userId: string
VoiceServer : close ( code )  -> ()

Closes every open connection with code (1000 by default).

Parameters

code: number?
VoiceServer : receivedOps ( )  -> { number }

The opcode of every received message, in arrival order.

Returns

{ number }
VoiceServer : waitForOp ( opcode ,  seconds )  -> boolean

Waits up to seconds of clock time for a message with opcode to have arrived. Returns whether one did.

Parameters

opcode: number
seconds: number

Returns

boolean
VoiceServer : stop ( )  -> ()

Stops listening, closing every open connection with 1000 first. The UDP server is left running. Safe to call twice.

VoiceServer . new ( settings )  -> VoiceServer

Creates and starts the server on 127.0.0.1 with an ephemeral port. The clock defaults to a real one.

Parameters

settings: {
clock: clock.Clock?,
udpServer: udpServer.UdpServer,
heartbeatIntervalMilliseconds: number?,
modes: { string,
}

Returns

VoiceServer