Send a message for each tone. Handle a pipe char as a 1 second delay. Watch chan.replaced messages also to handle tones.

git-svn-id: http://voip.null.ro/svn/yate@4448 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-06-09 10:19:09 +00:00
parent 6222a0032b
commit 04ea9ad141
1 changed files with 28 additions and 11 deletions

View File

@ -9,6 +9,7 @@
Parameters handled in call.answered: Parameters handled in call.answered:
postanm_dtmf: boolean: Handle the message. Defaults to false postanm_dtmf: boolean: Handle the message. Defaults to false
postanm_dtmf_text: string: Tones to send. The message will be ignored if text is empty postanm_dtmf_text: string: Tones to send. The message will be ignored if text is empty
Each pipe '|' character will be interpreted as 1 second delay
postanm_dtmf_outbound: boolean: Send DTMFs to called (true) or caller (false). Defaults to false postanm_dtmf_outbound: boolean: Send DTMFs to called (true) or caller (false). Defaults to false
postanm_dtmf_delay: integer: Interval to delay the tones in seconds. Defaults to 0 postanm_dtmf_delay: integer: Interval to delay the tones in seconds. Defaults to 0
*/ */
@ -55,20 +56,29 @@ function sendTones($id,$text)
global $param; global $param;
Yate::Debug($param . ": sendTones(" . $id ."," . $text . ")"); Yate::Debug($param . ": sendTones(" . $id ."," . $text . ")");
$m = new Yate("chan.masquerade"); while (strlen($text) > 0) {
$m->params["id"] = $id; $tone = substr($text,0,1);
$m->params["message"] = "chan.dtmf"; $text = substr($text,1);
$m->params["text"] = $text; if ($tone == "|") {
$m->Dispatch(); if (!empty($text))
setupCall($id,true,1,$text);
break;
}
$m = new Yate("chan.masquerade");
$m->params["id"] = $id;
$m->params["message"] = "chan.dtmf";
$m->params["text"] = $tone;
$m->Dispatch();
}
} }
// Handle call.answered // Handle call.answered
function callAnswered($ev,$text) function callAnswered($ev,$text,$idParam)
{ {
global $param; global $param;
global $defDelay; global $defDelay;
$evId = $ev->GetValue("id"); $evId = $ev->GetValue($idParam);
$evPeerId = $ev->GetValue("peerid"); $evPeerId = $ev->GetValue("peerid");
$outbound = getBoolValue($ev->getValue($param . "_outbound"),false); $outbound = getBoolValue($ev->getValue($param . "_outbound"),false);
$tmp = $ev->getValue($param . "_delay"); $tmp = $ev->getValue($param . "_delay");
@ -101,12 +111,15 @@ function checkCalls()
$calls[$key]--; $calls[$key]--;
if ($calls[$key] <= 0) { if ($calls[$key] <= 0) {
sendTones($key,$tones[$key]); sendTones($key,$tones[$key]);
setupCall($key,false); // sendTones() might change the counter
if ($calls[$key] <= 0)
setupCall($key,false);
} }
} }
} }
Yate::Watch("call.answered"); Yate::Watch("call.answered");
Yate::Watch("chan.replaced");
Yate::Install("chan.hangup"); Yate::Install("chan.hangup");
Yate::Install("engine.timer"); Yate::Install("engine.timer");
// Restart if terminated // Restart if terminated
@ -138,12 +151,16 @@ for (;;) {
$ev->Acknowledge(); $ev->Acknowledge();
break; break;
case "answer": case "answer":
if ($ev->name == "call.answered") { if ($ev->name == "call.answered" || $ev->name == "chan.replaced") {
$text = ""; $text = "";
if (getBoolValue($ev->getValue($param),false)) if (getBoolValue($ev->getValue($param),false))
$text = $ev->getValue($param . "_text"); $text = $ev->getValue($param . "_text");
if (!empty($text)) if (!empty($text)) {
callAnswered($ev,$text); $id = "id";
if ($ev->name == "chan.replaced")
$id = "newid";
callAnswered($ev,$text,$id);
}
} }
break; break;
case "watched": case "watched":