RingCentral Call aims to help developers to make and control call easily with RingCentral Web Phone and Call Control APIs. In this SDK, we use Web Phone for voice transmission, use Call Control API for call control.
- You will need an active RingCentral account to create RingCentral app. Don't have an account? Get your Free RingCentral Developer Account Now!
- A RingCentral app
- App type: Browser-Based or Server/Web
- Permissions: 'Call Control', 'Read Accounts', 'Read Presence', 'Webhook Subscriptions', 'VoIP Calling'
Use npm or yarn
$ yarn add @ringcentral/sdk @ringcentral/subscriptions ringcentral-call-control ringcentral-web-phone ringcentral-call
Use CDN scripts
<script type="text/javascript" src="https://unpkg.com/es6-promise@latest/dist/es6-promise.auto.js"></script>
<script type="text/javascript" src="https://unpkg.com/pubnub@latest/dist/web/pubnub.js"></script>
<script type="text/javascript" src="https://unpkg.com/whatwg-fetch@latest/dist/fetch.umd.js"></script>
<script type="text/javascript" src="https://unpkg.com/@ringcentral/sdk@latest/dist/ringcentral.js"></script>
<script type="text/javascript" src="https://unpkg.com/@ringcentral/subscriptions@latest/dist/ringcentral-subscriptions.js"></script>
<script type="text/javascript" src="https://unpkg.com/sip.js@0.13.5/dist/sip.js"></script>
<script type="text/javascript" src="https://unpkg.com/ringcentral-web-phone@0.7.7/dist/ringcentral-web-phone.js"></script>
<script type="text/javascript" src="https://unpkg.com/ringcentral-call@0.2.0/build/index.js"></script>
Online: Demo
Run in local:
$ git clone https://github.com/ringcentral/ringcentral-call-js.git
$ cd ringcentral-call-js
$ yarn
$ yarn build
$ yarn start
Open http://localhost:8080/demo/
, and login with RingCentral account to test.
For this example you will also need to have RingCentral JS SDK, RingCentral JS Subscriptions SDK, RingCentral Web Phone and RingCentral Call Control installed.
Create RingCentral Call instances:
var appClientId = '...';
var appClientSecret = '...';
var appName = '...';
var appVersion = '...';
var rcCall;
var sdk = new RingCentral.SDK({
clientId: appClientId,
clientSecret: appClientSecret,
appName: appName,
appVersion: appVersion,
server: RingCentral.SDK.server.production // or .sandbox
});
var subscriptions = new RingCentral.Subscriptions({ sdk });
var platform = sdk.platform();
platform
.login({
username: '...',
password: '...'
})
.then(function() {
return platform
.post('/restapi/v1.0/client-info/sip-provision', {
sipInfo: [{transport: 'WSS'}]
})
})
.then(function(res) {
return res.json();
})
.then(function(sipProvision) {
// create RingCentral web phone instance
var rcWebPhone = new RingCentral.WebPhone(sipProvision, {
appKey: appClientId,
appName: 'RingCentral Call Demo',
appVersion: '0.0.1'
});
// create RingCentral call instance
rcCall = new RingCentralCall({ webphone: rcWebPhone, sdk: sdk, subscriptions: subscriptions });
return rcCall;
})
Firstly, we need to create RingCentral JS SDK instance and RingCentral Web Phone instance. Then pass them when initialize RingCentral Call instance:
var rcCall = new RingCentralCall({ webphone: rcWebPhone, sdk: sdk });
var session = null;
rcCall.on('new', (newSession) => {
session = newSession;
});
rcCall.on('webphone-registered', function () {
// web phone feature is ready
});
rcCall.on('call-control-ready', function () {
// call control feature is ready
});
var sessions = rcCall.sessions;
rcCall.makeCall({
type: 'webphone',
toNumber: 'phone number',
fromNumber: 'from number',
}).then((session) => {
// ...
})
session.hangup().then(...)
session.hold().then(...)
session.unhold().then(...)
session.toVoicemail().then(...)
session.reject().then(...)
session.answer().then(...)
session.forward('forward number').then(...)
session.forward('transfer number').then(...)
session.mute().then(...)
session.unmute().then(...)
Status changed event
session.on('status', ({ party }) => {
// console.log(part)
});
- Call Switch
- Conference Call Support