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
| Option | Type | Description |
|---|---|---|
| serverUrl | string | Server URL (https://voca.vc or your own) |
| apiKey | string | API key for authentication |
| password | string | Optional room password (4-12 alphanumeric characters) |
| reconnect | object | { enabled, maxAttempts, baseDelayMs } |
Methods
| Method | Returns | Description |
|---|---|---|
| connect() | Promise | Connect to room |
| disconnect() | void | Leave room |
| toggleMute() | boolean | Toggle mute, returns new state |
| on(event, callback) | Function | Subscribe to events, returns unsubscribe |
Utility Functions
| Function | Returns | Description |
|---|---|---|
| validatePassword(pwd) | string | null | Validate password format, returns error message or null |
Events
| Event | Payload |
|---|---|
| status | 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error' | 'full' |
| error | { code: VocaErrorCode, message: string } |
| warning | { code: string, message: string } |
| peer-joined | peerId: string |
| peer-left | peerId: string |
| peer-audio-level | (peerId: string, level: number) |
| local-audio-level | level: number (0-1) |
Error Codes
| Code | Description |
|---|---|
| ROOM_FULL | Room has reached max capacity |
| ROOM_NOT_FOUND | Room does not exist |
| CONNECTION_FAILED | Failed to establish connection |
| WEBSOCKET_ERROR | WebSocket connection error |
| MICROPHONE_NOT_FOUND | No microphone detected |
| MICROPHONE_PERMISSION_DENIED | User denied microphone access |
| INSECURE_CONTEXT | HTTPS required |
| INVALID_PASSWORD | Incorrect password provided |
| PASSWORD_REQUIRED | Room requires a password |