Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

plivo-browser-sdk

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plivo-browser-sdk

Plivo WebRTC sdk for use in chrome/firefox

  • 2.1.0-beta.2
  • npm
  • Socket score

Version published
Weekly downloads
964
increased by0.63%
Maintainers
1
Weekly downloads
 
Created
Source

PlivoWebSDK

A pure javascript webRTC-SIP library

Setup

npm install

Development Environment

npm start

This builds the SDK file and attaches it to the port 9000 - http://localhost:9000/plivowebsdk.js

This uses webpack-dev-server so, when there is a change in any file, the build file is auto build, When this is used in plivo-websdk-2.0-example, the app will auto reload with the build with latest changes

Build

npm run build

Minified, production-ready build is created at dist/plivowebsdk.min.js

npm run build:nominfy

A non-minified version of the build file is created dist/plivowebsdk.js

Contribution

Follow this Git branching Strategy

Use your Plivo's google account to view that document.

Deploy

To deploy to production (CDN77 and CloudFront), just push to master, the upload is handled by CircleCI.

Revert plan to revert a buggy deployment

  1. git checkout master

  2. git pull origin master

  3. git reset --hard <last-stable-tag> replace <last-stable-tag> with last stable release tag

  4. git push -f origin master this force pushes the tag to master and the CI will kick in and deploy the last stable release to production.

Run sample app

Refer example app

Getting Started

Including the javascript

Add the javascript file to the example app or to the application that you are build to use the SDK.

To use the development build:

<script type="text/javascript" src="http://localhost:9000/plivowebsdk.js"></script>

To use the production build:

<script type="text/javascript" src="https://cdn.plivo.com/sdk/browser/v2/plivo.min.js"></script>

Initialising the Plivo JS Object

You may specify a set of configuration parameters to initialise the object. The details are covered in the [configuration section]

var options = {"debug":"DEBUG","permOnClick":true,"codecs":["OPUS","PCMU"],"enableIPV6":false,"audioConstraints":{"optional":[{"googAutoGainControl":false}]},"enableTracking":false,"appId":null};
var plivoWebSdk = 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.

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

Registering using your Plivo Endpoint

Register using your Plivo Endpoints credentials

var username = “johndoe1234@phone.plivo.com”; 
var password = “XXXXXXXX”;

plivoWebSdk.client.login(username, password);

Making a call

Making a call is among the various methods exposed by the Plivo JS Object. The other methods are described under [Methods]. You can pass extra headers to be sent with the call, but is optional.

var dest = “<jane1234@phone.plivo.com>”;
var extraHeaders = {'X-PH-Test1': 'test1', 'X-PH-Test2': 'test2'};

plivoWebSdk.client.call(dest, extraHeaders);

Accepting a call

This is how an incoming call is answered, which is notified by the event onIncomingCall.

plivoWebSdk.client.answer();

Sending DTMF

This is how DTMF is sent during a call.

plivoWebSdk.client.sendDtmf('1');

Configuration

All of these options are optional, if not present their default value will be used.

OptiondefaultDescription
debugDEBUGSet logging level for sdk, valid values: OFF, ERROR, WARN, INFO, DEBUG, ALL
permOnClickfalseSet to true if you want to ask for mic permission before call. Otherwise it will be asked on page load
enableIPV6falseEnables or disables IPv6 candidate collection. *Experimental
codecs["OPUS","PCMU"]Valid array values include OPUS or PCMU. Setting one or the other will force that codec and remove the other. If no codecs is provided it will default to OPUS only
audioConstraints{}Audio constraints object that will be passed to webRTC getUserMedia(). This is a browsers specific audio controls.
enableTrackingfalseset true to collect call stats
appIdnullif enableTracking is true set a valid callstats.io application id. If you don't have an appId and still wanna track call stats, Just set enableTracking: true and we'll use our default account.
dscpfalseBuy setting it to true you can enable QoS in voice traffic. Differentiated Services field in the packet headers for all WebRTC traffic.
registrationDomainSocketnullif you want to register with specific Plivo websocket server.
preDetectOwafalseset it to true if you want to detect one way audio before answering/sending the call.

Methods

These are all the methods supported on the plivoWebSdk.client

