[ previous ] [ next ] [ threads ]
 To :  Michael Tremer <michael.tremer@i...>, yate@v...
 From :  Marian Podgoreanu <marian@v...>
 Subject :  Re: [yate] Initiating outgoing calls with Javascript
 Date :  Wed, 25 Feb 2015 09:58:34 +0200
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.
> Please hold the line and you will be connected in a moment or hangup."
> When the invited party holds the line the call is connected to the
> conference after a second or two.
>
> I guess that this is not too complicated stuff but I have not had that
> much success. I thought that Javascript would be the best scripting
> language to use as it is well integrated in Yate. It just does not come
> with the possibility to execute external scripts which is used by the
> dialout-scheduler.php and dialout-dialer.php example.
>
> So my question is: Is Javascript suitable for this job? I would really
> like to use it so that I do not have one script in PHP, one in Perl, the
> next one in Javascript and so on.
>
> This is some of my code so far:
>
> function initiateCall(caller, called) {
> 	/* Just send a message to some other consumer that
> 	 * someone has been invited to a call. */
> 	var m = new Message("call.invite");
> 	m.caller = caller;
> 	m.called = called;
> 	m.dispatch();
>
> 	return true;
> }
>
> function onCallInvite(msg) {
> 	Engine.output("Initiating dialout " + msg.caller + " -> " + msg.called);
>
> 	Engine.debug("ON CALL INVITE");
> 	Engine.print_r(msg);
>
> 	return true;
> }
>
> function onEngineTimer(e) {
> 	var id;
> 	var caller;
> 	var called;
> 	var ret;
>
> 	var m = new Message("database");
> 	m.account = "postgresql-yate";
> 	m.query = "SELECT id, caller, called FROM dialout \
> 		WHERE (not_before IS NULL OR not_before <= NOW())";
>
> 	//Engine.debug("Running SQL query: " + m.query);
> 	if (m.dispatch()) {
> 		//Engine.debug("Got " + m.rows + " rows");
>
> 		for (var i = 0; i < m.rows; i++) {
> 			id     = m.getResult(i, 0);
> 			caller = m.getResult(i, 1);
> 			called = m.getResult(i, 2);
>
> 			ret = initiateCall(caller, called);
> 			if (ret) {
> 				var m = new Message("database");
> 				m.account = "postgresql-yate";
> 				m.query = "DELETE FROM dialout WHERE id = " + id.sqlEscape();
> 				m.dispatch();
> 			}
> 		}
> 	}
> }
>
> Engine.debugName("dialout-scheduler");
>
> // Poll the database every once in a while...
> Message.install(onEngineTimer, "engine.timer");
>
> // Handle call.invite messages
> Message.install(onCallInvite, "call.invite", 10);
>
>
> There will be an entry in the database which will start the whole
> process. A call.invite message is generated so that I can have other
> scripts send the same message and my script will handle them.
>
> So the critical part is the onCallInvite() bit. The PHP example has a
> data channel which (I think) is my biggest problem here. If I could use
> the Channel.callTo and Channel.callJust methods the rest would be much
> easier to implement. In contrast to dialout-{dialer,scheduler}.php I was
> trying to implement this all in one script. I tried using dumb channels
> and all sorts of things without much success.
>
> So I am reaching out to you and am looking forward to the advice you can
> give me to implement this properly.
>
> Thanks,
> -Michael
>