@revdesk/webrtc
v0.1.2
Published
Official RevDesk browser-calling client. Place and receive calls in the browser through the RevDesk voice network.
Maintainers
Readme
@revdesk/webrtc
Official browser-calling client for RevDesk. Place and receive phone calls directly in the browser through the RevDesk voice network — one branded surface, two connection paths, zero infrastructure to run.
Install
npm install @revdesk/webrtc
# or: bun add @revdesk/webrtcPair it with @revdesk/sdk to issue the call tokens
from your server.
Two paths, one surface
Both clients emit the same lifecycle events (callUpdate, error, ended) and the same
CallState, so your UI doesn't change when you switch paths.
Browser-direct — RevDeskRTC
The browser connects to the RevDesk voice network and places the call itself.
import { RevDeskRTC } from "@revdesk/webrtc";
// Token issued server-side via @revdesk/sdk: revdesk.webrtc.getToken({ from_number, to_number })
const call = new RevDeskRTC({ token });
call.on("callUpdate", ({ state }) => console.log(state)); // connecting → ringing → active → ended
call.on("error", (err) => console.error(err.code, err.message));
await call.connect();
call.dial({ to: "+15554560000", from: "+15551230000" });
// later…
call.mute();
call.sendDTMF("1"); // out-of-band IVR input; no local keypad tone is mixed into the mic
call.hangup();RevDeskRTC also emits structured Telnyx media warnings so packet loss, jitter, low audio, and
recovery events can be tied to a specific test call without collecting audio or network addresses:
call.on("qualityWarning", ({ code, name, message }) => {
console.warn(code, name, message);
});
// Aggregated counts, codec preference, and remote-playback recovery attempts.
console.log(call.getQualityReport());Relay — RevDeskRoom
RevDesk places the outbound call and the browser joins it. The browser never touches the destination network directly.
import { RevDeskRoom } from "@revdesk/webrtc";
// Token issued server-side: revdesk.webrtc.getRoomToken({ from_number, to_number })
const call = new RevDeskRoom({ token, roomUrl, callId });
call.on("callUpdate", ({ state }) => console.log(state));
await call.join();
call.setMuted(true);
call.leave();Call state
callUpdate carries the current state:
| State | Meaning |
| -------------- | -------------------------------------- |
| idle | created, not started |
| connecting | establishing the connection |
| ringing | placed, awaiting the other party |
| active | connected, audio flowing |
| held | active call temporarily on hold |
| reconnecting | media recovering after an interruption |
| ended | finished normally |
| error | failed (see the error event) |
Errors
The error event delivers a RevDeskCallError with a machine-readable code
(connection_failed, connection_timeout, call_rejected, …):
import { RevDeskCallError } from "@revdesk/webrtc";
call.on("error", (err: RevDeskCallError) => {
if (err.code === "call_rejected") {
/* the destination declined */
}
});Audio element (RevDeskRTC)
By default RevDeskRTC manages remote audio for you. To route it to a specific element, pass one:
new RevDeskRTC({ token, remoteAudioElement: document.querySelector("audio")! });License
MIT
