Code Monkey home page Code Monkey logo

ringcentral-web-phone's Introduction

RingCentral WebPhone Library

The RingCentral WebPhone Library includes a JavaScript WebRTC library and a WebRTC phone demo app.

Prerequisites

You will need an active RingCentral account. Don't have an account? Get your Free RingCentral Developer Account Now!

Table of Contents

  1. Installation
  2. Usage
  3. Configuring your RingCentral app
  4. Include Library And HTML Elements
  5. Application
  6. Demo
  7. API
  8. Initiating The Call
  9. Accepting Incoming Call
  10. DTMF
  11. Hold Unhold
  12. Mute Unmute
  13. Park
  14. Flip
  15. Transfer
  16. Warm Transfer
  17. Forward
  18. Start/Stop Recording
  19. Barge/Whisper

Installation

npm install ringcentral-web-phone
// or
bower install ringcentral-web-phone

If you are not using Bower or NPM:

  1. Download SIP.JS: http://sipjs.com/download/sip-0.7.5.js
  2. Download WebPhone SDK: https://cdn.rawgit.com/ringcentral/ringcentral-web-phone/master/src/ringcentral-web-phone.js
  3. Download audio files:
    1. https://cdn.rawgit.com/ringcentral/ringcentral-web-phone/master/audio/incoming.ogg
    2. https://cdn.rawgit.com/ringcentral/ringcentral-web-phone/master/audio/outgoing.ogg

Usage

Configuring your RingCentral app

Ensure your app has the following properties set. If these are not set, the error specified will be returned.

App Property Value Error if not set
Permissions VoIP Calling Specific application permission required
Platform type Browser-based Client edition is not compatible with current Brand

Since WebRTC enables dialing out, you need to have a DIGITAL LINE attached to an extension to use this capability. You can configure this in Online Web Portal for Production and Sandbox accounts. More information on Digital Lines and their configuration is available in the following RingCentral Knowledge Base article topics:

  1. Digital Line Overview (KB 5862)
  2. Adding a Digital Line (KB 3136). A limited number of Digital Lines are free with each sandbox account which can be configured with the free RingCentral for Desktop softphone.
  3. Reassigning an Existing Digital Line (KB 3748)

These permissions be configured for your app in the RingCentral Developer Portal. Fill this Registration Form to get access to WebRTC permissions. Please contact [email protected] to request these permissions.

Include Library And HTML Elements

<video id="remoteVideo" hidden="hidden"></video>
<video id="localVideo" hidden="hidden" muted="muted"></video>

<script src=".../sip.js" type="text/javascript"></script>
<script src=".../ringcentral-web-phone.js" type="text/javascript"></script>

Application

For this example you will also need to have RingCentral JS SDK installed.

Configure the web-phone

var appKey = '...'; 
var appSecret = '...';
var appName = '...';
var appVersion = '...';
 
var sdk = new RingCentral.SDK({
    appKey: appKey,
    appSecret: appSecret,
    appName: appName,
    appVersion: appVersion,
    server: RingCentral.SDK.server.production // or .sandbox
});

var platform = sdk.platform();

platform
    .login({
        username: '...',
        password: '...'
    })
    .then(function(loginResponse) {
    
        return platform
            .post('/client-info/sip-provision', {
                sipInfo: [{transport: 'WSS'}]
            })
            .then(function(res) { // Doing nested then because we need loginResponse in a simple way
            
                return new RingCentral.WebPhone(res.json(), { // optional
                    appKey: appKey,
                    appName: appName,
                    appVersion: appVersion,
                    uuid: loginResponse.json().endpoint_id,
                    logLevel: 1, // error 0, warn 1, log: 2, debug: 3
                    audioHelper: {
                        enabled: true, // enables audio feedback when web phone is ringing or making a call
                        incoming: 'path-to-audio/incoming.ogg', // path to audio file for incoming call
                        outgoing: 'path-to-audio/outgoing.ogg' // path to aduotfile for outgoing call
                    }
                });
                
            });
        
    })
    .then(function(webPhone){
    
        // YOUR CODE HERE
    
    })
    .catch(function(e){
        console.error(e.stack);
    });

Demo

