Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function callNumber() {
- let ext = '';
- let user =
- {
- soft:'Local/12345@from-internal',
- mobile: 'PJSIP/NUMBERHERE@Yay',
- mobileCalled: false,
- softCalled: false,
- } ;
- if (!softCalled) {
- ext = user.soft;
- user.softCalled = true;
- console.log('calling Soft');
- }
- else {
- ext = user.mobile;
- user.mobileCalled = true;
- console.log('calling Mobile');
- }
- var dialed = client.Channel();
- dialed.on('StasisStart', function(event, dialed) {
- // do stuff here
- });
- dialed.on('ChannelStateChange', function(event, dialed) {
- stateChanged(event, dialed);
- });
- console.log(ext);
- dialed.originate(
- {endpoint: ext, app: 'leg', appArgs: 'dialed'},
- function(err, dialed) {
- if (err) {
- console.log('there is a dialed error');
- throw err;
- }
- });
- }
- function stateChanged(event,dialed) {
- console.log(util.format(
- 'Channel %s is now: %s', event.channel.name, event.channel.state));
- if (event.channel.state == 'Ringing') {
- console.log('Ringing.....');
- setTimeout(notAnswered,20000);
- }
- function notAnswered() {
- console.log('hanging up');
- dialed.hangup(function(err) {
- console.log('hanged up');
- if (err) { throw err; }
- } );
- console.log('callthe next one');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement