"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7561/resources/prosody-plugins/mod_muc_call.lua" (29 Sep 2023, 4243 Bytes) of package /linux/misc/jitsi-meet-7561.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     -- FIX ME: luacheck warning 581
   62     --   not (x == y)' can be replaced by 'x ~= y' (if neither side is a table or NaN)
   63         if not (jid.bare(event.occupant.jid) == poltergeist_component) then
   64             return
   65         end
   66 
   67         -- A presence stanza is needed in order to trigger any calls.
   68         if not event.stanza then
   69             return
   70         end
   71 
   72         local call_id = event.stanza:get_child_text("call_id")
   73         if not call_id then
   74             module:log("info", "A call id was not provided in the status.")
   75             return
   76         end
   77 
   78         local invite = function()
   79             local url = assert(url_from_room_jid(event.stanza.attr.from))
   80             ext_events.invite(event.stanza, url, call_id)
   81         end
   82 
   83         local cancel = function()
   84             local url = assert(url_from_room_jid(event.stanza.attr.from))
   85             local status = event.stanza:get_child_text("status")
   86             ext_events.cancel(event.stanza, url, string.lower(status), call_id)
   87         end
   88 
   89         -- If for any reason call_cancel is set to true then a cancel
   90         -- is sent regardless of the rest of the presence info.
   91         local should_cancel = event.stanza:get_child_text("call_cancel")
   92         if should_cancel == "true" then
   93             cancel()
   94             return
   95         end
   96 
   97         local missed = function()
   98             cancel()
   99             ext_events.missed(event.stanza, call_id)
  100         end
  101 
  102         -- All other call flow actions will require a status.
  103         if event.stanza:get_child_text("status") == nil then
  104             return
  105         end
  106 
  107         local switch = function(status)
  108             case = {
  109                 [calling_status]   = function() invite() end,
  110                 [busy_status]      = function() cancel() end,
  111                 [rejected_status]  = function() missed() end,
  112                 [expired_status]   = function() missed() end,
  113                 [connected_status] = function() cancel() end
  114             }
  115             if case[status] then case[status]() end
  116         end
  117 
  118         switch(event.stanza:get_child_text("status"))
  119     end,
  120     -101
  121 );