Added script to provide ringback when not provided by the called party.

git-svn-id: http://yate.null.ro/svn/yate/trunk@3813 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-11-12 18:27:36 +00:00
parent 08bc5abb50
commit c4a036d5b1
1 changed files with 66 additions and 0 deletions

66
share/scripts/ringback.php Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/php -q
<?php
/* Ringback provider for the Yate PHP interface
Add in extmodule.conf
[scripts]
ringback.php=RINGBACK
where RINGBACK is a wave or autorepeat temporary tone resource like:
tone/*ring (this is the default)
wave/play/path/to/custom.au
*/
require_once("libyate.php");
// A fixed format is needed as we can't know what the called will offer
$mediafmt = "mulaw";
Yate::Init();
//Yate::Debug(true);
$ringback = Yate::Arg();
if ($ringback == "")
$ringback = "tone/*ring";
Yate::Install("call.ringing",50);
Yate::Watch("call.ringing");
Yate::SetLocal("restart",true);
for (;;) {
$ev=Yate::GetEvent();
if ($ev === false)
break;
if ($ev === true)
continue;
$id = $ev->GetValue("peerid");
if ($ev->type == "incoming") {
if ($ev->GetValue("earlymedia") == "false" &&
$ev->GetValue("rtp_forward") != "yes") {
Yate::Debug("Preparing fake $mediafmt ringback to $id");
$ev->SetParam("earlymedia",true);
$ev->SetParam("formats",$mediafmt);
$ev->SetParam("ringback",$ringback);
}
$ev->Acknowledge();
}
else if ($ev->type == "answer") {
if ($ev->handled) {
$ring = $ev->GetValue("ringback");
if ($id != "" && $ring != "") {
Yate::Debug("Faking ringback $ring to $id");
$m = new Yate("chan.masquerade");
$m->id = "";
$m->SetParam("message","chan.attach");
$m->SetParam("id",$id);
$m->SetParam("replace",$ring);
$m->SetParam("autorepeat",true);
$m->SetParam("single",true);
$m->Dispatch();
}
}
}
}
/* vi: set ts=8 sw=4 sts=4 noet: */
?>