Browser SDK

The Plivo Browser SDK lets you make and receive calls via Plivo applications directly from any web browser that supports WebRTC. Using our SDK you can create applications like click to call, conferencing, and web phones. We support the most recent and previous 10 versions of Chrome and Firefox, and the most recent and previous five versions of Safari.

Getting started with example applications

To see how to use Browser SDK, let’s walk through some simple code. Our example applications are a good introduction, and we call out some key points below.

Include the JavaScript

Include the Plivo JavaScript file:

<script type="text/javascript" src=""/>

Initialize the plivoBrowserSdk object

The plivoBrowserSdk object needs to be initialized.

var options = {
var plivoBrowserSdk = new window.Plivo(options);

Event registration

Pass function references to the events produced from the SDK. This is where your UI manipulation should handle all the different call flows.

plivoBrowserSdk.client.on('onWebrtcNotSupported', onWebrtcNotSupported);
plivoBrowserSdk.client.on('onLogin', onLogin);
plivoBrowserSdk.client.on('onLogout', onLogout);
plivoBrowserSdk.client.on('onLoginFailed', onLoginFailed);
plivoBrowserSdk.client.on('onCallRemoteRinging', onCallRemoteRinging);
plivoBrowserSdk.client.on('onIncomingCallCanceled', onIncomingCallCanceled);
plivoBrowserSdk.client.on('onCallFailed', onCallFailed);
plivoBrowserSdk.client.on('onCallAnswered', onCallAnswered);
plivoBrowserSdk.client.on('onCallTerminated', onCallTerminated);
plivoBrowserSdk.client.on('onCalling', onCalling);
plivoBrowserSdk.client.on('onIncomingCall', onIncomingCall);
plivoBrowserSdk.client.on('onMediaPermission', onMediaPermission);

Register using your Plivo endpoint

Register using your Plivo endpoint credentials.

var username = 'johndoe12345';
var password = 'XXXXXXXX';
plivoBrowserSdk.client.login(username, password);

Make a call

Make a call to any phone number or SIP endpoint. The application attached to a  registered endpoint should have an answer URL that ensures that the correct <Dial> element is returned.

var dest = “”;
var extraHeaders = {'X-PH-Test1': 'test1', 'X-PH-Test2': 'test2'};, extraHeaders);

Accept a call

Answer an incoming call when an onIncomingCall event is received.


Send a DTMF tone

Send a DTMF tone when in a phone call.



Here are the configuration parameters:

AttributeDescriptionAllowed ValuesDefault Value
debugEnable debug message in JS logOFF, ERROR, WARN, INFO, DEBUG, ALLINFO
permOnClickSet to true if you want to ask for mic permission before call. Otherwise, permission will be requested on page load.true/falsefalse
audioConstraintsAudio constraints object that will be passed to WebRTC getUserMedia().Audio constraints values are browser-specific. These values can be set to true or false: googEchoCancellation, googAutoGainControl, googNoiseSuppression, googHighpassFilter{}
enableTrackingSet to true if you want to get MediaMetrics events and enable call quality tracking.true/falsetrue
dscpSet to true if you want to enable QoS in voice traffic. Differentiated Services field in the packet headers for all WebRTC traffic.true/falsetrue
preDetectOwaDetect one-way audio before answering or sending the call.true/falsefalse
clientRegionInitialization options to set and route calls to specific MediaServer PoPs["usa_west","usa_east","australia","europe","asia","south_america"] 



These are the methods supported on plivoBrowserSdk.client


These methods are supported on (supported only on Chrome).

login(username, password)Register a Plivo endpoint
logout()Log out from the registered endpoint
call(number, extraHeaders)Call a number or SIP address. "number" takes a String value and "extraHeaders" takes a JSON object.
Example of "extraHeaders":
{'X-PH-Test1': 'test1', 'X-PH-Test2': 'test2'}
answer()Answer an incoming call
hangup()Hang up an ongoing call
reject()Reject an incoming call
sendDtmf(digit)Send digits as DTMF.
"digit" can be any of the following one-character strings: "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "*", "#"
mute()Mute the mic
unmute()Unmute the mic
setRingTone(url)Set the ringtone that plays when calling. The default tone will be used if the URL is not specified.
setRingToneBack(url)Set the ringtone that plays when being called. The default tone will be used if the URL is not specified.
setConnectTone(boolean)The dial beep that will play until we get an alert response from network. Setting "false" will not play the beep tone. Default is "true," connect tone is enabled.
setDebug(debug)Set the log level of the SDK. Allowed values are OFF, ERROR, WARN, INFO, DEBUG, ALL.
getPeerConnection()Returns an RTCPeerConnection object.
sendQualityFeedback(score, comment)Send call quality feedback at the end of a call. "score" can take an integer value between 1 to 5. Comment must be one of the values: ['bad-audio', 'call-dropped', 'wrong-callerid', 'post-dial-delay', 'dtmf-not-captured', 'audio-latency', 'unsolicited-call', 'one-way-audio', 'no-audio', 'never-connected']. This feedback will be sent only if the "enableTracking" flag is set to true.
getCallUUID()Returns a String call UUID if a call is active, else returns null.
getLastCallUUID()Returns last call UUID. Useful if you want to send feedback for the last call.
webRTC()Returns true if WebRTC is supported and false if there is no WebRTC support.
versionVariable that returns the current version of the Plivo SDK.
isLoggedIn Variable that returns true if the user is logged in and false otherwise.
availableDevices(filter)Promise-based callback that returns available devices. The filter parameter is optional and takes a String value. Pass "input" to filter by Input audio devices, "output" to filter by Output audio devices, null to get all audio devices.
revealAudioDevices(arg)Promise-based callback that forces and asks for allowing permission before returning all available devices. The arg parameter is optional and takes a string. Pass "returnStream" as arg to return local stream as well in Promise success.

