"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-5079/resources/prosody-plugins/mod_muc_call.lua" (17 Jun 2021, 4126 Bytes) of package /linux/misc/jitsi-meet-5079.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 local ext_events = module:require "ext_events"
    2 local jid = require "util.jid"
    3 local extract_subdomain = module:require "util".extract_subdomain;
    4 
    5 -- Options and configuration
    6 local poltergeist_component = module:get_option_string(
    7     "poltergeist_component",
    8     module.host
    9 );
   10 local muc_domain_base = module:get_option_string("muc_mapper_domain_base");
   11 if not muc_domain_base then
   12     module:log(
   13         "warn",
   14         "No 'muc_domain_base' option set, unable to send call events."
   15     );
   16     return
   17 end
   18 
   19 -- Status strings that trigger call events.
   20 local calling_status   = "calling"
   21 local busy_status      = "busy"
   22 local rejected_status  = "rejected"
   23 local connected_status = "connected"
   24 local expired_status   = "expired"
   25 
   26 -- url_from_room_jid will determine the url for a conference
   27 -- provided a room jid. It is required that muc domain mapping
   28 -- is enabled and configured. There are two url formats that are supported.
   29 -- The following urls are examples of the supported formats.
   30 --     https://meet.jit.si/jitsi/ProductiveMeeting
   31 --     https://meet.jit.si/MoreProductiveMeeting
   32 -- The urls are derived from portions of the room jid.
   33 local function url_from_room_jid(room_jid)
   34     local node, _, _ = jid.split(room_jid)
   35     if not node then return nil end
   36 
   37     local target_subdomain, target_node = extract_subdomain(node);
   38 
   39     if not(target_node or target_subdomain) then
   40         return "https://"..muc_domain_base.."/"..node
   41     else
   42         return "https://"..muc_domain_base.."/"..target_subdomain.."/"..target_node
   43     end
   44 end
   45 
   46 -- Listening for all muc presences stanza events. If a presence stanza is from
   47 -- a poltergeist then it will be further processed to determine if a call
   48 -- event should be triggered. Call events are triggered by status strings
   49 -- the status strings supported are:
   50 --    -------------------------
   51 --    Status      | Event Type
   52 --    _________________________
   53 --    "calling"   | INVITE
   54 --    "busy"      | CANCEL
   55 --    "rejected"  | CANCEL
   56 --    "connected" | CANCEL
   57 module:hook(
   58     "muc-broadcast-presence",
   59     function (event)
   60         -- Detect if the presence is for a poltergeist or not.
   61         if not (jid.bare(event.occupant.jid) == poltergeist_component) then
   62             return
   63         end
   64 
   65         -- A presence stanza is needed in order to trigger any calls.
   66         if not event.stanza then
   67             return
   68         end
   69 
   70         local call_id = event.stanza:get_child_text("call_id")
   71         if not call_id then
   72             module:log("info", "A call id was not provided in the status.")
   73             return
   74         end
   75 
   76         local invite = function()
   77             local url = assert(url_from_room_jid(event.stanza.attr.from))
   78             ext_events.invite(event.stanza, url, call_id)
   79         end
   80 
   81         local cancel = function()
   82             local url = assert(url_from_room_jid(event.stanza.attr.from))
   83             local status = event.stanza:get_child_text("status")
   84             ext_events.cancel(event.stanza, url, string.lower(status), call_id)
   85         end
   86 
   87         -- If for any reason call_cancel is set to true then a cancel
   88         -- is sent regardless of the rest of the presence info.
   89         local should_cancel = event.stanza:get_child_text("call_cancel")
   90         if should_cancel == "true" then
   91             cancel()
   92             return
   93         end
   94 
   95         local missed = function()
   96             cancel()
   97             ext_events.missed(event.stanza, call_id)
   98         end
   99 
  100         -- All other call flow actions will require a status.
  101         if event.stanza:get_child_text("status") == nil then
  102             return
  103         end
  104 
  105         local switch = function(status)
  106             case = {
  107                 [calling_status]   = function() invite() end,
  108                 [busy_status]      = function() cancel() end,
  109                 [rejected_status]  = function() missed() end,
  110                 [expired_status]   = function() missed() end,
  111                 [connected_status] = function() cancel() end
  112             }
  113             if case[status] then case[status]() end
  114         end
  115 
  116         switch(event.stanza:get_child_text("status"))
  117     end,
  118     -101
  119 );