OptionparamsDescription
loginusername, passwordRegistering a Plivo endpoint
logoutLogging out from the registered endpoint
callnumber, extraHeadersCall a number or sip address.
answerAnswer an incoming call
hangupHangup an ongoing call
rejectReject and incoming call
sendDtmfdigitSend the digits as dtmf
muteMute the mic
unmuteUnmute the mic
setRingToneurl to audio fileSet the ring tone that plays when calling, default tone is here
setRingToneBackurl to audio fileSet the ring tone that plays when being called, default tone is here
setConnectTonetrue/falseDial beep will play till we get 18X response from server. setting false will not play beep tone.
setDtmfTonedigit, url to audio toneSet the tone played when sending dtmf. Default tone is located here, where you need to replace digit between dtmf-[digit].mp3.
setDebugINFOwill look for any of [INFO, DEBUG, ERROR, WARN, ALL, OFF] Set the log level of the sdk, DEBUG and ALL will show all logs, OFF will turn off all plivo logs
sendQualityFeedback(callUUID,score, comment)score is between 1-5. For score 1-4, comment must be one of the following values ['bad-audio', 'call-dropped', 'wrong-callerid', 'post-dial-delay', 'dtmf-not-captured', 'audio-latency', 'unsolicited-call', 'one-way-audio', 'no-audio', 'never-connected'], only valid if call stats integration setup. If invalid score/comment returns error
getCallUUIDReturns call UUID if a call is active, else returns null
getLastCallUUIDReturns last call UUID, Useful in the cases if you want to send feedback for last call
webRTCReturn true if webRTC is supported. false if there is no webrtc support
versionIt is a variable that returns current version of Plivo SDK
Audio API

Methods allowed in audio API plivoWebSdk.client.audio

NameParamDescription
availableDevices {Function}filter {String} - OptionalPromise based callback! Pass 'input' as filter by Input audio devices,'output' as filter by Output audio devices, null to get all audio devices
revealAudioDevices {Function}arg {String} - OptionalPromise based callback! This will force and ask for allow permission, On permisson allowed it will list available devices. Pass 'returnStream' as arg to get local stream in Promise success
microphoneDevices {Object}set(deviceId) - deviceId {String} is Manditory, get(),reset()set method will set the audioDevice ID as default Microphone device. get method will return the Microphone device ID which is set already!, reset method will remove any Microphone device ID which is already set!
speakerDevices {Object}set(deviceId) - deviceId {String} is Manditory, get(),reset(),media(source)- source {String} is Manditoryset method will set the audioDevice ID as default Speaker device for DTMF and Callee's/Remote audio. get method will return the Speaker device ID which is set already!, reset method will remove any Speaker device ID which is already set! media will take 'dtmf' or 'ringback' as source name and will return a HTML audio element for the source name you passed
ringtoneDevices {Object}set(deviceId) - deviceId {String} is Manditory, get(),reset(),media()set method will set the audioDevice ID as default Ringtone device for incoming ringtone audio. get method will return the Ringtone device ID which is set already!, reset method will remove any Ringtone device ID which is already set! media method will return Ringtone HTML audio element.

Events

EventDescription
onLoginOccurs when a login is successful
onLoginFailedOccurs when a login has failed
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 the an outbound call is answered
onCallTerminatedOccurs when the an outbound call has ended
onIncomingCallOccurs when there is an incoming call
onIncomingCallCanceledOccurs when an incoming call is cancelled by the caller
onCallFailed(cause)Occurs when an outbound call fails
onMediaPermissionOccurs when media permission has been granted
onWebrtcNotSupportedOccurs when browser does not support web rtc
audioDeviceChange(deviceObj)Occurs when there is a change in USB audio device, Device added or removed
onConnectionChangeOccurs when the connection state is changed such as websocket abruptly closes
mediaMetricsWorks only for Chrome Occurs with below type high_jitter When the jitter is higher than 30 ms for 3 out of last 5 samples, high_latency When the RTT is higher than 400 ms for 3 out of last 5 samples, high_packetloss When the packet loss is > 10% for OPUS and loss > 20% PCMU, low_mos When sampled mos is < 3 for 3 out of last 5 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 callee or When audio level is stable for last 3 samples. All the above will have level:warning its group : network/audio related params will have its own value and state active:true/false , ice_timeout will get triggered when ICE gathering takes more than 2 sec either for outgoing call invite or incoming call answer. Example => {active : true, desc : "local_audio", group : "audio", level : "warning", type : "no_audio_received", value : 0}

Tests

These are just behavioural in nature which just tests if a call flows as it should. The SDK code is not unit testable as it has no modularity(all the functions are defined in the callbacks itself).

Pre requisites

  • firefox(from version 56) and chrome(from version 59) supporting headless execution
  • tmux
  • linphonec
  • sip endpoints credentials in test/spec.js

Run npm test in the root directory to start executing tests on firefox and chrome in headless mode

Refer Change log for version changes

FAQs

Package last updated on 28 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc