How to connect WebRTC to Zoom and call 2 times cheaper
The Zoom service took the videoconferencing industry by storm - simply because the guys were able to offer good video quality and “always work.” The competitors and the first and second somehow not stuck. Who has tried to make a video conference for five or more people in Skype or analog, will understand me. The authors of the service adequately estimate its popularity and “premium” opportunities offer expensive: the ability to connect participants with regular phones to conferences costs from $ 100 per month . But the SIP connection is twice cheaper. And under the cut, I want to show how to connect Voximplant to similar services so that in a few lines of JavaScript code we can receive low-cost calls all over the world and our voice automation.
Zoom setting
All Zoom needs to do is buy the integration with SIP, which is called the H.323 / SIP Room Connector and is bought from this link . We will need only one port, since all the “telephone magic” will be implemented using JavaScript on the Voximplant side.
Voximplant setup
The idea is to create a web interface that through the HTTP API will instruct the Voximplant cloud to connect to the desired Zoom conference. And then the cloud will be able to connect participants from phones to this conference: both by calling itself and by providing a number for the call. To make the decision even cheaper, we will use the numbers in the sandbox of Gotham City, which are almost like real ones, but work through additional numbers.
You can register as a Voximplant developer here , after which the manage.voximplant.com control panel is at your complete disposal, in which further configuration steps will be carried out.
Using the “applications” section of the top menu, create a new application and name it zoomconnector . Then, using the “scripts” section, create ZoomBridge and ZoomCall-In scripts with the following source code: ')
Some code under the spoiler
require(Modules.Conference);
var customData,
confName,
conference,
pstnCalls = [];
/**
* Handle StartConference request
*/
VoxEngine.addEventListener(AppEvents.Started, function (e) {
// We will send some parameters in customData
try {
customData =JSON.parse(VoxEngine.customData());
} catch (e) {
Logger.write("Something went wrong. Broken JSON. Life is pain. Please try again.");
}
/**
* Conference ID
*/
if (customData !==undefined&& confName ===undefined) confName =customData.conference;
/**
* Display Name
*/
if (customData !==undefined&&customData.displayName!==undefined) displayName =customData.displayName;
else displayName ="Untitled";
// Create conference
conference =VoxEngine.createConference();
if (confName !==undefined) callZoomConference(confName);
});
/**
* Handle Call-In
*/
VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
if (e.headers["X-conference"] !==undefined) {
// If we haven't set conference id yet (conference session started by inbound call instead of HTTP API call)
if (confName ===undefined) {
confName =e.headers["X-conference"];
callZoomConference(confName);
}
e.call.addEventListener(CallEvents.Connected, function (ev) {
VoxEngine.sendMediaBetween(ev.call, conference);
});
e.call.answer();
}
});
/**
* Make outbound SIP call to Zoom
*/
functioncallZoomConference(conf) {
var call =VoxEngine.callSIP("sip:"+ conf +"@zoomcrc.com", {
callerid:"voximplant",
displayName: displayName,
video:true
});
call.addEventListener(CallEvents.Connected, function (e) {
// When connected to Zoom - send media between our conference and Zoom
VoxEngine.sendMediaBetween(conference, call);
// Handle commands for PSTN Call-out
// To initiate call-out use the URL that looks as follows: media_session_access_url/CallOut/phonenumber
VoxEngine.addEventListener(AppEvents.HttpRequest, function (e) {
//Logger.write("HTTP REQUEST:");
//Logger.write(e.path);
var path =e.path.split("/"),
num;
if (path[path.length-2] =="CallOut") {
num = path[path.length-1];
handleCallOut(num);
return'{"result":"callingto:'+ num +'"}';
}
});
});
// If the connection with Zoom has been lost - destroy the conference
To allow conference participants to call Gotham, go to the “numbers” section, click on the “real” / “debug” switches and buy yourself a number in a nonexistent city for one cent. For this example we will use 699100266 in Gotham City. This is an extension number. To call it, you first need to call the single access number of the virtual numbers (listed in the “my numbers” section) and after the voice greeting, dial this number. Also in the section "my numbers" you need to link the number and application:
The last thing to do is specify which JavaScript scripts to run in which situations. To do this, go to the “applications” section, select the zoomconnector application and click on “rules”. Need to create two rules. The first will execute a ZoomCall-In script on an incoming call to a virtual number, and the second will execute a ZoomBridge script to organize a conference and interact with Zoom. Note that the order in which the scripts are specified is important. More specific (for one number) need to be placed higher than less specific (for all calls).
and some more screenshots under the spoiler
You can call!
Launch the Zoom application and open the Zoom Meeting:
The running Meeting has a Meeting ID, which is used when connecting. The demo JavaScript scripts copied above allow you to connect to the Zoom in two ways:
The user calls the access number in Gotham City, dials an extension and enters the ZoomCall-In script, which already synthesizes "enter the Meeting number". The user enters the number in the same way he entered the extension. After that, the script makes an internal call to the ZoomBridge conference script , which, when it is first received , connects to the Zoom and then begins to mix the voices of the participants “from the phone” and transfer all this to the Zoom and back. The same scenario is responsible for ensuring that the Voximplant cloud itself calls the specified number and adds a call to the conference. Thus, you can add up to 100 (!!!) participants from the phones to the conference.
Voximplant cloud can create a conference without an incoming call. To do this, you need to make an HTTP startconference request, passing as a parameter the Meeting number to the Zoom and application information. The resulting JavaScript session with the ZoomBridge script will establish a connection to the Zoom and will wait for incoming calls or commands for an outgoing call.
Add members by callback
Check out this code snippet in the ZoomBridge script:
// JS HTTP
VoxEngine.addEventListener(AppEvents.HttpRequest, function (e) {
After the Voximplant cloud has launched a JavaScript session on an incoming call or on a command from the HTTP API, you can interact with this session by making HTTP requests to a special access url (the session itself, by the way, can also communicate with the outside world, making HTTP- requests). In our example, we use this feature to instruct the JavaScript session of the conference to call the specified number and add it to the conversation with the Zoom Meeting:
functionhandleCallOut(num) {
var pstn =VoxEngine.callPSTN(num);
pstn.addEventListener(CallEvents.Connected, function (e) {
pstnCalls.push(e.call); //
VoxEngine.sendMediaBetween(pstn, conference); //
});
pstn.addEventListener(CallEvents.Disconnected, function (e) {
if (pstnCalls.indexOf(e.call) >-1) pstnCalls.splice(pstnCalls.indexOf(e.call), 1);
});
pstn.addEventListener(CallEvents.Failed, function (e) {
“Access URL” for communicating with the session we get either by running the session through the HTTP API (method number 2 above), or by subscribing to the event Started session and transferring it to ourselves with an HTTP call from the session to our backend. In our example, the command to start a callback will look something like this: