Voice SDKs
...
Getting Started
Web Client SDK APIs and Integration Workflow
9 min
web client sdk apis and integration workflow initialize library webrtc client sdk library needs to be initialized prior to using a sample code snippet to do so is as below step1 import the exotel client library as below import { exotelwebclient as exwebclient } from '@exotel/webrtc client sdk'; step2 initialize the exotel web client with sipaccountinfo and callbacks using the api initwebrtc // initialise sipaccountinfo dictionary const sipaccountinfo = { 'username' ‘username’, 'authuser' ‘username’, 'sipdomain' ‘domain’, 'domain' ‘hostserver’ + " " + port 'displayname' ‘displayname’, 'secret' ‘password’, 'port' ‘port’, 'security' ‘wss’, } // initialize callbacks exwebclient initwebrtc(sipaccountinfo, registereventcallback, calllistenercallback, sessioncallback) this api also takes as input three callbacks registereventcallback handles registration states as they change calllistenercallback handles call events as they occur sessioncallback handles notifications for multiple tab sessions the details of the callbacks are explained in the corresponding flows argument details args datatype sipaccountinfo object registereventcallback callback function calllistenercallback callback function sessioncallback callback function sipaccountinfo authuser string sip username to register username string used as a unique map index for phones same as authuser displayname string local displayname on dialer secret string sip password sipdomain string sip public domain security string “wss”/”ws” typically “wss” port string 443 for websockets opus codec preference optional to enable opus codec, it can be enabled from exotel voip domain settings, for that we can raise a request to hello\@exotel com to enable the opus codec support once opus codec is enabled, then and if browser is not preferring opus codec in sip 200 ok, then we have an api to make opus codec as preferred codec exwebclient setpreferredcodec(“opus”); download logs optional to help with debugging or sharing logs with support, whenever a user faces an issue, we can invoke the downloadlogs method this will download a “ txt” file (e g ”webrtc sdk logs 2025 04 03 txt” ) containing 1000 logs stored in the browser’s localstorage exwebclient downloadlogs(); register the sip phones before receiving / making any call, the sip phone needs to be registered; and the api for this purpose is “doregister” api name exotelwebclient doregister args none exported to application ui //ensure that initwebrtc is invoked before calling doregister exwebclient doregister(); once the registration has been done, the response comes in the registrationcallback with the events, “registered ”/ ”terminated” as below api name registereventcallback args params type values state string "registered" / “terminated” / “sent request” / “unregistered” phone string username exported to application ui function registereventcallback (state, phone){ if (state === 'registered') { // successful registration setregstate(true) } else if (state === 'unregistered') { // successful unregistration setregstate(false) } else if (state === 'terminated') { // registration/unregistration failed setregstate(false) } else if (state === 'sent request') { // registration/unregistration request sent if (unregisterwait === "true") { unregisterwait = "false"; setregstate(false) } } } unregister the sip phones to stop getting calls anymore, the sip phones need to be unregistered the api to do so is “unregister” api name exotelwebclient unregister args none exported to application ui //ensure that initwebrtc is invoked before calling doregister exwebclient unregister(); the response to unregistration comes in the registrationcallback as below api name registereventcallback args params type values state string "registered" / "unregistered" / “terminated” / “sent request” phone string username exported to application ui function registereventcallback (state, phone){ if (state === 'registered') { // successful registration setregstate(true) } else if (state === 'unregistered') { // successful unregistration setregstate(false) } else if (state === 'terminated') { // registration/unregistration failed setregstate(false) } else if (state === 'sent request') { // registration/unregistration request sent if (unregisterwait === "true") { unregisterwait = "false"; setregstate(false) } } } note 1 if you have more than one phone, the second argument “phone” would give the indication as to which phone got unregistered
🤔
Have a question?
Our knowledgeable support team and an awesome community will get you an answer in a flash.
To ask a question or participate in discussions, you'll need to authenticate first.