VoIP SDK for CemScale multi-tenant platform — API client, WebRTC, React hooks
Package Exports
@cemscale-voip/voip-sdk
@cemscale-voip/voip-sdk/hooks
Readme
@cemscale-voip/voip-sdk
TypeScript SDK for integrating CemScale VoIP into your application.
Installation
npminstall @cemscale-voip/voip-sdk
Authentication
Use an API Key to authenticate. Get one from the dashboard (API Keys page).
import{ VoIPClient }from'@cemscale-voip/voip-sdk';const voip =newVoIPClient({
apiUrl:'https://voip-api.cemscale.com',
apiKey:'csk_live_your_key_here',});// Ready. All methods work immediately.
That's it. No login, no passwords, no tokens to manage.
Examples
Click-to-call
// Call a phone number from extension 1001const{ callUuid }=await voip.originate({
fromExtension:'1001',
toNumber:'+15551234567',});// Control the callawait voip.holdCall(callUuid);await voip.transfer(callUuid,{ targetExtension:'1002', type:'blind'});await voip.hangup(callUuid);
// Link a CRM user to a VoIP extensionawait voip.updateCrmMapping('ext-id',{
crmUserId:'crm-user-123',
crmMetadata:{ department:'Sales'},});// Look up extension by CRM user (click-to-call from contact page)const{ extension }=await voip.getExtensionByCrmUser('crm-user-123');await voip.originate({ fromExtension: extension.extension, toNumber:'+15551234567'});
Real-Time Events (WebSocket)
voip.connectWebSocket();
voip.onWsEvent('call_start',(event)=>{console.log('New call:', event.data);});
voip.onWsEvent('presence_change',(event)=>{console.log(event.data.extension, event.data.status);});
voip.onWsEvent('call_end',(event)=>{// Log to CRMlogCallToCRM(event.data);});
// Create a key for a new integrationconst{ apiKey }=await voip.createApiKey({ name:'Mobile App', role:'readonly'});console.log(apiKey.key);// csk_live_... — save this, shown only once// List all keysconst{ apiKeys }=await voip.listApiKeys();// Revoke a keyawait voip.revokeApiKey('key-id');
Connecting a WebRTC Softphone
Your app doesn't need to know or store SIP passwords. Use the API key to fetch credentials on the fly:
// 1. Get SIP credentials for the extension (API key handles auth)const{ sipCredentials }=await voip.getSipCredentialsByNumber('1001');// sipCredentials = {// extension: "1001",// displayName: "Alice",// password: "auto-provided", <-- API returns it, your app doesn't store it// sipDomain: "sip.cemscale.com",// wsUri: "wss://sip.cemscale.com/ws",// registrar: "sip:sip.cemscale.com"// }// 2. Also get TURN credentials for NAT traversalconst turn =await voip.getTurnCredentials();
Two methods available:
Method
Use when
getSipCredentials(extensionId)
You have the extension UUID
getSipCredentialsByNumber('1001')
You have the extension number
WebRTC Softphone (Browser Only)
For building a browser-based softphone, use the WebRTCPhone class or the useVoIP React hook.
These require SIP credentials (extension + password), not an API key.