2018-04-05 21:23:59 +00:00
|
|
|
local ext_events = module:require "ext_events"
|
|
|
|
local jid = require "util.jid"
|
|
|
|
|
|
|
|
-- Options and configuration
|
|
|
|
local poltergeist_component = module:get_option_string(
|
2018-06-15 19:28:05 +00:00
|
|
|
"poltergeist_component",
|
|
|
|
module.host
|
2018-04-05 21:23:59 +00:00
|
|
|
);
|
|
|
|
local muc_domain_base = module:get_option_string("muc_mapper_domain_base");
|
|
|
|
if not muc_domain_base then
|
2018-06-15 19:28:05 +00:00
|
|
|
module:log(
|
|
|
|
"warn",
|
|
|
|
"No 'muc_domain_base' option set, unable to send call events."
|
|
|
|
);
|
|
|
|
return
|
2018-04-05 21:23:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Status strings that trigger call events.
|
2018-05-22 17:54:47 +00:00
|
|
|
local calling_status = "calling"
|
|
|
|
local busy_status = "busy"
|
|
|
|
local rejected_status = "rejected"
|
2018-05-07 16:12:11 +00:00
|
|
|
local connected_status = "connected"
|
2018-07-11 20:49:11 +00:00
|
|
|
local expired_status = "expired"
|
2018-04-05 21:23:59 +00:00
|
|
|
|
|
|
|
-- url_from_room_jid will determine the url for a conference
|
|
|
|
-- provided a room jid. It is required that muc domain mapping
|
|
|
|
-- is enabled and configured. There are two url formats that are supported.
|
|
|
|
-- The following urls are examples of the supported formats.
|
|
|
|
-- https://meet.jit.si/jitsi/ProductiveMeeting
|
|
|
|
-- https://meet.jit.si/MoreProductiveMeeting
|
|
|
|
-- The urls are derived from portions of the room jid.
|
|
|
|
local function url_from_room_jid(room_jid)
|
2018-06-15 19:28:05 +00:00
|
|
|
local node, _, _ = jid.split(room_jid)
|
|
|
|
if not node then return nil end
|
2018-04-05 21:23:59 +00:00
|
|
|
|
2018-06-15 19:28:05 +00:00
|
|
|
local target_subdomain, target_node = node:match("^%[([^%]]+)%](.+)$")
|
2018-04-05 21:23:59 +00:00
|
|
|
|
2018-06-15 19:28:05 +00:00
|
|
|
if not(target_node or target_subdomain) then
|
|
|
|
return "https://"..muc_domain_base.."/"..node
|
|
|
|
else
|
2018-06-15 19:28:05 +00:00
|
|
|
return "https://"..muc_domain_base.."/"..target_subdomain.."/"..target_node
|
2018-06-15 19:28:05 +00:00
|
|
|
end
|
2018-04-05 21:23:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Listening for all muc presences stanza events. If a presence stanza is from
|
|
|
|
-- a poltergeist then it will be further processed to determine if a call
|
|
|
|
-- event should be triggered. Call events are triggered by status strings
|
|
|
|
-- the status strings supported are:
|
|
|
|
-- -------------------------
|
2018-05-07 16:12:11 +00:00
|
|
|
-- Status | Event Type
|
2018-04-05 21:23:59 +00:00
|
|
|
-- _________________________
|
2018-05-22 17:54:47 +00:00
|
|
|
-- "calling" | INVITE
|
|
|
|
-- "busy" | CANCEL
|
|
|
|
-- "rejected" | CANCEL
|
2018-05-07 16:12:11 +00:00
|
|
|
-- "connected" | CANCEL
|
2018-06-15 19:28:05 +00:00
|
|
|
module:hook(
|
|
|
|
"muc-broadcast-presence",
|
|
|
|
function (event)
|
|
|
|
-- Detect if the presence is for a poltergeist or not.
|
|
|
|
if not (jid.bare(event.occupant.jid) == poltergeist_component) then
|
|
|
|
return
|
|
|
|
end
|
2018-04-05 21:23:59 +00:00
|
|
|
|
2018-06-15 19:28:05 +00:00
|
|
|
-- A presence stanza is needed in order to trigger any calls.
|
|
|
|
if not event.stanza then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local call_id = event.stanza:get_child_text("call_id")
|
|
|
|
if not call_id then
|
|
|
|
module:log("info", "A call id was not provided in the status.")
|
|
|
|
return
|
|
|
|
end
|
2018-05-24 15:20:52 +00:00
|
|
|
|
2018-06-15 19:28:05 +00:00
|
|
|
local invite = function()
|
|
|
|
local url = assert(url_from_room_jid(event.stanza.attr.from))
|
|
|
|
ext_events.invite(event.stanza, url, call_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
local cancel = function()
|
|
|
|
local url = assert(url_from_room_jid(event.stanza.attr.from))
|
|
|
|
local status = event.stanza:get_child_text("status")
|
|
|
|
ext_events.cancel(event.stanza, url, string.lower(status), call_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If for any reason call_cancel is set to true then a cancel
|
|
|
|
-- is sent regardless of the rest of the presence info.
|
|
|
|
local should_cancel = event.stanza:get_child_text("call_cancel")
|
|
|
|
if should_cancel == "true" then
|
|
|
|
cancel()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-07-11 20:49:11 +00:00
|
|
|
local missed = function()
|
|
|
|
cancel()
|
|
|
|
ext_events.missed(event.stanza, call_id)
|
|
|
|
end
|
|
|
|
|
2018-06-15 19:28:05 +00:00
|
|
|
-- All other call flow actions will require a status.
|
|
|
|
if event.stanza:get_child_text("status") == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local switch = function(status)
|
|
|
|
case = {
|
|
|
|
[calling_status] = function() invite() end,
|
|
|
|
[busy_status] = function() cancel() end,
|
2018-07-11 20:49:11 +00:00
|
|
|
[rejected_status] = function() missed() end,
|
|
|
|
[expired_status] = function() missed() end,
|
2018-06-15 19:28:05 +00:00
|
|
|
[connected_status] = function() cancel() end
|
|
|
|
}
|
|
|
|
if case[status] then case[status]() end
|
|
|
|
end
|
|
|
|
|
|
|
|
switch(event.stanza:get_child_text("status"))
|
|
|
|
end,
|
|
|
|
-101
|
|
|
|
);
|