UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

99 lines (74 loc) 3.38 kB
# Sinch RTC SDK for JavaScript The Sinch RTC SDK enables real-time **voice and video calling** directly in web applications. It provides a complete client-side solution for building in-app calling experiences in the browser. ## Features - **App-to-App Calling** — High-quality voice and video calls between users in your application - **App-to-PSTN Calling** — Call regular phone numbers directly from the browser - **App-to-SIP Calling** — Connect to SIP endpoints for enterprise telephony integration - **App-to-Conference Calling** — Join multi-party conference calls from the browser ## Prerequisites 1. [Register a Sinch account](https://dashboard.sinch.com/signup) 2. Create an application in the Dashboard to obtain an **Application Key** and **Application Secret** ## Installation ```bash npm install sinch-rtc ``` ## Quick Start ```javascript import { Sinch } from "sinch-rtc"; const sinchClient = Sinch.getSinchClientBuilder() .applicationKey("YOUR_APP_KEY") .userId("YOUR_USER_ID") .build(); sinchClient.addListener({ onClientStarted: (client) => { console.log("Sinch client started"); }, onClientFailed: (client, error) => { console.error("Sinch client failed", error); }, onCredentialsRequired: (client, registrationCallback) => { // Fetch a signed JWT from your backend and pass it to the callback. // Never embed the Application Secret in client-side code. fetch("/api/sinch-jwt?userId=YOUR_USER_ID") .then((res) => res.json()) .then(({ jwt }) => registrationCallback.register(jwt)); }, }); sinchClient.start(); ``` Please find more about how to generate JWT in our [documentation](https://developers.sinch.com/docs/in-app-calling/js/application-authentication). ## Making a Call ```javascript const callClient = sinchClient.getCallClient(); callClient.addListener({ onIncomingCall: (client, call) => { call.answer(); }, }); const call = callClient.callUser("REMOTE_USER_ID"); call.addListener({ onCallProgressing: (call) => { console.log("Ringing..."); }, onCallEstablished: (call) => { console.log("Call established"); }, onCallEnded: (call) => { console.log("Call ended"); }, }); ``` ## Key Components | Component | Description | | --------------- | ------------------------------------------------------------------------------------------------------ | | **SinchClient** | Primary entry point — manages configuration, authentication, and feature controllers | | **CallClient** | Exposes APIs to place and receive calls, notifies about incoming call events | | **Call** | Represents an active call with methods for answering, declining, and hanging up | | **Listeners** | `SinchClientListener`, `CallClientListener`, and `CallListener` provide callbacks for state and events | ## Documentation - [Getting Started Guide](https://developers.sinch.com/docs/in-app-calling/js/first-time-setup) - [Full API Reference](https://download.sinch.com/js/latest/reference/index.html) - [JavaScript Reference App](https://github.com/sinch/rtc-reference-applications/tree/master/javascript) - [Try the Live Sample](https://in-app.sinch.com/javascript/samples/index.html) ## License ISC