Advertisement
thirdprotocol

Untitled

Jan 9th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function callNumber() {
  2.  
  3.  
  4.  
  5.         let ext = '';
  6.  
  7. let user =
  8. {
  9.         soft:'Local/12345@from-internal',
  10.         mobile: 'PJSIP/NUMBERHERE@Yay',
  11.         mobileCalled: false,
  12.         softCalled: false,
  13.  
  14. } ;
  15.         if (!softCalled) {
  16.  
  17.             ext = user.soft;
  18.  
  19.             user.softCalled = true;
  20.  
  21.             console.log('calling Soft');
  22.  
  23.  
  24.         }
  25.         else {
  26.  
  27.             ext = user.mobile;
  28.             user.mobileCalled = true;
  29.  
  30.             console.log('calling Mobile');
  31.  
  32.         }
  33.         var dialed = client.Channel();
  34.  
  35.         dialed.on('StasisStart', function(event, dialed) {
  36.        
  37.           // do stuff here
  38.         });
  39.  
  40.         dialed.on('ChannelStateChange', function(event, dialed) {
  41.             stateChanged(event, dialed);
  42.  
  43.            
  44.         });
  45.         console.log(ext);
  46.  
  47.            
  48.  
  49.             dialed.originate(
  50.                 {endpoint: ext, app: 'leg', appArgs: 'dialed'},
  51.                 function(err, dialed) {
  52.                     if (err) {
  53.                         console.log('there is a dialed error');
  54.  
  55.                         throw err;
  56.                     }
  57.                 });
  58.     }
  59.  
  60.    function stateChanged(event,dialed) {
  61.  
  62.         console.log(util.format(
  63.             'Channel %s is now: %s', event.channel.name, event.channel.state));
  64.  
  65.  
  66.         if (event.channel.state == 'Ringing') {
  67.  
  68.             console.log('Ringing.....');
  69.  
  70.  
  71.            setTimeout(notAnswered,20000);
  72.        
  73.         }
  74.  
  75.         function notAnswered() {
  76.  
  77.             console.log('hanging up');
  78.  
  79.  
  80.             dialed.hangup(function(err) {
  81.  
  82.                 console.log('hanged up');
  83.  
  84.  
  85.                 if (err) { throw err; }
  86.             } );
  87.  
  88.             console.log('callthe next one');
  89.         }
  90.  
  91.  
  92.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement