Giter Club home page Giter Club logo

plivo-browser-sdk2-examples's Introduction

Plivo Browser SDK v2.1 Example

This Plivo example shows how to use all the features in Plivo Browser SDK 2.1 using a simple webphone demo. This demo helps in making phone calls from web browser to both sip addresses and PSTN phone numbers without installing any plugins.

plivo-websdk-2.0-example


To use the live web phone demo

a. Sign up for a Plivo account here: https://console.plivo.com/accounts/register/

b. Create a Plivo Endpoint here: https://console.plivo.com/voice/endpoints/add/

c. Use this Plivo endpoint to login after deploying the application


Automatically Deploy to Heroku

  • Create a Plivo account
  • Create and verify a Heroku account if you don't have one then click the button below.

Deploy

Deploying the application on your local setup

git clone https://github.com/plivo/plivo-browser-sdk2-examples.git
npm install
npm start

Initialization

Include

<script type="text/javascript" src="https://cdn.plivo.com/sdk/browser/v2/plivo.min.js"></script>

in the <body> tag before you include other javascript files dependent on the SDK.

Lets create a customclient.js file and declare a variable var plivoBrowserSdk; This is where we initialise a new Plivo object by passing options as plivoBrowserSdk = new window.Plivo(options);. The application can set up listeners for events as shown in the initPhone function below.

var plivoBrowserSdk; 
function initPhone(username, password){
  var options = refreshSettings();
  plivoBrowserSdk = new window.Plivo(options);

  
  plivoBrowserSdk.client.on('onWebrtcNotSupported', onWebrtcNotSupported);
  plivoBrowserSdk.client.on('onLogin', onLogin);
  plivoBrowserSdk.client.on('onLogout', onLogout);
  plivoBrowserSdk.client.on('onLoginFailed', onLoginFailed);
  plivoBrowserSdk.client.on('onCallRemoteRinging', onCallRemoteRinging);
  plivoBrowserSdk.client.on('onIncomingCallCanceled', onIncomingCallCanceled);
  plivoBrowserSdk.client.on('onCallFailed', onCallFailed);
  plivoBrowserSdk.client.on('onCallAnswered', onCallAnswered);
  plivoBrowserSdk.client.on('onCallTerminated', onCallTerminated);
  plivoBrowserSdk.client.on('onCalling', onCalling);
  plivoBrowserSdk.client.on('onIncomingCall', onIncomingCall);
  plivoBrowserSdk.client.on('onMediaPermission', onMediaPermission);
  plivoBrowserSdk.client.on('mediaMetrics',mediaMetrics);
  plivoBrowserSdk.client.on('audioDeviceChange',audioDeviceChange);
  plivoBrowserSdk.client.on('onConnectionChange', onConnectionChange);
  plivoBrowserSdk.client.on('volume', volume);
  plivoBrowserSdk.client.setRingTone(true);
  plivoBrowserSdk.client.setRingToneBack(true);
  console.log('initPhone ready!')
}

In the demo, options can be set from UI in the CONFIG menu. Once the CONFIG is updated clicking on LOGIN will boot the phone again.

Document ready state

If you're directly calling login on page load, please make sure you do that only after HTML document ready.

  <script type="text/javascript">
    $(document).ready(function() {
      console.log("HTML ready!");
      resetSettings(); // Optional, reset your Plivo settings on page load
      initPhone(); // Optional, Initialise Plivo sdk instance on load
    }); 
  </script>

Login

plivo-websdk-2.0-example

function login(username, password) {
  if(username && password) {
    //start UI load spinner
    kickStartNow();     
    plivoBrowserSdk.client.login(username, password);
  } else {
    console.error('username/password missing!')
  }
}

$('#clickLogin').click(function(e){
  var userName = $('#loginUser').val();
  var password = $('#loginPwd').val();
  login(userName, password);
});

Options

Options allow to disable tracking, setting codec type, enabling and disabling AEC/AGC etc. The list of all the settings can be found in the documentation page. plivo-websdk-2.0-example

var defaultSettings = { "debug":"DEBUG", "permOnClick":true, "codecs":["OPUS","PCMU"], "enableIPV6":false, "audioConstraints":{"optional":[{"googAutoGainControl":false}, {"googEchoCancellation":false}]}, "enableTracking":true, "closeProtection":false, "maxAverageBitrate":48000}
function resetSettings(){
  document.getElementById('loglevelbtn').value = "INFO"
  document.getElementById('onpageload').checked = true
  document.getElementById('monitorquality').checked = true
  document.getElementById('dontcloseprotect').checked = true
  document.getElementById('allowdscp').checked = true
  document.getElementById('noincoming').checked = true
  document.getElementById('msregionbtn').value = "AUTO"
  document.getElementById('averagebitrate').value = 48000
  localStorage.setItem('plivosettings',JSON.stringify(defaultSettings));
}

