Make it so that if a call is parked to an occupied parking lot it is returned to sender.

This commit is contained in:
Mark Crane 2013-09-16 21:35:37 +00:00
parent 60f5e5ff1e
commit 18cd29749d
1 changed files with 37 additions and 27 deletions

View File

@ -194,40 +194,50 @@
event:addHeader("answer-state", "confirmed"); event:addHeader("answer-state", "confirmed");
event:fire(); event:fire();
--start the fifo monitor on its own so that it doesn't block the script execution
api = freeswitch.API();
cmd = "luarun park_monitor.lua "..uuid.." "..domain_name.." "..park_extension.." "..park_timeout_type.." "..park_timeout_seconds.." "..park_timeout_destination;
result = api:executeString(cmd);
else else
--bridge the current call to the call that is parked context = session:getVariable("context");
--set the presence to terminated caller_id_number = session:getVariable("caller_id_number");
event = freeswitch.Event("PRESENCE_IN"); dialed_extension = session:getVariable("dialed_extension");
event:addHeader("proto", "sip"); dialed_user = session:getVariable("dialed_user");
event:addHeader("event_type", "presence"); cmd = "user_exists id ".. caller_id_number .." "..domain_name;
event:addHeader("alt_event_type", "dialog"); if (api:executeString(cmd) == "true") then
event:addHeader("Presence-Call-Direction", "outbound"); --bridge the current call to the call that is parked
--event:addHeader("state", "Active (1 waiting)"); --set the presence to terminated
event:addHeader("from", park_extension.."@"..domain_name); event = freeswitch.Event("PRESENCE_IN");
event:addHeader("login", park_extension.."@"..domain_name); event:addHeader("proto", "sip");
event:addHeader("unique-id", uuid); event:addHeader("event_type", "presence");
event:addHeader("answer-state", "terminated"); event:addHeader("alt_event_type", "dialog");
event:fire(); event:addHeader("Presence-Call-Direction", "outbound");
--event:addHeader("state", "Active (1 waiting)");
event:addHeader("from", park_extension.."@"..domain_name);
event:addHeader("login", park_extension.."@"..domain_name);
event:addHeader("unique-id", uuid);
event:addHeader("answer-state", "terminated");
event:fire();
--delete the lot from the database --delete the lot from the database
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' "); dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
--freeswitch.consoleLog("NOTICE", "Park 200- Affected rows: " .. dbh:affected_rows() .. "\n"); --freeswitch.consoleLog("NOTICE", "Park 200- Affected rows: " .. dbh:affected_rows() .. "\n");
--set the park status --set the park status
cmd = "uuid_setvar "..lot_uuid.." park_status unparked"; cmd = "uuid_setvar "..lot_uuid.." park_status unparked";
result = trim(api:executeString(cmd)); result = trim(api:executeString(cmd));
freeswitch.consoleLog("NOTICE", "Park Status: unparked "..park_extension.."\n"); freeswitch.consoleLog("NOTICE", "Park Status: unparked "..park_extension.."\n");
--connect the calls --connect the calls
cmd = "uuid_bridge "..uuid.." "..lot_uuid; cmd = "uuid_bridge "..uuid.." "..lot_uuid;
result = trim(api:executeString(cmd)); result = trim(api:executeString(cmd));
else
--transfer the call back to the callee
session:execute("transfer", dialed_user .." XML "..context);
end
end end
--continue running when the session ends --continue running when the session ends
session:setAutoHangup(false); session:setAutoHangup(false);
--start the fifo monitor on its own so that it doesn't block the script execution
api = freeswitch.API();
cmd = "luarun park_monitor.lua "..uuid.." "..domain_name.." "..park_extension.." "..park_timeout_type.." "..park_timeout_seconds.." "..park_timeout_destination;
result = api:executeString(cmd);
end end