# Voice Quickstart | Signal House API Docs

> Get started with Signal House Voice: a WebRTC softphone in the browser, or server-side programmable calls over REST.

Source: https://docs.signalhouse.io/voice-quickstart

---

# Voice Quickstart

Get started with Signal House Voice using the SDK. There are two integration models: a **browser/mobile softphone** over WebRTC, and **server-side programmable calls** over REST. The browser softphone (`Device`/`Call`) is **JavaScript-only**, exposed from the `@signalhouse-sms/sdk/voice-browser` subpath; the REST voice surface (`sdk.voice.tokens`, `sdk.voice.calls`) lives in the JavaScript SDK's `voice` namespace.

**Prerequisites:** a Signal House account with an API credential, and at least one voice-capable phone number on the account to present as caller ID.

## 1\. Install & initialize

Install

```
npm install @signalhouse-sms/sdk jssip
```

`jssip` is an optional peer dependency, required only for the browser softphone (the `voice-browser` subpath). Server-only usage (tokens, calls) doesn't need it.

Initialize

```
import { SignalHouseSDK } from "@signalhouse-sms/sdk";

const signalHouse = new SignalHouseSDK({
    apiKey: "your-api-token",
    baseUrl: "https://v2.signalhouse.io",
});
```

## 2\. Mint a voice token (server-side)

Never ship your API credential to the browser. Mint a short-lived voice token on your server and hand it to the client — it embeds the ephemeral SIP credentials the softphone registers with.

**Receiving inbound calls?** You must pass `subgroupId` — the subgroup that owns the phone numbers you want to ring. Inbound calls to a DID fork to every softphone whose live token carries that DID's `subgroupId`. A token minted without `subgroupId` can still place outbound calls and register fine, but inbound calls will never reach it (they fall through to voicemail). Outbound-only softphones may omit it.

Server

```
// On your backend
const { data } = await signalHouse.voice.tokens.create({
    tokenData: {
        identity: "alice",       // your logical name for this user
        ttl: 1800,               // token lifetime, in seconds
        subgroupId: "S1A2B3C4",  // REQUIRED for inbound — the subgroup whose numbers ring this softphone
        grants: {
            voice: {
                incoming: { allow: true },
                outgoing: { allowedNumbers: ["+15551234567"] }, // DIDs this identity may present as caller ID
            },
        },
    },
});
// data => { token, identity, expires_at, sip_credentials: { username, password, domain, wss_url } }
// Return data to the browser (this is the object you pass to Device below).
```

## 3\. Register a browser softphone

In the browser, hand the token response to `Device` (from the `voice-browser` subpath), register, then place and receive calls.

Browser

```
import { Device } from "@signalhouse-sms/sdk/voice-browser";

const device = new Device(tokenResponse); // the /voice/tokens response from your server
await device.register();

// Outbound call
const call = await device.connect({ to: "+15557654321", from: "+15551234567" });

// Inbound call
device.on("incoming", (incoming) => incoming.accept());

// Lifecycle
device.on("registered", () => console.log("softphone ready"));
device.on("registrationFailed", (e) => console.error("register failed", e));
```

**Device events:** `registered`, `unregistered`, `registrationFailed`, `incoming`, `connected`, `disconnected`, `tokenWillExpire`, `tokenRefreshFailed`, `error`. The `from` caller ID must be a phone number owned by your account.

### Keep the token alive (required for long sessions)

Voice tokens are short-lived — a token's SIP credential authenticates only until its `expires_at`. If you let it lapse, the softphone can no longer re-register and **inbound calls stop arriving** (they go to voicemail). The Device raises `tokenWillExpire` shortly before expiry: get a fresh token from your server and hand it back via `updateToken()` (mirrors Twilio's `Device.updateToken()`).

**Prefer the refresh endpoint.** Have your backend call `POST /voice/tokens/refresh` — it *extends the same token in place* (same identity + credentials, new `expires_at`). The Device recognizes the unchanged identity and simply reschedules, keeping its existing registration — fully seamless, no re-register, safe even mid-call. If instead you mint a brand-new token (`POST /voice/tokens`), it carries a new identity, so the Device re-registers under it — the swap is deferred while a call is active so live audio is never disrupted.

Token refresh (manual)

```
// Fetch a fresh /voice/tokens response from YOUR backend, then apply it.
device.on("tokenWillExpire", async () => {
  const fresh = await fetch("/my/backend/voice-token").then((r) => r.json());
  await device.updateToken(fresh);
});
```

Or let the Device refresh itself — pass a `tokenProvider`: a function *you* write that returns a fresh token, minted the same server-side way as your first one (your backend → `POST /voice/tokens` → return the response to the browser). It's just step 2 wrapped in a function so the Device can call it again before each expiry. Contract: `() => Promise<tokenResponse>`.

Token refresh (automatic)

```
const device = new Device(tokenResponse, {
  // Same call you used to mint the initial token — hits YOUR backend, which
  // brokers to POST /voice/tokens. Never call the SignalHouse API from the browser.
  tokenProvider: () => fetch("/my/backend/voice-token").then((r) => r.json()),
  tokenRefreshMs: 30000, // raise tokenWillExpire ~30s before expiry (default)
});
await device.register();
```

## 4\. In-call controls

Call controls

```
call.accept();                                   // answer an inbound call
call.reject({ statusCode: 486, reason: "Busy Here" });
call.hangup();                                   // end the call

call.mute(true); call.unmute(); call.isMuted();
call.hold(true); call.unhold(); call.isOnHold();
call.transfer("+15559990000");                   // blind transfer

call.on("accepted", () => {});
call.on("ended", ({ cause }) => {});
```

Call status flows: `initial`/`ringing` → `in_progress` → `ended` | `failed`.

## 5\. Server-side programmable calls

Originate and control calls from your backend without a browser — for example, click-to-call to a registered identity via `to_identity`.

Server

```
const { data: call } = await signalHouse.voice.calls.create({
    callData: { to: "+15557654321", from: "+15551234567" }, // or { to_identity: "alice" }
});
// call => { call_id, status, direction, from, to, created_at }

await signalHouse.voice.calls.list({ filters: { page: 1, limit: 50 } });
await signalHouse.voice.calls.get({ id: call.call_id });
await signalHouse.voice.calls.hangup({ id: call.call_id, reason: "completed" });
```

**Good to know.** Voice tokens are short-lived — mint them per session on your server, never client-side. Caller ID (`from`) must be an account-owned DID; ownership is validated server-side. For the full endpoint reference, see the [Voice API documentation](https://docs.signalhouse.io/voice).
