Altering release cause
From Yate Documentation
(Difference between revisions)
(→Example) |
(→Example) |
||
Line 12: | Line 12: | ||
The following [[Javascript]] is an example of altering the release cause. The script can be placed in the share/scripts directory and be configured in javascript.conf | The following [[Javascript]] is an example of altering the release cause. The script can be placed in the share/scripts directory and be configured in javascript.conf | ||
+ | |||
+ | In javascript.conf | ||
+ | |||
+ | [scripts] | ||
alter_cause=alter_release_cause.js | alter_cause=alter_release_cause.js | ||
Revision as of 14:15, 25 October 2013
Yate provides a default mapping from the call release cause of the call leg that initiated the release.
You may want to alter the release cause or to enforce specific mappings per protocol.
Concept
When a call leg is released a cause code is received over the protocol or is generated locally in case of an error.
The peer of the hung up call leg gets disconnected. At this stage it sends a chan.disconnected message that can be used to prevent the call release or to alter the propagated release cause.
Example
The following Javascript is an example of altering the release cause. The script can be placed in the share/scripts directory and be configured in javascript.conf
In javascript.conf
[scripts] alter_cause=alter_release_cause.js
Content of a very simple script:
function onDisconnected(msg) { if (msg.reason == "congestion") msg.reason = "busy"; return false; } Message.install(onDisconnected,"chan.disconnected",80);
A more complex script:
function onDisconnected(msg) { var newreason = false; switch (msg.id) { case /^sip\//: // Cause propagated to SIP switch (msg.lastpeerid) { case /^sip\//: // SIP to SIP switch (msg.reason) { case "noroute": newreason = "congestion"; break; case "rejected": newreason = "forbidden"; break; } break; } break; case /^h323\//: // Cause propagated to H.323 switch (msg.reason) { case "congestion": newreason = "busy"; break; } break; } if (newreason) { Engine.debug(Engine.DebugInfo,"Changing end reason '" + msg.reason + "' to '" + newreason + "'"); msg.reason = newreason; } return false; } Message.install(onDisconnected,"chan.disconnected",80);