|
@@ -0,0 +1,64 @@
|
|
1
|
+local ext_events = module:require "ext_events"
|
|
2
|
+local jid = require "util.jid"
|
|
3
|
+
|
|
4
|
+-- Options and configuration
|
|
5
|
+local poltergeist_component = module:get_option_string(
|
|
6
|
+ "poltergeist_component",
|
|
7
|
+ module.host
|
|
8
|
+);
|
|
9
|
+local muc_domain_base = module:get_option_string("muc_mapper_domain_base");
|
|
10
|
+if not muc_domain_base then
|
|
11
|
+ module:log(
|
|
12
|
+ "warn",
|
|
13
|
+ "No 'muc_domain_base' option set, unable to send call events."
|
|
14
|
+ );
|
|
15
|
+ return
|
|
16
|
+end
|
|
17
|
+
|
|
18
|
+-- Status strings that trigger call events.
|
|
19
|
+local invited_status = "Invited"
|
|
20
|
+
|
|
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
|
+
|
|
32
|
+ local target_subdomain, target_node = node:match("^%[([^%]]+)%](.+)$")
|
|
33
|
+
|
|
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
|
+
|
|
42
|
+-- Listening for all muc presences stanza events. If a presence stanza is from
|
|
43
|
+-- a poltergeist then it will be further processed to determine if a call
|
|
44
|
+-- event should be triggered. Call events are triggered by status strings
|
|
45
|
+-- the status strings supported are:
|
|
46
|
+-- -------------------------
|
|
47
|
+-- Status | Event Type
|
|
48
|
+-- _________________________
|
|
49
|
+-- "Invited" | Invite
|
|
50
|
+module:hook("muc-broadcast-presence", function (event)
|
|
51
|
+ -- Detect if the presence is for a poltergeist or not.
|
|
52
|
+ if not
|
|
53
|
+ (jid.bare(event.occupant.jid) == poltergeist_component)
|
|
54
|
+ or
|
|
55
|
+ event.stanza == nil
|
|
56
|
+ then
|
|
57
|
+ return
|
|
58
|
+ end
|
|
59
|
+
|
|
60
|
+ if event.stanza:get_child_text("status") == invited_status then
|
|
61
|
+ local url = assert(url_from_room_jid(event.stanza.attr.from))
|
|
62
|
+ ext_events.invite(event.stanza, url)
|
|
63
|
+ end
|
|
64
|
+end, -101);
|