englercj / node-esl

FreeSWITCH ESL implementation for Node.js; implements the full Event Socket Library specified in: http://wiki.freeswitch.org/wiki/Esl
http://englercj.github.com/node-esl/
MIT License
170 stars 111 forks source link

How to transfer calls inside Conn.Server using uuid of the calls? #79

Closed axchanda closed 5 years ago

axchanda commented 5 years ago

Hi,

I want to transfer a live call happening at a server api which is bridged to an endpoint over to an extension without terminating or hanging up the call. I had set the "hangup after bridge call to be false", and I execute this code:

var esl = require('modesl');

var esl_server = new esl.Server({port: 8085, myevents:true}, function(){
    console.log("esl server is up");
});

esl_server.on('connection::ready', function(conn, id) {
        conn.execute('answer');
        conn.execute('set',"hangup_after_bridge=false");
        conn.execute('bridge','name_of_the_bridge'); 
        // conn.api('uuid_transfer',uuid,'-bleg or both',description,dialplan, context
       conn.api('uuid_transfer',id,'-bleg',1000,'XML','default');
 }

I am trying to transfer the call from a bridge to an extension - incoming call with the user not getting disconnected.

Please answer my doubts asap! Thanks in advance. Immediate answers would be appreciated!

axchanda commented 5 years ago

@englercj Would request you to kindly look into it, please!

englercj commented 5 years ago

This sounds like a FreeSWITCH question. You'd probably have more luck on the mailing list than here. I haven't used FreeSWITCH in years.

axchanda commented 5 years ago

@englercj No, it is not FreeSWITCH problem. I am able to transfer calls through the dialplan. However, it fails only when I try to do it programmatically through the modesl code. Please refer and try to help me from your side! Thanks!

englercj commented 5 years ago

I can't know what you problem is intuitively, your best bet is to debug the node app and ensure it is sending the commands you expect. If you type the commands manually and they work, but they don't work programmatically then first confirm the program is sending the commands you think it is.

englercj commented 5 years ago

Your call to .api() doesn't look right, there are only 3 arguments to .api() and those are:

  1. The command string
  2. The array of arguments to send
  3. A callback

Maybe you are trying to do:

conn.api('uuid_transfer', [id,'-bleg',1000,'XML','default']);

?

axchanda commented 5 years ago

@englercj I am getting an error like new call dJEV49tAWuXaFMj2TGx8 -ERR No such channel!

Is the uuid same as the id created during esl.connection::ready the same?

If not, how to get the uuid of the created connection on the esl Server?

englercj commented 5 years ago

The id of the connection is a random unique id we generate. It has nothing to do with a call you make. The uuid_transfer command takes the uuid of the call to transfer.

I don't know how you get that uuid off the top of my head, read up on the commands you are issuing and see what they return. I bet one of them (answer maybe?) gives you the uuid of the call you can use to transfer.

shentianyu93 commented 5 years ago

why not use FreeSWITCH app transfer ? conn.execute('transfer','1000 XML default')

if you want to use 'uuid_transfer', you need get aleg uuid

axchanda commented 5 years ago

@shentianyu93 I need the uuid of the call to pass it into another stream from which I control the freeswitch call. So, please let me know how to get the UUID of a freeswitch call from dialplan?

shentianyu93 commented 5 years ago

@axchanda try this.

var esl = require('modesl');

var eslServer = new esl.Server({host: '192.168.1.3', port: 8084, myevents: true}, function () {
    console.info("esl server is start.");
});

eslServer.on('connection::ready', function (conn, id) {
    if(conn.channelData.type === 'CHANNEL_DATA'){
        console.log(conn.channelData.headers);
    }
});
[
  { name: 'Event-Name', value: 'CHANNEL_DATA' },
  { name: 'Core-UUID', value: '08a97102-b26b-46ba-aaeb-1c348c0681f2' },
  { name: 'FreeSWITCH-Hostname', value: '192.168.1.5' },
  { name: 'FreeSWITCH-Switchname', value: '192.168.1.5' },
  { name: 'FreeSWITCH-IPv4', value: '192.168.1.5' },
  { name: 'FreeSWITCH-IPv6', value: '::1' },
  { name: 'Event-Date-Local', value: '2019-07-27 09:41:29' },
  { name: 'Event-Date-GMT', value: 'Sat, 27 Jul 2019 01:41:29 GMT' },
  { name: 'Event-Date-Timestamp', value: '1564191689601255' },
  { name: 'Event-Calling-File', value: 'mod_event_socket.c' },
  { name: 'Event-Calling-Function', value: 'parse_command' },
  { name: 'Event-Calling-Line-Number', value: '2011' },
  { name: 'Event-Sequence', value: '1808' },
  { name: 'Channel-Direction', value: 'outbound' },
  { name: 'Channel-Logical-Direction', value: 'outbound' },
  { name: 'Channel-Dialplan', value: 'XML' },
  { name: 'Channel-Caller-ID-Name', value: 'Outbound Call' },
  { name: 'Channel-Caller-ID-Number', value: '1001' },
  { name: 'Channel-Orig-Caller-ID-Number', value: '0000000000' },
  { name: 'Channel-Callee-ID-Number', value: '0000000000' },
  { name: 'Channel-Network-Addr', value: '192.168.1.3' },
  { name: 'Channel-ANI', value: '0000000000' },
  { name: 'Channel-Destination-Number', value: '9999' },
  {
    name: 'Channel-Unique-ID',
    value: '627e4d38-1277-49db-ad9a-25c0b1f8499d'
  },
  { name: 'Channel-Source', value: 'src/switch_ivr_originate.c' },
  {
    name: 'Channel-Transfer-Source',
    value: '1564191689:26022422-fb51-43dc-a62a-c506927193f0:bl_xfer:9999/default/XML'
  },
  { name: 'Channel-Context', value: 'default' },
  { name: 'Channel-RDNIS', value: '1001' },
  {
    name: 'Channel-Channel-Name',
    value: 'sofia/internal/1001@192.168.1.3:65093'
  },
  { name: 'Channel-Profile-Index', value: '2' },
  { name: 'Channel-Profile-Created-Time', value: '1564191689601255' },
  { name: 'Channel-Channel-Created-Time', value: '1564191689301218' },
  { name: 'Channel-Channel-Answered-Time', value: '1564191689601255' },
  { name: 'Channel-Channel-Progress-Time', value: '0' },
  {
    name: 'Channel-Channel-Progress-Media-Time',
    value: '1564191689581333'
  },
  { name: 'Channel-Channel-Hangup-Time', value: '0' },
  { name: 'Channel-Channel-Transfer-Time', value: '0' },
  { name: 'Channel-Channel-Resurrect-Time', value: '0' },
  { name: 'Channel-Channel-Bridged-Time', value: '0' },
  { name: 'Channel-Channel-Last-Hold', value: '0' },
  { name: 'Channel-Channel-Hold-Accum', value: '0' },
  { name: 'Channel-Screen-Bit', value: 'true' },
  { name: 'Channel-Privacy-Hide-Name', value: 'false' },
  { name: 'Channel-Privacy-Hide-Number', value: 'false' },
  { name: 'Channel-State', value: 'CS_EXECUTE' },
  { name: 'Channel-Call-State', value: 'ACTIVE' },
  { name: 'Channel-State-Number', value: '4' },
  {
    name: 'Channel-Name',
    value: 'sofia/internal/1001@192.168.1.3:65093'
  },
  { name: 'Unique-ID', value: '627e4d38-1277-49db-ad9a-25c0b1f8499d' },
  { name: 'Call-Direction', value: 'outbound' },
  { name: 'Presence-Call-Direction', value: 'outbound' },
  { name: 'Channel-HIT-Dialplan', value: 'true' },
  { name: 'Channel-Presence-ID', value: '1001@192.168.1.5' },
  {
    name: 'Channel-Call-UUID',
    value: '627e4d38-1277-49db-ad9a-25c0b1f8499d'
  },
  { name: 'Answer-State', value: 'answered' },
  { name: 'Channel-Read-Codec-Name', value: 'PCMU' },
  { name: 'Channel-Read-Codec-Rate', value: '8000' },
  { name: 'Channel-Read-Codec-Bit-Rate', value: '64000' },
  { name: 'Channel-Write-Codec-Name', value: 'PCMU' },
  { name: 'Channel-Write-Codec-Rate', value: '8000' },
  { name: 'Channel-Write-Codec-Bit-Rate', value: '64000' },
  { name: 'Caller-Direction', value: 'outbound' },
  { name: 'Caller-Logical-Direction', value: 'outbound' },
  { name: 'Caller-Dialplan', value: 'XML' },
  { name: 'Caller-Caller-ID-Name', value: 'Outbound Call' },
  { name: 'Caller-Caller-ID-Number', value: '1001' },
  { name: 'Caller-Orig-Caller-ID-Number', value: '0000000000' },
  { name: 'Caller-Callee-ID-Number', value: '0000000000' },
  { name: 'Caller-Network-Addr', value: '192.168.1.3' },
  { name: 'Caller-ANI', value: '0000000000' },
  { name: 'Caller-Destination-Number', value: '9999' },
  {
    name: 'Caller-Unique-ID',
    value: '627e4d38-1277-49db-ad9a-25c0b1f8499d'
  },
  { name: 'Caller-Source', value: 'src/switch_ivr_originate.c' },
  {
    name: 'Caller-Transfer-Source',
    value: '1564191689:26022422-fb51-43dc-a62a-c506927193f0:bl_xfer:9999/default/XML'
  },
  { name: 'Caller-Context', value: 'default' },
  { name: 'Caller-RDNIS', value: '1001' },
  {
    name: 'Caller-Channel-Name',
    value: 'sofia/internal/1001@192.168.1.3:65093'
  },
  { name: 'Caller-Profile-Index', value: '2' },
  { name: 'Caller-Profile-Created-Time', value: '1564191689601255' },
  { name: 'Caller-Channel-Created-Time', value: '1564191689301218' },
  { name: 'Caller-Channel-Answered-Time', value: '1564191689601255' },
  { name: 'Caller-Channel-Progress-Time', value: '0' },
  {
    name: 'Caller-Channel-Progress-Media-Time',
    value: '1564191689581333'
  },
  { name: 'Caller-Channel-Hangup-Time', value: '0' },
  { name: 'Caller-Channel-Transfer-Time', value: '0' },
  { name: 'Caller-Channel-Resurrect-Time', value: '0' },
  { name: 'Caller-Channel-Bridged-Time', value: '0' },
  { name: 'Caller-Channel-Last-Hold', value: '0' },
  { name: 'Caller-Channel-Hold-Accum', value: '0' },
  { name: 'Caller-Screen-Bit', value: 'true' },
  { name: 'Caller-Privacy-Hide-Name', value: 'false' },
  { name: 'Caller-Privacy-Hide-Number', value: 'false' },
  { name: 'variable_direction', value: 'outbound' },
  { name: 'variable_is_outbound', value: 'true' },
  {
    name: 'variable_uuid',
    value: '627e4d38-1277-49db-ad9a-25c0b1f8499d'
  },
  { name: 'variable_session_id', value: '17' },
  { name: 'variable_sip_profile_name', value: 'internal' },
  { name: 'variable_text_media_flow', value: 'disabled' },
  {
    name: 'variable_channel_name',
    value: 'sofia/internal/1001@192.168.1.3:65093'
  },
  {
    name: 'variable_sip_destination_url',
    value: 'sip:1001@192.168.1.3:65093;ob'
  },
  ... 102 more items
]

the UUID of a freeswitch call ===== 'Unique-ID' this key's value

axchanda commented 5 years ago

@shentianyu93 Actually it was way too simpler. The dialplan variable ${uuid} can be passed into the headers of the request, and from there the call can be controlled using esl. But I now get codec issues :
Can't find matching codec in SDP. Any ideas for that?

shentianyu93 commented 5 years ago

@axchanda You need to learn more about FreeSWITCH. Codec+Negotiation

englercj commented 5 years ago

Closing this since these are FreeSWITCH questions and not specific to this library.