function updateSettings(val){
  let loglevel = document.getElementById('loglevelbtn').value;
  val.debug = loglevel;
  changeVal(val, document.getElementById('onpageload').checked, 'permOnClick', true);
  changeVal(val, document.getElementById('monitorquality').checked, "enableTracking", false);
  changeVal(val, document.getElementById('dontcloseprotect').checked, "closeProtection", true);
  changeVal(val, document.getElementById('allowdscp').checked, "dscp", false);
  changeVal(val, document.getElementById('noincoming').checked, "allowMultipleIncomingCalls", true);
  let clientRegion = document.getElementById('msregionbtn').value;
  if(clientRegion!='AUTO') {
    val.clientRegion = clientRegion;
  }
  let averagebitrate = document.getElementById('averagebitrate').value;
  val.maxAverageBitrate = parseInt(averagebitrate);
  localStorage.setItem('plivosettings',JSON.stringify(val));
  console.log('plivosettings updated!')
}
// From UI triggers
$('#updateSettings').click(function(e){
  updateSettings(defaultSettings);
});

$('#resetSettings').click(function(e){
  resetSettings();
}); 

Registration

The following snippet shows how to handle registration related events in the application

function onReady(){
  $('#phonestatus').html('trying to login...');
  console.info('Ready');
}

function onLogin(){
  $('#phonestatus').html('online');
  console.info('Logged in');
  $('#makecall').attr('class', 'btn btn-success btn-block flatbtn');
  $('#loginContainer').hide();
  $('#callContainer').show();
}

function onLoginFailed(reason){
  console.info('onLoginFailed ',reason);
  customAlert('Login failure :',reason, 'warn');  
}

function onLogout(){
  console.info('onLogout');
  $('#loginContainer').show();
  $('#callContainer').hide();
}

Outgoing call

Given a number or SIP URI, this snippet shows how to make an outgoing call. The following snippet takes input from the dial pad UI.

$('#makecall').click(function(e){
  var to = $('#toNumber').val().replace(" ","");
  var callEnabled = $('#makecall').attr('class').match('disabled');
  if(!to || !plivoBrowserSdk || !!callEnabled){return};
  console.info('Click make call : ',to);
  plivoBrowserSdk.client.call(to);
  $('.phone').hide();
  $('.AfterAnswer').show();
  $('#boundType').html('Outgoing : '+to);
  $('#callDuration').html('00:00:00');
  $('.callinfo').show();
});

Outgoing call with dynamic caller ID

There are cases where you need to set different caller ID for each campaign or some different reasons, then you can start using extraHeaders in .call() method

$('#makecall').click(function(e){
  var to = $('#toNumber').val();
  // pass caller Id
  var extraHeaders={},
  customCallerId = localStorage.getItem('callerId'); // get the dynamic caller id
  if(customCallerId) {
    extraHeaders = {'X-PH-callerId': customCallerId};
  }
  console.info('Click make call : ',to);
  plivoBrowserSdk.client.call(to, extraHeaders);
});

Capture this extraHeader in application side and use callerId attribute to set the callerId in Dial Element

Handling Incoming calls

By creating the onIncomingCall listener, the plivoBrowserSdk object can handle incoming calls to the Plivo Endpoint.

function onIncomingCall(callerName, extraHeaders){
  console.info(callerName, extraHeaders);
  $('#boundType').html('Incomming :');
  $('#callNum').html(callerName);
  $('#callDuration').html('00:00:00');
  $('.callinfo').show();
  $('.callScreen').show();
  $('.inboundBeforeAnswer').show();
}
function onIncomingCallCanceled(){
  console.info('onIncomingCallCanceled');
  callOff();
}

The following snippet shows how to answer an incoming call

$('.answerIncoming').click(function(){
  console.info('Call accept clicked');
  plivoBrowserSdk.client.answer();
  $('.incomingCallDefault').hide();
  $('.callinfo').show();
});

The following snippet shows how to reject an incoming call

$('.rejectIncoming').click(function(){
  console.info('Call rejected');
  plivoBrowserSdk.client.reject();
  $('.incomingCallDefault').hide();
});

