Get started →
Documentation

Browser SDK

@ruut/voice-sdk/browser provides a WebRTC softphone device that registers an agent extension over SIP/WSS and handles incoming and outgoing calls in the browser.

Install

npmbash

npm install @ruut/voice-sdk

Create a device

Provision an extension and fetch its credentials from your server, then create a RuutDevice:

Examplets

import { RuutDevice } from "@ruut/voice-sdk/browser";

const device = new RuutDevice({
  credentials: {
    username: creds.username,
    password: creds.password,
    domain: creds.domain,
    wsUrl: creds.ws_url,
    agentExtensionId: creds.id,
    restBaseUrl: creds.restBaseUrl,
    restAccountSid: creds.restAccountSid,
    restAuthToken: creds.restAuthToken,
  },
  audioElement: document.querySelector("audio"),
  logLevel: "info",      // "debug" to trace SIP
  traceSip: false,
});

Device events

Subscribe to lifecycle events:

Show an Accept / Reject UI, then:ts

device.on("registered", () => setStatus("online"));
device.on("unregistered", () => setStatus("offline"));
device.on("stateChanged", (state, prev) => console.log(state, prev));
device.on("transportDisconnected", (err) => console.warn("WSS dropped", err));
device.on("error", (err) => console.error(err));

device.on("incoming", (call) => {
  // Show an Accept / Reject UI, then:
  call.accept();      // or call.reject();
});

device.on("callStarted", (call) => showCall(call));
device.on("callEnded", (call) => clearCall(call));

Register

Examplets

await device.start();   // connects + registers
await device.register();   // re-register
await device.unregister(); // unregister (idle)
await device.stop();       // teardown

Place an outbound call

Examplets

const call = await device.connect("+2348000000001");       // E.164 number
const call2 = await device.connect("agent-1001");          // extension
const call3 = await device.connect("sip:trunk@pbx.example.com"); // SIP URI

During a call, use the returned RuutCall:

Exampletext

call.accept();
call.reject();
call.disconnect();       // hang up
call.mute(); / call.unmute();
call.hold(); / call.unhold();
call.sendDigits("123#");
call.transfer("+2348000000003");

Accept an inbound call

Examplets

device.on("incoming", async (call) => {
  const accepted = await call.accept();
  if (accepted) console.log("Call connected");
});

Presence

Keep the device registered while the agent is available so inbound calls and ring groups reach them. Set the agent's presence server-side with client.agentExtensions.update(sid, { status: "online" }) so ring-group routing includes them.

Next