I am very new to Yate and trying to create a php windows global script
since I believe that is the only type of script that will work on windows.
I have seen a former post that was trying to do the same thing:
http://forum.yate.ro/index.php?topic=401.msg1166#msg1166It is a basic script using dumb channel to answer call and play a sound.
The last post in that thread doesn't seem to be complete and working.
So I tried to add missing parts to get it working but still have problems.
I never seem to get past route and then execute messages.
(So I never get any chan.* message)
I think I am somehow missing getting back the dumb channel id
somewhere, but it is very confusing on where to get and add that.
I am sure with more reading through the documentation it will become clear.
But it seems the windows version differences are not always clear.
An example of how to do a global script for windows that performs like one
of the example channel scripts (voicemail, ivr, etc) would make things much clearer.
The code I have changed from the other post is below, but not working.
I put markings (***) next to comments where I changed the code.
Thank you for any info on what I may be missing or setting incorrectly.
And thanks to original poster jamie for the initial example code changes.
<?php
require_once("libyate.php");
//Start YATE
Yate::Init(true, "localhost", 5039, "");
$eventCtr = 0;
Yate::Debug(true);
Yate::Output(true);
Yate::Install("call.route", 80 );
Yate::Install("call.execute", 70 );
Yate::Install("chan.notify"); //*** any priority needed other than default?
//*** added this
$ourcallid = "example/" . uniqid(rand(),1);
$chl_id = "";
/* The main loop. We pick events and handle them */
for (;;) {
$ev=Yate::GetEvent();
// To help see all events
if ($ev && $ev->name!='engine.timer'
&& $ev->type!=='installed' && $ev->type!=='watched')
{
Yate::Debug(' E --------' . $ev->type . ' -> ' . $ev->name);
};
/* If Yate disconnected us then exit cleanly */
if ($ev === false)
break;
/* Empty events are normal in non-blocking operation.
This is an opportunity to do idle tasks and check timers */
if ($ev === true) {
Yate::Output("PHP event: empty");
continue;
}
// Handling Functions
/* If we reached here we should have a valid object */
switch ($ev->type) {
case "incoming":
Yate::Debug( '-EV-name ' . $ev->name );
//***Changed below to chan.notify, but do not get it or chan.connected
//if ( $ev && $ev->name == "chan.connected" && $ev->params["module"] == 'sip' )
if ( $ev && $ev->name == "chan.notify" )
{
Yate::Debug( 'CHAN CONNECTED ' . $ev->getValue("called") );
$peer_id = $ev->params["peerid"];
$m = new Yate("chan.masquerade");
$m->params["message"] = "chan.attach";
$m->params["source"] = "wave/play/./sounds/record.gsm"; //*** not sure of path, but never get this far
$m->params["id"] = $peer_id;
$m->params["notify"] = $ourcallid;
$m->Dispatch();
}
if ( $ev && $ev->name == "call.route" )
{
if ( $ev->getValue("called") == '600' )
{
Yate::Debug( 'Route Called ' . $ev->getValue("called") );
$chl_id = NULL;
//*** removed this as it will overwrite ourcallid?
//$ourcallid = $ev->params["id"];
// Not sure about this, it's all I can do to get it to start.
//$ev->retval = "tone/noise";
//*** changed from other post to the dumb channel
$ev->retval = "dumb/";
$ev->handled = true;
$ev->Acknowledge();
$ev = false;
}
}
if ( $ev && $ev->name == "call.execute" )
{
Yate::Debug( 'Execute ' . $ev->params["id"] );
//*** added this section for Acknowledge, missing from other post
$partycallid = $ev->GetValue("id");
$ev->params["targetid"] = $ourcallid;
$ev->handled = true; //*** or should be false?
$ev->Acknowledge();
$ev = false;
//*** end of added section
$m = new Yate("call.answered");
//$m->params["id"] = $chl_id;
//*** changed from above NULL id
$m->params["id"] = $ourcallid;
//$m->params["targetid"] = $chl_id;
//*** changed from above NULL id
$m->params["targetid"] = $partycallid;
$m->Dispatch();
}
if ($ev)
$ev->Acknowledge();
break;
case "answer":
Yate::Output("PHP Answered -: " . $ev->name . " time: " . microtime(true) );
break;
case "installed":
Yate::Output("PHP Installed: " . $ev->name . " time: " . microtime(true) );
break;
case "uninstalled":
Yate::Output("PHP Uninstalled: " . $ev->name . " time: " . microtime(true) );
break;
case "setlocal":
Yate::Output("PHP Parameter: ". $ev->name . "=" . $ev->retval . ($ev->handled ? " (OK)" : " (error)") . " time: " . microtime(true) );
break;
default:
( $ev->type != 'empty' ? Yate::Output("PHP Event: " . $ev->type . ", " . $ev->name . " time: " . microtime(true) ) : NULL );
}
}
Yate::Output("PHP: bye!");
?>