$ git clone https://github.com/ringcentral/ringcentral-web-phone.git
$ cd ringcentral-web-phone
$ npm start
  1. Open http://localhost:8080/demo/ in the browser (port may change if 8080 will be already used by other app)
  2. Add your RC credentials and click on Register
  3. For making outbound calls, enter phone number and click on Call
  4. For receiving incoming calls, Click on Accept button when window pops up (will be visible when there is an incoming call)

If there's any connection problems to Sandbox environment, you may need to switch to the Production environment.

WebRTC works with issues when served from file system directly to browser (e.g. file:// protocol), so you will need a local HTTP server (comes with this package).

Online demo is hosted at https://ringcentral-web-phone.herokuapp.com/demo.


API

Except for some RingCentral-specific features the API is 100% the same as SIP.JS: http://sipjs.com/api/0.7.0: most of the time you will be working with RC-flavored UserAgent and Session objects of SIP.JS.

We encourage you to take a look at Guides section, especially Make A Call and Receive A Call articles.

Constructor

var webPhone = new RingCentral.WebPhone(provisionData, options);
  • Provision Data — the JSON returned from /client-info/sip-provision API endpoint
  • Options — object with various configuration options that adjust WebPhone behavior
    • appKey — your application key
    • appName — your application short code name
    • appVersion — your application version
    • uuid — manually provide the unique identifier of WebPhone instance (should persist between page reloads)
    • logLevel — controls verboseness in browser console
      • 0 — Errors only (good for production)
      • 1 — Errors & warnings
      • 2 — Errors, warnings, logs
      • 3 — Everything including debug information (good for development)
    • audioHelper — audio feedback when web phone is ringing or making a call
      • enabled — turns feedback on and off
      • incoming — path to incoming.ogg, audio file for incoming call
      • outgoing — path to outgoing.ogg, audio file for outgoing call
    • onSession — this callback will be fired each time User Agent starts working with session (incoming or outgoing)

Initiating The Call

var session = webPhone.userAgent.invite('PHONE_NUMBER', {
    media: {
        render: {
            remote: document.getElementById('remoteVideo'),
            local: document.getElementById('localVideo')
        }
    },
    fromNumber: 'PHONE_NUMBER', // Optional, Company Number will be used as default
    homeCountryId: '1' // Optional, the value of
});

Accepting Incoming Call

webPhone.userAgent.on('invite', function(session){
    session.accept({
        media: {
            render: {
                remote: document.getElementById('remoteVideo'),
                local: document.getElementById('localVideo')
            }
        }
    }).then(...);
});

DTMF

Callee will be put on hold and the another person can join into the call by dialing the extension number announced within the call.

session.dtmf('DTMF_DIGITS').then(...);

Hold Unhold

Callee will be put on hold and the another person can join into the call by dialing the extension number announced within the call.

session.hold().then(...);
session.unhold().then(...);

Mute Unmute

Callee will be put on mute or unmute

session.mute();
session.unmute();

Park

Callee will be put on hold and the another person can join into the call by dialing the extension number announced within the call.

session.park().then(...);

Flip

Caller can filp calls to different devices logged in through the same credentials.

session.flip('TARGET_NUMBER').then(...);

Transfer

session.transfer('TARGET_NUMBER').then(...);

Warm Transfer

If an agent has an active call with a customer and needs to transfer this call to a supervisor, then agent puts existing call on hold, makes a call to a supervisor and when ready performs a warm transfer. Customer will be connected to supervisor and the call between customer and agent will be disconnected.

Warm transfer puts current line on hold (if not done yet) then takes an existing line from arguments and makes transfer.

session.hold().then(function(){
    
    return new Promise(function(resolve, reject){
            
        var newSession = webPhone.userAgent.invite('PHONE_NUMBER', {
            media: {}
        });
        
        // when ready call the following code, for example when user clicks "Complete Transfer" button
        document.getElementById('complete-transfer').addEventListener('click', function(){
            resolve(session.warmTransfer(newSession));
        });

    });
        
}).then(...).catch(...);

Forward

session.forward('TARGET_NUMBER').then(...);

Start/Stop Recording

session.startRecord().then(...);
session.stopRecord().then(...);

Barge/Whisper

Not yet implemented. Could be done by dialing *83. The account should be enabled for barge/whisper access through system admin.

ringcentral-web-phone's People

Contributors

anton-bulyenov avatar chenghaoc avatar creatovisguru avatar egreenmachine avatar grokify avatar kirill-konshin avatar vladyslav-korenkov avatar vyshakhbabji avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.