瀏覽代碼

Updates correct loading and fix checking is dominant speaker.

master
damencho 5 年之前
父節點
當前提交
a5fc62b920
共有 1 個文件被更改,包括 24 次插入11 次删除
  1. 24
    11
      resources/prosody-plugins/mod_speakerstats_component.lua

+ 24
- 11
resources/prosody-plugins/mod_speakerstats_component.lua 查看文件

@@ -10,13 +10,8 @@ if muc_component_host == nil then
10 10
     log("error", "No muc_component specified. No muc to operate on!");
11 11
     return;
12 12
 end
13
-local muc_module = module:context("conference."..muc_component_host);
14
-if muc_module == nil then
15
-    log("error", "No such muc found, check muc_component config.");
16
-    return;
17
-end
18 13
 
19
-log("debug", "Starting speakerstats for %s", muc_component_host);
14
+log("info", "Starting speakerstats for %s", muc_component_host);
20 15
 
21 16
 -- receives messages from client currently connected to the room
22 17
 -- clients indicates their own dominant speaker events
@@ -128,7 +123,7 @@ function occupant_joined(event)
128 123
 
129 124
                     -- before sending we need to calculate current dominant speaker
130 125
                     -- state
131
-                    if values:isDominantSpeaker() ~= nil then
126
+                    if values:isDominantSpeaker() then
132 127
                         local timeElapsed = math.floor(
133 128
                             socket.gettime()*1000 - values._dominantSpeakerStart);
134 129
                         totalDominantSpeakerTime = totalDominantSpeakerTime
@@ -184,7 +179,25 @@ function room_destroyed(event)
184 179
 end
185 180
 
186 181
 module:hook("message/host", on_message);
187
-muc_module:hook("muc-room-created", room_created, -1);
188
-muc_module:hook("muc-occupant-joined", occupant_joined, -1);
189
-muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
190
-muc_module:hook("muc-room-destroyed", room_destroyed, -1);
182
+
183
+-- executed on every host added internally in prosody, including components
184
+function process_host(host)
185
+    if host == muc_component_host then -- the conference muc component
186
+        module:log("info","Hook to muc events on %s", host);
187
+
188
+        local muc_module = module:context(host);
189
+        muc_module:hook("muc-room-created", room_created, -1);
190
+        muc_module:hook("muc-occupant-joined", occupant_joined, -1);
191
+        muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
192
+        muc_module:hook("muc-room-destroyed", room_destroyed, -1);
193
+    end
194
+end
195
+
196
+if prosody.hosts[muc_component_host] == nil then
197
+    module:log("info","No muc component found, will listen for it: %s", muc_component_host)
198
+
199
+    -- when a host or component is added
200
+    prosody.events.add_handler("host-activated", process_host);
201
+else
202
+    process_host(muc_component_host);
203
+end

Loading…
取消
儲存