Objects in Audio Device API are:

ObjectMethods and ParametersDescription
set method sets the audioDevice ID as default Microphone device. The deviceID parameter is mandatory and takes a String value.
get method returns the Microphone device ID that’s set.
reset method removes any Microphone device ID that’s set.
set method sets the audioDevice ID as default Speaker device for DTMF and remote audio. The deviceID parameter is mandatory and takes a String value.
get method returns the Speaker device ID that’s set.
reset method removes any Speaker device ID that’s set.
media takes "dtmf" or "ringback" as source parameter and returns the corresponding HTML audio element. This parameter is mandatory.
set method sets the audioDevice ID as default Ringtone device for DTMF and remote audio. The deviceID parameter is mandatory and takes a String value.
get method returns the Ringtone device ID that’s set.
reset method removes any Ringtone device ID that’s set.
media method returns Ringtone HTML audio element.


plivoBrowserSdk object may receive these events:

onLoginOccurs when a login is successful
onLoginFailed(cause)Occurs when a login has failed. cause returns the login failure reason
onLogoutOccurs when a logout is successful
onCallingOccurs when a call is initiated
onCallRemoteRingingOccurs when the remote end starts ringing during an outbound call
onCallAnsweredOccurs when an outbound or inbound call is answered
onCallTerminatedOccurs when an outbound or inbound call has ended
onIncomingCall(callerID, extraHeaders)Occurs when there is an incoming call. callerID provides the caller ID and extraHeaders return the X-Headers from Plivo
onIncomingCallCanceledOccurs when an incoming call is cancelled by the caller
onCallFailed(cause)Occurs when an outbound or inbound call fails. cause returns the reason for call failing
onMediaPermission(event)Occurs when media permission has been granted. event returns the stream access status. The success event returns {'status':'success','stream':true}. On failure the event returns {'status':'failure','error':errorName}
onWebrtcNotSupportedOccurs when browser does not support WebRTC
mediaMetricsWorks only for Chrome. Raises the following events:
high_jitter: when the jitter is higher than 30 ms for three out of last five samples.
high_rtt: When the RTT is higher than 400 ms for three out of last five samples.
high_packetloss: When the packet loss is > 10% for Opus and loss > 20% PCMU.
low_mos: When sampled mos is < 3 for three out of last five samples. no_microphone_access When we detect one-way audio (<80 bytes sent in 3 seconds).
no_audio_received : When the user is not able to hear the call recipient or when audio level is stable for last three samples.
ice_timeout : Alert if ICE gathering takes more than 2 seconds either for outgoing call invite or incoming call answer.
All the above will have `level`:`warning`, its `group` : `network/audio`, related params will have their own `value` and state `active`:`true/false`.
Example: {active : true, desc : "local_audio", group : "audio", level : "warning", type : "no_audio_received", value : 0}
onAudioDeviceChange(deviceObj)Occurs when there is a change in USB audio device: device added or removed. This event emits an object with two properties, "change" and "device." "change" may have values "added" or "removed". "device" provides device-specific properties
onConnectionChangeGenerated when the state of Plivo’s WebSocket connection changes — for example, when the WebSocket is disconnected due to internet issues.

On WebSocket disconnect {
'state': 'disconnected',
'eventCode': <code>,
'eventReason': <reason>

On WebSocket reconnect {
'state': 'connected'

Common WebSocket event codes (RFC 6455)
1006: indicates that the connection was closed abnormally, e.g., without sending or
receiving a Close control frame. For example, internet disconnection.
1009: indicates that an endpoint is terminating the connection
because it has received a message that is too big for it to
1011: indicates that a server is terminating the connection because
it encountered an unexpected condition that prevented it from
fulfilling the request.