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
Properties
VoiceServer.clock :: ClockVoiceServer.udpServer :: UdpServerVoiceServer.onStop :: function?VoiceServer.server :: any?VoiceServer.port :: numberVoiceServer.url :: stringVoiceServer.connections :: { Connection }VoiceServer.received :: { Received }VoiceServer.pendingPaths :: { string }VoiceServer.heartbeatIntervalMilliseconds :: numberVoiceServer.modes :: { string }VoiceServer.daveProtocolVersion :: numberVoiceServer.token :: stringVoiceServer.sessionId :: stringVoiceServer.serverId :: string?VoiceServer.ssrc :: numberVoiceServer.secretKey :: bufferVoiceServer.selectedMode :: string?VoiceServer.sequence :: numberVoiceServer.errors :: { string }VoiceServer.ackHeartbeats :: booleanVoiceServer.refuseUpgrades :: numberVoiceServer.upgradeDelaySeconds :: numberVoiceServer.handshaking :: booleanMethods
VoiceServer:sendJson(opcode: number, data: any)VoiceServer:sendBinary(opcode: number, payload: buffer)VoiceServer:sendSpeaking(userId: string, ssrc: number, speaking: number)VoiceServer:sendClientsConnect(userIds: { string })VoiceServer:sendClientDisconnect(userId: string)VoiceServer:close(code: number?)VoiceServer:receivedOps() → { number }VoiceServer:waitForOp(opcode: number, seconds: number) → booleanVoiceServer:stop()Properties
Section titled “Properties”The world clock: received records are stamped with it and waitForOp polls in it.
udpServer
Section titled “udpServer”The UDP server whose port Ready announces.
onStop
Section titled “onStop”Called with the handle after it stops.
server
Section titled “server”The Zune server handle, nil after it stops.
The ephemeral port the server bound to.
The server's URL with its scheme, ws://127.0.0.1:{port}, which VOICE_SERVER_UPDATE carries as endpoint.
connections
Section titled “connections”Every connection ever opened, in open order; a closed one stays with open = false.
received
Section titled “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 }.
pendingPaths
Section titled “pendingPaths”Paths of accepted upgrades whose connection has not opened yet, oldest first.
heartbeatIntervalMilliseconds
Section titled “heartbeatIntervalMilliseconds”The interval Hello and Ready announce, 41250 by default.
The encryption modes Ready offers; Select Protocol with any other mode is closed with 4016.
daveProtocolVersion
Section titled “daveProtocolVersion”The DAVE protocol version Session Description announces, 0 (no end-to-end encryption) by default.
The voice token VOICE_SERVER_UPDATE hands out and a Resume must carry.
sessionId
Section titled “sessionId”The voice session id VOICE_STATE_UPDATE hands out and a Resume must carry.
serverId
Section titled “serverId”The server_id the latest Identify carried, which a Resume must match; nil before the first Identify.
The SSRC Ready assigns, 1234 by default.
secretKey
Section titled “secretKey”The 32-byte key Session Description hands out as secret_key.
selectedMode
Section titled “selectedMode”The mode the latest accepted Select Protocol chose, nil before one.
sequence
Section titled “sequence”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.
errors
Section titled “errors”Every error raised while answering a message, which Zune would otherwise print and swallow.
ackHeartbeats
Section titled “ackHeartbeats”Whether a Heartbeat is answered with an ACK; true by default. False makes the client miss its ACKs.
refuseUpgrades
Section titled “refuseUpgrades”How many of the next upgrades to refuse; each refusal fails the client's connect with UpgradeFailed.
upgradeDelaySeconds
Section titled “upgradeDelaySeconds”Clock seconds each upgrade is held before it is answered, 0 for none.
handshaking
Section titled “handshaking”True while an upgrade is held by upgradeDelaySeconds.
Methods
Section titled “Methods”sendJson
Section titled “sendJson”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 |
sendBinary
Section titled “sendBinary”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 |
sendSpeaking
Section titled “sendSpeaking”VoiceServer : sendSpeaking ( userId , ssrc , speaking ) -> ()
Sends Speaking (op 5) for userId on ssrc with the speaking flags.
sendClientsConnect
Section titled “sendClientsConnect”VoiceServer : sendClientsConnect ( userIds ) -> ()
Sends Clients Connect (op 11) listing userIds.
Parameters
| userIds: { string } |
sendClientDisconnect
Section titled “sendClientDisconnect”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? |
receivedOps
Section titled “receivedOps”VoiceServer : receivedOps ( ) -> { number }
The opcode of every received message, in arrival order.
Returns
| { number } |
waitForOp
Section titled “waitForOp”VoiceServer : waitForOp ( opcode , seconds ) -> boolean
Waits up to seconds of clock time for a message with opcode to have arrived. Returns whether one did.
VoiceServer : stop ( ) -> ()
Stops listening, closing every open connection with 1000 first. The UDP server is left running. Safe to call twice.
Functions
Section titled “Functions”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 |