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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. local calling_status = "calling"
  19. local ringing_status = "ringing"
  20. local busy_status = "busy"
  21. local rejected_status = "rejected"
  22. local connected_status = "connected"
  23. -- url_from_room_jid will determine the url for a conference
  24. -- provided a room jid. It is required that muc domain mapping
  25. -- is enabled and configured. There are two url formats that are supported.
  26. -- The following urls are examples of the supported formats.
  27. -- https://meet.jit.si/jitsi/ProductiveMeeting
  28. -- https://meet.jit.si/MoreProductiveMeeting
  29. -- The urls are derived from portions of the room jid.
  30. local function url_from_room_jid(room_jid)
  31. local node, _, _ = jid.split(room_jid)
  32. if not node then return nil end
  33. local target_subdomain, target_node = node:match("^%[([^%]]+)%](.+)$")
  34. if not(target_node or target_subdomain) then
  35. return "https://"..muc_domain_base.."/"..node
  36. else
  37. return
  38. "https://"..muc_domain_base.."/"..target_subdomain.."/"..target_node
  39. end
  40. end
  41. -- Listening for all muc presences stanza events. If a presence stanza is from
  42. -- a poltergeist then it will be further processed to determine if a call
  43. -- event should be triggered. Call events are triggered by status strings
  44. -- the status strings supported are:
  45. -- -------------------------
  46. -- Status | Event Type
  47. -- _________________________
  48. -- "calling" | INVITE
  49. -- "Invited" | INVITE
  50. -- "ringing" | CANCEL
  51. -- "busy" | CANCEL
  52. -- "rejected" | CANCEL
  53. -- "connected" | CANCEL
  54. module:hook("muc-broadcast-presence", function (event)
  55. -- Detect if the presence is for a poltergeist or not.
  56. if not
  57. (jid.bare(event.occupant.jid) == poltergeist_component)
  58. or
  59. event.stanza == nil
  60. then
  61. return
  62. end
  63. local invite = function()
  64. local url = assert(url_from_room_jid(event.stanza.attr.from))
  65. ext_events.invite(event.stanza, url)
  66. end
  67. local cancel = function()
  68. local url = assert(url_from_room_jid(event.stanza.attr.from))
  69. local status = event.stanza:get_child_text("status")
  70. ext_events.cancel(event.stanza, url, string.lower(status))
  71. end
  72. local switch = function(status)
  73. case = {
  74. [invited_status] = function() invite() end,
  75. [calling_status] = function() invite() end,
  76. [ringing_status] = function() cancel() end,
  77. [busy_status] = function() cancel() end,
  78. [rejected_status] = function() cancel() end,
  79. [connected_status] = function() cancel() end
  80. }
  81. if case[status] then case[status]() end
  82. end
  83. switch(event.stanza:get_child_text("status"))
  84. end, -101);