Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mod_muc_call.lua 3.8KB

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