"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-4428/resources/prosody-plugins/mod_conference_duration_component.lua" (23 Sep 2020, 2140 Bytes) of package /linux/misc/jitsi-meet-4428.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 st = require "util.stanza";
    2 local socket = require "socket";
    3 local json = require "util.json";
    4 local ext_events = module:require "ext_events";
    5 local it = require "util.iterators";
    6 
    7 -- we use async to detect Prosody 0.10 and earlier
    8 local have_async = pcall(require, "util.async");
    9 if not have_async then
   10     module:log("warn", "conference duration will not work with Prosody version 0.10 or less.");
   11     return;
   12 end
   13 
   14 local muc_component_host = module:get_option_string("muc_component");
   15 if muc_component_host == nil then
   16     log("error", "No muc_component specified. No muc to operate on!");
   17     return;
   18 end
   19 
   20 log("info", "Starting conference duration timer for %s", muc_component_host);
   21 
   22 function occupant_joined(event)
   23     local room = event.room;
   24     local occupant = event.occupant;
   25 
   26     local participant_count = it.count(room:each_occupant());
   27 
   28     if participant_count > 1 then
   29 
   30         if room.created_timestamp == nil then
   31             room.created_timestamp = os.time() * 1000; -- Lua provides UTC time in seconds, so convert to milliseconds
   32         end
   33 
   34         local body_json = {};
   35         body_json.type = 'conference_duration';
   36         body_json.created_timestamp = room.created_timestamp;
   37 
   38         local stanza = st.message({
   39             from = module.host;
   40             to = occupant.jid;
   41         })
   42         :tag("json-message", {xmlns='http://jitsi.org/jitmeet'})
   43         :text(json.encode(body_json)):up();
   44 
   45         room:route_stanza(stanza);
   46     end
   47 end
   48 
   49 -- executed on every host added internally in prosody, including components
   50 function process_host(host)
   51     if host == muc_component_host then -- the conference muc component
   52         module:log("info", "Hook to muc events on %s", host);
   53 
   54        local muc_module = module:context(host)
   55        muc_module:hook("muc-occupant-joined", occupant_joined, -1);
   56     end
   57 end
   58 
   59 if prosody.hosts[muc_component_host] == nil then
   60     module:log("info", "No muc component found, will listen for it: %s", muc_component_host);
   61 
   62     -- when a host or component is added
   63     prosody.events.add_handler("host-activated", process_host);
   64 else
   65     process_host(muc_component_host);
   66 end