diff --git a/resources/prosody-plugins/mod_speakerstats_component.lua b/resources/prosody-plugins/mod_speakerstats_component.lua index 14c4cbd58..0c7a8c7ac 100644 --- a/resources/prosody-plugins/mod_speakerstats_component.lua +++ b/resources/prosody-plugins/mod_speakerstats_component.lua @@ -6,6 +6,7 @@ local ext_events = module:require "ext_events" local st = require "util.stanza"; local socket = require "socket"; local json = require "util.json"; +local um_is_admin = require "core.usermanager".is_admin; -- we use async to detect Prosody 0.10 and earlier local have_async = pcall(require, "util.async"); @@ -22,6 +23,10 @@ end log("info", "Starting speakerstats for %s", muc_component_host); +local function is_admin(jid) + return um_is_admin(jid, module.host); +end + -- receives messages from client currently connected to the room -- clients indicates their own dominant speaker events function on_message(event) @@ -126,9 +131,9 @@ end -- Create SpeakerStats object for the joined user function occupant_joined(event) - local room = event.room; + local occupant, room = event.occupant, event.room; - if is_healthcheck_room(room.jid) then + if is_healthcheck_room(room.jid) or is_admin(occupant.bare_jid) then return; end @@ -145,26 +150,26 @@ function occupant_joined(event) -- skip reporting those without a nick('dominantSpeakerId') -- and skip focus if sneaked into the table if values.nick ~= nil and values.nick ~= 'focus' then - local resultSpeakerStats = {}; - local totalDominantSpeakerTime - = values.totalDominantSpeakerTime; + local totalDominantSpeakerTime = values.totalDominantSpeakerTime; + if totalDominantSpeakerTime > 0 or room:get_occupant_jid(jid) == nil then + -- before sending we need to calculate current dominant speaker state + if values:isDominantSpeaker() then + local timeElapsed = math.floor(socket.gettime()*1000 - values._dominantSpeakerStart); + totalDominantSpeakerTime = totalDominantSpeakerTime + timeElapsed; + end - -- before sending we need to calculate current dominant speaker - -- state - if values:isDominantSpeaker() then - local timeElapsed = math.floor( - socket.gettime()*1000 - values._dominantSpeakerStart); - totalDominantSpeakerTime = totalDominantSpeakerTime - + timeElapsed; + users_json[values.nick] = { + displayName = values.displayName, + totalDominantSpeakerTime = totalDominantSpeakerTime + }; end - - resultSpeakerStats.displayName = values.displayName; - resultSpeakerStats.totalDominantSpeakerTime - = totalDominantSpeakerTime; - users_json[values.nick] = resultSpeakerStats; end end + if next(users_json) == nil then + return; + end + local body_json = {}; body_json.type = 'speakerstats'; body_json.users = users_json;