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_muc_call.lua 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local ext_events = module:require "ext_events"
  2. local jid = require "util.jid"
  3. -- Options and configuration
  4. local poltergeist_component = module:get_option_string(
  5. "poltergeist_component",
  6. module.host
  7. );
  8. local muc_domain_base = module:get_option_string("muc_mapper_domain_base");
  9. if not muc_domain_base then
  10. module:log(
  11. "warn",
  12. "No 'muc_domain_base' option set, unable to send call events."
  13. );
  14. return
  15. end
  16. -- Status strings that trigger call events.
  17. local invited_status = "Invited"
  18. -- url_from_room_jid will determine the url for a conference
  19. -- provided a room jid. It is required that muc domain mapping
  20. -- is enabled and configured. There are two url formats that are supported.
  21. -- The following urls are examples of the supported formats.
  22. -- https://meet.jit.si/jitsi/ProductiveMeeting
  23. -- https://meet.jit.si/MoreProductiveMeeting
  24. -- The urls are derived from portions of the room jid.
  25. local function url_from_room_jid(room_jid)
  26. local node, _, _ = jid.split(room_jid)
  27. if not node then return nil end
  28. local target_subdomain, target_node = node:match("^%[([^%]]+)%](.+)$")
  29. if not(target_node or target_subdomain) then
  30. return "https://"..muc_domain_base.."/"..node
  31. else
  32. return
  33. "https://"..muc_domain_base.."/"..target_subdomain.."/"..target_node
  34. end
  35. end
  36. -- Listening for all muc presences stanza events. If a presence stanza is from
  37. -- a poltergeist then it will be further processed to determine if a call
  38. -- event should be triggered. Call events are triggered by status strings
  39. -- the status strings supported are:
  40. -- -------------------------
  41. -- Status | Event Type
  42. -- _________________________
  43. -- "Invited" | Invite
  44. module:hook("muc-broadcast-presence", function (event)
  45. -- Detect if the presence is for a poltergeist or not.
  46. if not
  47. (jid.bare(event.occupant.jid) == poltergeist_component)
  48. or
  49. event.stanza == nil
  50. then
  51. return
  52. end
  53. if event.stanza:get_child_text("status") == invited_status then
  54. local url = assert(url_from_room_jid(event.stanza.attr.from))
  55. ext_events.invite(event.stanza, url)
  56. end
  57. end, -101);