Asterisk bridge dial javascript error

258 views Asked by At

Im trying examples from asterisk ari github.Right now im at brigde-dial example but there is a problem.When i try javascript code it gives following error:

usage: node bridge-dial.js endpoint

but python works fine and i can dial another pjsip endpoint.This one is javascript example:

Bridge-dial Javascript example on github

and this one is python:

Bridge-dial Python example on github

Could you please help me with issue ?

By the way, i have coded an javascript code to push pjsip to asterisk.Here it is:

var request = require('request');
var json = require('json');

var userName = '5000';



 authUrl = 'http://localhost:8088/ari/asterisk/config/dynamic/res_pjsip/auth/' +userName;

 aorUrl = 'http://localhost:8088/ari/asterisk/config/dynamic/res_pjsip/aor/' +userName;

 endpointUrl = 'http://localhost:8088/ari/asterisk/config/dynamic/res_pjsip/endpoint/' +userName;



 authconfig = {
    'fields': [
      { 'attribute': 'auth_type', 'value': 'userpass' },
      { 'attribute': 'username', 'value': userName },
      { 'attribute': 'password', 'value': 'asterisk' },
      { 'attribute': 'md5_cred', 'value': '' },
      { 'attribute': 'nonce_lifetime', 'value': '32' },


     ]
   };

 aorconfig = {
      'fields': [
         { 'attribute': 'support_path', 'value': 'yes' },
         { 'attribute': 'remove_existing', 'value': 'yes' },
         { 'attribute': 'max_contacts', 'value': '1' },
         { 'attribute': 'default_expiration', 'value': '3600' },
         { 'attribute': 'qualify_timeout', 'value': '3.000000' },
         { 'attribute': 'mailboxes', 'value': '' },
         { 'attribute': 'minimum_expiration', 'value': '60' },
         { 'attribute': 'outbound_proxy', 'value': '' },
         { 'attribute': 'maximum_expiration', 'value': '7200' },
         { 'attribute': 'qualify_frequency', 'value': '0' },
         { 'attribute': 'authenticate_qualify', 'value': 'no' },
         { 'attribute': 'contact', 'value': '' },

     ]
 };

 endpointconfig = {
     'fields': [
         { 'attribute': 'from_user', 'value': userName },
         { 'attribute': 'allow', 'value': '!all,g722,ulaw,alaw' },
         { 'attribute': 'ice_support', 'value': 'yes' },
         { 'attribute': 'force_rport', 'value': 'yes' },
         { 'attribute': 'rewrite_contact', 'value': 'yes' },
         { 'attribute': 'rtp_symmetric', 'value': 'yes' },
         { 'attribute': 'context', 'value': 'default' },
         { 'attribute': 'auth', 'value': userName },
         { 'attribute': 'aors', 'value': userName },
     ]
 };




 var respAuth = { 'auth': {'username':'asterisk', 'password':'asterisk'}, url: authUrl, json: authconfig}


 request.put(respAuth, function(err,res) {
 if(err) {
    console.log ('Received Error');
 }
 else {
       if(res.statusCode == 200) {
         console.log('Successfully Pushed');
         var result = JSON.stringify(res.body, null, 2);
         var finalResult = result.replace(/\\n/gi, '\n');
         console.log(finalResult);

        } else {
         console.log('Object Not Found');

 }
 }

 });

 var respAor = { 'auth': {'username':'asterisk', 'password':'asterisk'}, url: aorUrl, json: aorconfig}

 request.put(respAor, function(err,res) {
 if(err) {
    console.log ('Received Error');
 }
 else {
       if(res.statusCode == 200) {
         console.log('Successfully Pushed');
         var result = JSON.stringify(res.body, null, 2);
         var finalResult = result.replace(/\\n/gi, '\n');
         console.log(finalResult);

        } else {
         console.log('Object Not Found');
 }
 }

 });

 var respEndpoint = { 'auth': {'username':'asterisk',      'password':'asterisk'}, url: endpointUrl, json: endpointconfig}

 request.put(respEndpoint, function(err,res) {
 if(err) {
    console.log ('Received Error');
 }else {
       if(res.statusCode == 200) {
         console.log('Successfully Pushed');
         var result = JSON.stringify(res.body, null, 2);
         var finalResult = result.replace(/\\n/gi, '\n');
         console.log(finalResult);

        } else {
         console.log('Object Not Found');
 }
 }

 });
1

There are 1 answers

0
Çağdaş Öksüztepe On BEST ANSWER

if anybody stumbles upon same problem, i solved this problem by doing this:

I deleted;

if (!process.argv[2]) { console.error('usage: node bridge-dial.js endpoint'); process.exit(1); }

and changed the code below;

dialed.originate(
  {endpoint: process.argv[2], app: 'bridge-dial', appArgs: 'dialed'},

                             |
                             |
                             V


dialed.originate(
  {endpoint: channel.dialplan.exten, app: 'bridge-dial', appArgs: 'dialed'},