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 - npm Package Compare versions

Comparing version 2.1.0-beta.2 to 2.1.0-beta.3

README-INTERNAL.md

6

package.json
{
"name": "plivo-browser-sdk",
"title": "plivo-browser-sdk",
"version": "2.1.0-beta.2",
"description": "Plivo WebRTC sdk for use in chrome/firefox ",
"version": "2.1.0-beta.3",
"description": "This library allows you to connect with plivo's voice enviroment from browser",
"main": "./dist/plivo.js",

@@ -22,3 +22,3 @@ "scripts": {

},
"author": "",
"author": "Plivo",
"license": "Apache-2.0",

@@ -25,0 +25,0 @@ "bugs": {

@@ -1,235 +0,26 @@

# 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](https://github.com/webpack/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](https://github.com/plivo/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](https://docs.google.com/document/d/10D4hIgwRlxhPMn3xZzZVPEyeszGLw2DF1b1z0g3ymEs/edit?ts=5b616182&pli=1)
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](https://github.com/plivo/plivo-websdk-2.0-example)
Getting Started
===============
Including the javascript
------------------------
* [Documentation](https://s3.amazonaws.com/plivowebrtc/v2-0.html)
* [Example](https://github.com/plivo/plivo-websdk-2.0-example)
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:
```html
<script type="text/javascript" src="http://localhost:9000/plivowebsdk.js"></script>
```
To use the production build:
```html
<script type="text/javascript" src="https://cdn.plivo.com/sdk/browser/v2/plivo.min.js"></script>
```
Initialising the Plivo JS Object
NPM Installation
--------------------------------
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
------------------
```npm install plivo-browser-sdk --save```
Pass function references to the events produced from the sdk. This is where your UI manipulation should handle all the different call flows.
#### Usage:
```js
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);
```
```const Plivo = require('plivo-browser-sdk');```
Registering using your Plivo Endpoint
-------------------------------------
or
Register using your Plivo Endpoints credentials
```import Plivo from 'plivo-browser-sdk'```
```js
var username = “johndoe1234@phone.plivo.com”;
var password = “XXXXXXXX”;
plivoWebSdk.client.login(username, password);
CDN
------------------
```html
<script type="text/javascript" src="https://cdn.plivo.com/sdk/browser/v2/plivo.min.js"></script>
```
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.
```js
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`.
```js
plivoWebSdk.client.answer();
```
Sending DTMF
------------
This is how DTMF is sent during a call.
```js
plivoWebSdk.client.sendDtmf('1');
```
Configuration
=============
All of these options are optional, if not present their default value will be used.
| **Option** | **default** | **Description** |
|---------------------|-------------|--------------------------------------------------------------------------------------------------------|
| `debug` | `DEBUG` | Set logging level for sdk, valid values: OFF, ERROR, WARN, INFO, DEBUG, ALL |
| `permOnClick` | `false` | Set to true if you want to ask for mic permission before call. Otherwise it will be asked on page load |
| `enableIPV6` | `false` | Enables 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.|
|`enableTracking` | `false` | set `true` to collect call stats
| `appId` | `null` | if `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.|
| `dscp` | `false` | Buy setting it to `true` you can enable QoS in voice traffic. Differentiated Services field in the packet headers for all WebRTC traffic.
| `registrationDomainSocket` | `null` | if you want to register with specific Plivo websocket server.
| `preDetectOwa` | `false` | set 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`
| **Option** | **params** | **Description** |
|-------------|--------------------------|------------------------------------------|
| `login` | `username`, `password` | Registering a Plivo endpoint |
| `logout` | | Logging out from the registered endpoint |
| `call` | `number`, `extraHeaders` | Call a number or sip address. |getCallUUID
| `answer` | | Answer an incoming call |
| `hangup` | | Hangup an ongoing call |
| `reject` | | Reject and incoming call |
| `sendDtmf` | `digit` | Send the digits as dtmf |
| `mute` | | Mute the mic |
| `unmute` | | Unmute the mic |
| `setRingTone`|`url to audio file` | Set the ring tone that plays when calling, default tone is [here](https://s3.amazonaws.com/plivosdk/audio/us-ring.mp3) |
| `setRingToneBack`| `url to audio file` | Set the ring tone that plays when being called, default tone is [here](https://s3.amazonaws.com/plivosdk/audio/us-ring.mp3) |
|`setConnectTone`| true/false| Dial beep will play till we get 18X response from server. setting `false` will not play beep tone.|
| `setDtmfTone`| `digit`, `url to audio tone` | Set the tone played when sending dtmf. Default tone is located [here](https://s3.amazonaws.com/plivosdk/audio/dtmf-2.mp3), where you need to replace digit between `dtmf-[digit].mp3`. |
| `setDebug`| `INFO` | will 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|
| `getCallUUID` | | Returns call UUID if a call is active, else returns null|
| `getLastCallUUID`| | Returns last call UUID, Useful in the cases if you want to send feedback for last call
|`webRTC`| | Return `true` if webRTC is supported. `false` if there is no webrtc support
|`version`| | It is a variable that returns current version of Plivo SDK
#### Audio API
Methods allowed in audio API `plivoWebSdk.client.audio`
| Name | Param | Description
|---------------------|-------------|--------------------------------------------------------------------------------------------------------|
| `availableDevices` {Function}| `filter` {String} - Optional | Promise 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} - Optional |Promise 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 Manditory| `set` 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
======
| **Event** | **Description** |
|----------------------------------------------|----------------------------------------------------------------------------------|
| `onLogin` | Occurs when a login is successful |
| `onLoginFailed` | Occurs when a login has failed |
| `onLogout` | Occurs when a logout is successful |
| `onCalling` | Occurs when a call is initiated |
| `onCallRemoteRinging` | Occurs when the remote end starts ringing during an outbound call |
| `onCallAnswered` | Occurs when the an outbound call is answered |
| `onCallTerminated` | Occurs when the an outbound call has ended |
| `onIncomingCall` | Occurs when there is an incoming call |
| `onIncomingCallCanceled` | Occurs when an incoming call is cancelled by the caller |
| `onCallFailed(cause)` | Occurs when an outbound call fails |
| `onMediaPermission` | Occurs when media permission has been granted |
| `onWebrtcNotSupported` | Occurs when browser does not support web rtc |
| `audioDeviceChange(deviceObj)` | Occurs when there is a change in USB audio device, Device added or removed |
| `onConnectionChange` | Occurs when the connection state is changed such as websocket abruptly closes |
| `mediaMetrics`| `Works 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](http://www.linphone.org/)
+ 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](https://github.com/plivo/plivo-websdk-2.0/blob/master/CHANGELOG.md) for version changes
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