The following snippet shows how to ignore an incoming call

$('.ignoreIncoming').click(function(){
  console.info('Call ignored');
  plivoBrowserSdk.client.ignore();
  $('.incomingCallDefault').hide();
});

Terminating a call

This code may be used to terminate a call.

$('.hangup').click(function(){
  console.info('Hangup');
  if(plivoBrowserSdk.client.callSession) {
    plivoBrowserSdk.client.hangup();
  }else {
    callOff();
  }
}); 

Implementing MediaMetrics

This snippet shows how to handle network or media related events from the SDK. A simple dynamic UI to show notifications when some warning events get emitted from Plivo SDK

plivo-websdk-2.0-example

Please check Chrome or Firefox console to see the complete info of the event.

function mediaMetrics(obj){
  console.table([obj]); 
  $(".alertmsg").prepend(
  '<div class="metrics -'+obj.type+'">' +
  '<span style="margin-left:20px;">'+obj.level+' | </span>' +
  '<span style="margin-left:20px;">'+obj.group+' | </span>' +
  '<span style="margin-left:20px;">'+message+' - '+obj.desc+' : </span><span >'+obj.value+'</span>'+
  '<span aria-hidden="true" onclick="closeMetrics(this)" style="margin-left:25px;cursor:pointer;">X</span>' +
  '</div>'
  );
}

Audio Device API

The Audio Device API in this SDK allows developers to select input, output and ring devices for the calls. plivo-websdk-2.0-example

The following snippet uses this API to demonstrate how to handle device selection from the UI 

// Audio device selection
$('#micDev').change(function(){
  var selectDev = $('#micDev').val();
  plivoBrowserSdk.client.audio.microphoneDevices.set(selectDev);
  console.debug('Microphone device set to : ',selectDev);
});

$('#speakerDev').change(function(){
  var selectDev = $('#speakerDev').val();
  plivoBrowserSdk.client.audio.speakerDevices.set(selectDev);
  console.debug('Speaker device set to : ',selectDev);
});

$('#ringtoneDev').change(function(){
  var selectDev = $('#ringtoneDev').val();
  plivoBrowserSdk.client.audio.ringtoneDevices.set(selectDev);
  console.debug('Ringtone dev set to : ',selectDev);
});

The following snippet uses this API and demonstrates the use case of testing audio devices

// Ringtone device test
$('#ringtoneDevTest').click(function(){
  let ringtoneVal = document.getElementById('ringtoneDevTest').innerText;
  // Toggle Test
  if(ringtoneVal=='Test') {
    showOuputAudioLevel('ringoutput');
    $('#ringtoneDevTest').html('Stop');
  } else if(ringtoneVal=='Stop') {
    stopOutputAudioLevel('ringoutput');
    $('#ringtoneDevTest').html('Test');
  }
});

// Speaker device test
$('#speakerDevTest').click(function(){
  let speakerVal = document.getElementById('speakerDevTest').innerText;
  // Toggle Test
  if(speakerVal=='Test') {
    showOuputAudioLevel('speakeroutput');
    $('#speakerDevTest').html('Stop');
  } else if(speakerVal=='Stop') {
    stopOutputAudioLevel('speakeroutput');
    $('#speakerDevTest').html('Test');
  }
});

The following snippet uses this API to retrieve available devices and populate them in UI

function updateAudioDevices(){
  // Remove existing options if any
  document.querySelectorAll('#micDev option').forEach(e=>e.remove())
  document.querySelectorAll('#ringtoneDev option').forEach(e=>e.remove())
  plivoBrowserSdk.client.audio.availableDevices()
  .then(function(e){
  e.forEach(function(dev){
    if(dev.label && dev.kind == "audioinput")
    $('#micDev').append('<option value='+dev.deviceId+'>'+dev.label+'</option>')
    if(dev.label && dev.kind == "audiooutput"){
    $('#ringtoneDev').append('<option value='+dev.deviceId+'>'+dev.label+'</option>');
    $('#speakerDev').append('<option value='+dev.deviceId+'>'+dev.label+'</option>')  
    }
  });
  })
  .catch(function(error){
  console.error(error);
  })
}

//revealAudioDevices
$('#allowAudioDevices').click(function(){
  refreshAudioDevices();
});

