Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

90 lines (69 sloc) 2.04 KB

Control Widget

The Widget provides some API that allow developer to control it out of widget. It is based on postMessage API.

Go to Dial and start a call

Find the widget iframe and use postMessage to send command and data:

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-new-call',
  phoneNumber: `phone number`,
  toCall: true,
}, '*');

This feature can be used for Click to Dial. If you set toCall to ture, it will start the call immediately.

Go to SMS Page

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-new-sms',
  phoneNumber: `phone number`,
}, '*');

Go to SMS Page with prefill text

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-new-sms',
  phoneNumber: `phone number`,
  text: `your text`,
}, '*');

Control the web call

Answer a ringing call

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-control-call',
  callAction: 'answer',
  callId: `call id`
}, '*');
// callId comes from web phone call event

// answer the current ringing call, call id default is current ringing call id.
document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-control-call',
  callAction: 'answer',
}, '*');

Reject a ringing call

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-control-call',
  callAction: 'reject',
  callId: `call id`
}, '*');

Hangup a call

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-control-call',
  callAction: 'hangup',
  callId: `call id`
}, '*');

// hangup current active call
document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-control-call',
  callAction: 'hangup',
}, '*');

Log out user

document.querySelector("#rc-widget").contentWindow.postMessage({
  type: 'rc-adapter-logout'
}, '*');
You can’t perform that action at this time.