[ previous ] [ next ] [ threads ]
 To :  Michael Tremer <michael.tremer@i...>
 From :  Marian Podgoreanu <marian@v...>
 Subject :  Re: [yate] Initiating outgoing calls with Javascript
 Date :  Fri, 06 Mar 2015 10:19:06 +0200
Hi,

There is no need to route the call: the dumb channel will do it.

This will be a global script, not a routing one.
You need to:
- Install handlers for chan.disconnected and call.answered without filters
- Remember tracked channels' id in a global variable (you may store 
additional info also: like caller/called number)
- Remove tracked channels when handling chan.disconnected
- You may need to track chan.connected also (the second call will lead 
to dumb chan to be disconnected)
- Keep in mind: the chan.disconnected message is sent only by the 
channel beeing disconnected, it is not sent by both channels

About regexroute rule forbidding unauthorized calls:
I suppose it is set in route section so it won't affect the second call: 
this one is executed, not routed

CDR:
Yate creates an entry for each call leg.
Try to use the cdrcombine module if you want to put together a call.
See http://docs.yate.ro/wiki/CDRcombine_Module

Marian

On 28.02.2015 18:15, Michael Tremer wrote:
> Hey Marian,
>
> thanks for getting back. Here is what I made with your advice. The other
> functions are unchanged.
>
> function onCallInvite(msg) {
> 	var m, success;
>
> 	Engine.output("Initiating dialout " + msg.caller + " -> " + msg.called);
>
> 	m = new Message("call.route");
> 	m.auth = true;
> 	m.caller = msg.called;
> 	m.called = msg.caller;
>
> 	success = m.dispatch();
> 	if (!success) {
> 		Engine.output("Call was not successful: " + m.error);
> 		return false;
> 	}
>
> 	// The SIP/IAX2 id of the calling user
> 	var target = m.retValue();
>
> 	// Create a new dumb channel which calls the caller
> 	m = new Message("call.execute");
> 	m.callto = "dumb/";
> 	m.cdrtrack = false;
> 	m.direct = target;
> 	m.target = msg.caller;
>
> 	// Set the real caller and called party
> 	m.caller = msg.called;
> 	m.called = msg.called;
>
> 	success = m.dispatch();
>
> 	if (!success) {
> 		Engine.output("Error executing call to " + target + ": " + m.error);
> 		return false;
> 	}
>
> 	Engine.debug("Got a new channel:");
> 	Engine.debug("       ID: " + m.id);
> 	Engine.debug("  peer ID: " + m.peerid);
>
> 	Message.install(onCallerAnswered,   "call.answered",     1, "id", m.peerid);
> 	Message.install(onChanDisconnected, "chan.disconnected", 1, "id", m.peerid);
>
> 	return true;
> }
>
> function onCallerAnswered(msg) {
> 	Engine.debug("ON CALLER ANSWERED");
> 	Engine.print_r(msg);
>
> 	var m = new Message("chan.masquerade");
> 	m.message = "call.execute";
> 	m.id = msg.id;
> 	m.caller = "1000";
> 	m.callto = "sip/sip:9999@XXX";
> 	//m.target = "9999";
> 	m.dispatch();
>
> 	return true;
> }
>
> function onChanDisconnected(msg) {
> 	Engine.debug("ON HANGUP");
> 	Engine.print_r(msg);
>
> 	return false;
> }
>
> So I execute call.route for the calling party, get back the target,
> create the dumb channel and the phone is ringing. Great. I get the ID
> and peer ID on the console.
>
> As soon as I pick up the phone onCallerAnswered() is executed. I am not
> entirely sure if the Message.install() method is what you meant. It
> works although I have not tried what would happen if I executed a
> thousand calls this way. Would this be a problem? Should I call
> Message.uninstall() as first thing in onCallerAnswered() or
> onChanDisconnected()?
>
> What else must I take care of on chan.disconnected?
>
> If I execute the code above a call to extension "9999" is established. I
> guess I first would need to do the call.route thing once again to find
> out the "callto" bit. However, I don't have the "caller" and "called"
> set to the originally called parties at this point. What would be the
> most elegant way to pass them to this point in code?
>
> I also have some difficulties with executing the second call on behalf
> of the user that has been called first. In my regex dialplan I use a
> line that refuses unauthorized calls which I need to circumvent at this
> point. I also get different entries in the CDR log. Is there any chance
> that I can improve this situation? "caller" always equals the username
> of the user initiating the call.
>
> This is also my implementation of one party calling an other. I guess
> that there is no good way to put this and the conference invitation code
> in one file as it is a completely different approach and only shares
> very few lines of code.
>
> Thank you so much for your patient help.
>
> -Michael
>
> On Wed, 2015-02-25 at 09:58 +0200, Marian Podgoreanu wrote:
>> Hi,
>>
>> You may:
>> Call the target using dumbchan: send a call.execute with callto=dumb/
>> and direct=YOUR_TARGET
>>
>> Track the returned id's (remember them in some list):
>>      The call.execute message (on success) will contain:
>>      id=the id of the dumb channel
>>      peerid: The id of the outgoing channel
>>
>> Track the channels for chan.disconnected: this will indicate call hangup
>>
>> You may add a call to a conference using the call.conference message
>>
>> If you want to play a prompt you may attach a wave source using chan.attach
>>
>> Some documentation:
>> http://docs.yate.ro/wiki/Dumbchan
>> http://docs.yate.ro/wiki/Call.conference
>> http://docs.yate.ro/wiki/Chan.attach
>>
>> Marian
>>
>> On 22.02.2015 18:16, Michael Tremer wrote:
>>> Hello *,
>>>
>>> we have been using Yate for a long time in the IPFire project for
>>> internal communications. Developers can phone each other and so on. It
>>> is working really great.
>>>
>>> Now I would like to add a new feature for us. Yate should be able to
>>> initiate calls by itself to invite people to calls or conferences. This
>>> topic is touched very often on this list, but I could not find a really
>>> proper solution.
>>>
>>> Here is what I want to do: We have a web user interface where people can
>>> log on to and click on a "call" button next to a contact in the address
>>> book. Yate should then call the caller. As soon as he or she picks up
>>> the phone, a call to the called party should be executed. This is pretty
>>> standard.
>>>
>>> When someone invites somebody else to a conference this should work very
>>> similar: The invited party is called and a short message is played back
>>> saying something along the lines "You have been invited to a conference=