浏览代码

Updates correct loading and fix checking is dominant speaker.

j8
damencho 6 年前
父节点
当前提交
a5fc62b920
共有 1 个文件被更改,包括 24 次插入11 次删除
  1. 24
    11
      resources/prosody-plugins/mod_speakerstats_component.lua

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

10
     log("error", "No muc_component specified. No muc to operate on!");
10
     log("error", "No muc_component specified. No muc to operate on!");
11
     return;
11
     return;
12
 end
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
 -- receives messages from client currently connected to the room
16
 -- receives messages from client currently connected to the room
22
 -- clients indicates their own dominant speaker events
17
 -- clients indicates their own dominant speaker events
128
 
123
 
129
                     -- before sending we need to calculate current dominant speaker
124
                     -- before sending we need to calculate current dominant speaker
130
                     -- state
125
                     -- state
131
-                    if values:isDominantSpeaker() ~= nil then
126
+                    if values:isDominantSpeaker() then
132
                         local timeElapsed = math.floor(
127
                         local timeElapsed = math.floor(
133
                             socket.gettime()*1000 - values._dominantSpeakerStart);
128
                             socket.gettime()*1000 - values._dominantSpeakerStart);
134
                         totalDominantSpeakerTime = totalDominantSpeakerTime
129
                         totalDominantSpeakerTime = totalDominantSpeakerTime
184
 end
179
 end
185
 
180
 
186
 module:hook("message/host", on_message);
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

正在加载...
取消
保存