function refreshAudioDevices() {
  _forEach.call(document.querySelectorAll('#popAudioDevices option'), e=>e.remove());
  plivoBrowserSdk.client.audio.revealAudioDevices()
  .then(function(e){
    updateAudioDevices();
    console.log('Media permission ',e)
  })
  .catch(function(error){
    console.error('media permission error :',error);
    $('#mediaAccessBlock').modal('show');
  })
}

Audio Device change

Show users about change in audio device, either added or removed. When a new device gets added they can select the device for either input or output audio.

plivo-websdk-2.0-example

function audioDeviceChange(e){
  console.log('audioDeviceChange',e);
  if(e.change){
    if(e.change == "added") {
      customAlert(e.change,e.device.kind +" - "+e.device.label,'info');   
    }else {
      customAlert(e.change,e.device.kind +" - "+e.device.label,'warn');
    }
  }else {
    customAlert('info','There is an audioDeviceChange but mediaPermission is not allowed yet');
  }
}

Sending Feedback

The following snippet shows how to collect feedback using the SDK. There is a predefined list of feedback comments that users can select for the score range from 1-3. In this application we are taking “good” and “perfect” as feedback for scores 4 and 5.

plivo-websdk-2.0-example

$('#sendFeedback').click(function(){
  var score = $('#stars li.selected').last().data('value');
  score = Number(score);
  var lastCallid = plivoBrowserSdk.client.getLastCallUUID();
  var issues=[];
  _forEach.call(document.querySelectorAll('[name="callqualitycheck"]'), e=>{
    if(e.checked) {
      issues.push(e.value);
    }
  });
  var note = sendFeedbackComment.value;
  var sendConsoleLogs = document.getElementById("sendConsoleLogs").checked;
  // submitCallQualityFeedback takes parameteres callUUId, starRating, issues, note, sendConsoleLogs
  plivoBrowserSdk.client.submitCallQualityFeedback(lastCallid, score, issues, note, sendConsoleLogs)
  .then((result) => {
    $('#feedbackStatus').html('Feedback sent');
    $('#ignoreFeedback').click();
    customAlert('Feedback sent','','info');
    $('.lowQualityRadios').hide();
  })
  .catch((error) => {
    $('#feedbackStatus').html(error);
    customAlert('Could not send feedback','','warn');
  });
});

Real-time volume indicator on UI

Display user real-time volume of mic and speaker. 'volume' event handler will be invoked 60 times per second. The handler receives inputVolume and outputVolume as percentages of maximum volume represented by a floating point number between 0.0 and 1.0, inclusive. This value represents a range of relative decibel values between -100dB and -30dB.

plivo-websdk-2.0-example

function volume(audioStats){
  inputVolume = audioStats.inputVolume;
  outputVolume =  audioStats.outputVolume;
  colorPids(Math.floor(inputVolume * 325), 'localaudio');
  colorPids(Math.floor(outputVolume * 325), 'remoteaudio');
}

plivo-browser-sdk2-examples's People

Contributors

abhishek-kumar-plivo avatar akshayatplivo avatar altanai avatar altanaib avatar anand-plivo avatar bevenky avatar dependabot[bot] avatar dhruvinplivo avatar eniyavan-muruganantham-plivo avatar huzaif-plivo avatar karthikdechiraju-plivo avatar nixonsam avatar pothinenikarthik-plivo avatar rdhek-plivo avatar sanyamjain-plivo avatar sasi-plivo avatar sivaplivo avatar vikash-plivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plivo-browser-sdk2-examples's Issues

fix npm audit - 8 vulnerabilities


npm audit

                       === npm audit security report ===

# Run  npm install --save-dev [email protected]  to resolve 5 vulnerabilities
SEMVER WARNING: Recommended action is a potentially breaking change
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-stream > glob > minimatch             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/118                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-stream > minimatch                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/118                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > glob >     │
│               │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/118                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > minimatch  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/118                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > lodash     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/577                             │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Denial-of-Service Memory Exhaustion                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ qs                                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >= 1.x                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp-express [dev]                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp-express > tiny-lr > qs                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/29                              │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Denial-of-Service Extended Event Loop Blocking               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ qs                                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >= 1.x                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp-express [dev]                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp-express > tiny-lr > qs                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/28                              │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ debug                                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >= 2.6.9 < 3.0.0 || >= 3.1.0                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp-express [dev]                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp-express > tiny-lr > debug                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/534                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 8 vulnerabilities (2 low, 6 high) in 1301 scanned packages
  5 vulnerabilities require semver-major dependency updates.
  3 vulnerabilities require manual review. See the full report for details.

