API Reference

@treyorr/voca-client

VocaClient.createRoom(config?)

Creates a new room on the server and returns a client instance.

const client = await VocaClient.createRoom({
  serverUrl: 'https://voca.vc',
  apiKey: 'T8izjz8JpcWa3mtuhOFwprVk77uZKIzn',
  password: 'secret123' // Optional: 4-12 alphanumeric chars
});
console.log(client.roomId); // e.g. "abc123"

new VocaClient(roomId, config?)

Join an existing room by ID.

const client = new VocaClient('abc123', config);

Config Options

OptionTypeDescription
serverUrlstringServer URL (https://voca.vc or your own)
apiKeystringAPI key for authentication
passwordstringOptional room password (4-12 alphanumeric characters)
reconnectobject{ enabled, maxAttempts, baseDelayMs }

Methods

MethodReturnsDescription
connect()PromiseConnect to room
disconnect()voidLeave room
toggleMute()booleanToggle mute, returns new state
on(event, callback)FunctionSubscribe to events, returns unsubscribe

Utility Functions

FunctionReturnsDescription
validatePassword(pwd)string | nullValidate password format, returns error message or null

Events

EventPayload
status'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error' | 'full'
error{ code: VocaErrorCode, message: string }
warning{ code: string, message: string }
peer-joinedpeerId: string
peer-leftpeerId: string
peer-audio-level(peerId: string, level: number)
local-audio-levellevel: number (0-1)

Error Codes

CodeDescription
ROOM_FULLRoom has reached max capacity
ROOM_NOT_FOUNDRoom does not exist
CONNECTION_FAILEDFailed to establish connection
WEBSOCKET_ERRORWebSocket connection error
MICROPHONE_NOT_FOUNDNo microphone detected
MICROPHONE_PERMISSION_DENIEDUser denied microphone access
INSECURE_CONTEXTHTTPS required
INVALID_PASSWORDIncorrect password provided
PASSWORD_REQUIREDRoom requires a password