Hi Monica,
Thanks for the reply & sorry for not posting all the code.
I've actually been using the sample scripts for help, but unfortunately as far as i understand, Windows can't use the external script routing method.
Example:
^NNN$=external/nodata/playrec.php
... so I've been attempting to use global scripts instead, but with inspiration from the sample scripts.
as you suggested i went back to the playrec.php script and extracted what I think is the relavent parts to get me going.
Pasted below is what was created:
// 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 ); // Added because we dont get the call.execute event without it
Yate::Install("chan.notify" );
$ourcallid = "";
$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":
if ( $ev && $ev->name == "call.route" )
{
if ( $ev->getValue("called") == '600' ) {
Yate::Debug( 'Route Called ' . $ev->getValue("called") );
$chl_id = NULL;
$ourcallid = "playtest/" . uniqid(rand(),1);
// Not sure about this, it's all I can do to get it to start.
//$ev->retval = "tone/noise";
$ev->retval = "dumb/";
$ev->handled = true;
$ev->Acknowledge();
$ev = false;
}
}
if ( $ev && $ev->name == "call.execute" )
{
Yate::Debug( 'Execute ' . $ev->params["id"] );
$chl_id = $ev->params["id"];
$ev->params["targetid"] = $ourcallid;
$ev->handled = true;
// we must ACK this message before dispatching a call.answered
$ev->Acknowledge();
// we already ACKed this message
$ev = false;
$m = new Yate("call.answered");
$m->params["id"] = $ourcallid;
$m->params["targetid"] = $chl_id;
$m->Dispatch();
$m = new Yate("chan.attach");
$m->params["source"] = "wave/play/C:/Program Files/Yate/share/sounds/test.wav";
$m->Dispatch();
// Resulted in the error
//<WARN> Wave source 'C:/Program Files/Yate/share/sounds/test.wav' attach request with no data channel!
}
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 . " time: " . microtime(true) ) : NULL );
}
}
Yate::Output("PHP: bye!");
However, this kept giving me an error:
<WARN> Wave source 'C:/Program Files/Yate/share/sounds/test.wav' attach request with no data channel!
So .... I did a bit of Googling and found a previous question that was almost the same query as mine.
http://permalink.gmane.org/gmane.comp.telephony.yate/6182Here, you suggested replacing chan.attach with a chan.masquerade and chan.attach, for example:
$m = new Yate("chan.masquerade");
$m->params["message"] = "chan.attach";
$m->params["source"] = "wave/play/C:/Program Files/Yate/share/sounds/test.wav";
$m->params["id"] = $peerid;
$m->params["notify"] = $chl_id;
( This was initially inserted in place of the chan.attach code above )
But sadly I couldn't get this to work as $peerid of the other channel wasn't available to catch yet. ie it's wasn't in 'call.execute'
So, what i came up with was the following: ( this replaces the $ev->type 'incoming' above )
Which works, but I'm not so happy with chan.connected being the best way to detect when a call is 'answered' and ready to play prompts etc etc !
Sorry, for the long post, but please could you help point me in the right direction ?
Thank you!
if ( $ev && $ev->name == "chan.connected" && $ev->params["module"] == 'sip' )
{
$peer_id = $ev->params["peerid"];
$m = new Yate("chan.masquerade");
$m->params["message"] = "chan.attach";
//$m = new Yate("chan.attach");
$m->params["source"] = "wave/play/C:/Program Files/Yate/share/sounds/test.wav";
$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;
$ourcallid = $ev->params["id"];
// Not sure about this, it's all I can do to get it to start.
$ev->retval = "tone/noise";
//$ev->retval = "dumb/";
$ev->handled = true;
$ev->Acknowledge();
$ev = false;
}
}
if ( $ev && $ev->name == "call.execute" )
{
Yate::Debug( 'Execute ' . $ev->params["id"] );
$m = new Yate("call.answered");
$m->params["id"] = $chl_id;
$m->params["targetid"] = $chl_id;
$m->Dispatch();
}