You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mod_conference_duration_component.lua 2.1KB

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