Passing parameters to answer callback

How can I pass parameters to the answer URL of the application when making a call? I didn't find a way to use a custom answer URL during a call with, for example, a query string appended to the URL.

Or should I use SIP headers for this?

So far the only way I came up with is to store a Call ID <-> parameters pair on the backend when initiating a call and then extracting this info when the callback is called.

No sound during the call when receiving in browser

Hello Team,

We are using Plivo SDK to establish call between android app to browser between two sip endpoints.

Problem is that after receiving incoming call on browser, there is no sound during ongoing call.

Note:

When call comes to browser , I can listen incoming ringtone.

Please. help me to get this done.

Waiting for your feedback.

Outgoing call to number does not work

How can i make outbound call works to random numbers? It redirect to answer endpoint back when dial random number(it converts to sip endpoint when dial just numbers - not plivo number).
Please help me to resolve this asap.

onCallRemoteRinging is never called

I'm using an onCallRemoteRinging handler to get the CallUUID of the call to store some information about the call before the answer URL is requested by Plivo (to work around the inability to pass parameters to Answer URL, see #2).

For some reason it just stopped working. It used to be called somewhere between client.call() and answer URL but now it's not. I can still make outgoing calls from the browser.

This is really frustrating because I don't see any errors in the logs, so I can only guess what's wrong with my setup.

Call from custom number everytime

Calling is working fine. But i receive call always from the number that i defined in Endpoint CLID parameter in plivo dashboard.
But i want to change FROM field from client side.
How can i accomplish this?
Thanks.

Flutter Web?

Hi
Do you have a Flutter Web SDK ? (Dart bindings to your JS SDK)

Thanks

Receive incoming on browser

Hi,
I want to receive incoming call on browser. I already create plivo application and endpoint. Here is my answer_url code snippet. I am trying to make a call to purchase plivo phone number from my phone number as like customer. Its ringing on my phone number but onIncomingCall not fired up. How I call onIncomingCall function when anyone want to call my plivo number?

<?php
require 'vendor/autoload.php';
use Plivo\XML\Response;
$dst = $_REQUEST['ForwardTo'];
if(! $dst)
    $dst = $_REQUEST['To'];
$src = $_REQUEST['CLID'];
if(! $src)
    $src = $_REQUEST['From'] or "";
$cname = $_REQUEST['CallerName'] or "";
$hangup = $_REQUEST['HangupCause'];
$dial_music = $_REQUEST['DialMusic'];
$disable_call = $_REQUEST['DisableCall'];
    
$r = new Response();

if($dst) {
    $dial_params = array();
    if($src)
        $dial_params['callerId'] = $src;
    if($cname)
        $dial_params['callerName'] = $cname;
    if(substr($dst, 0,4) == "sip:")
        $is_sip_user = TRUE;
    else
        $is_sip_user = FALSE;
    if($is_sip_user and in_array($disable_call, array("all", "sip"))) {
        $r->addHangup(array("reason" => "busy"));
    } elseif (! $is_sip_user and in_array($disable_call, array("all", "number"))) {
        $r->addHangup(array("reason" => "busy"));
    } else {
        if($dial_music)  {
            $dial_params["dialMusic"] = $dial_music;
            $d = $r->addDial($dial_params);
        } else
            $d = $r->addDial($dial_params);
        if($is_sip_user)
            $d->addUser($dst);
        else
            $d->addNumber($dst);
    } 
 } else {
     $r->addHangup();
 }
header("Content-Type: text/xml");
echo($r->toXML());
?>

Thank you.

Changing audio source during/after a call

Hello,

I am programming a phone application using your sdk, utilizing different audio sources. I tried to work with version 1 sdk, but since it didn't allow me to change the audio source, I switched to version 2.

The example webpage you offered here works fine for changing the input source. However after I make a call, even if I change the input source, the changes aren't reflected in Chrome. I have to refresh the page, select the input source again, then make a call.

I added this code to reflect the changes in Chrome, but although it changes the settings for Chrome, the changes didn't reflect on plivo:

var selectDev = $('#micDev').val();
plivoWebSdk.client.audio.microphoneDevices.set(selectDev);
var mediaConstraints = {audio:{deviceId: selectDev ? {exact: selectDev} : true}, video:false};
navigator.mediaDevices.getUserMedia(mediaConstraints);

Is there a way to change microphone/speakers after having made a call, without refreshing the page? Thank you.

Best,
Cem

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.