|
@@ -1,6 +1,9 @@
|
1
|
1
|
local get_room_from_jid = module:require "util".get_room_from_jid;
|
2
|
2
|
local jid_resource = require "util.jid".resource;
|
3
|
3
|
local ext_events = module:require "ext_events"
|
|
4
|
+local st = require "util.stanza";
|
|
5
|
+local socket = require "socket";
|
|
6
|
+local json = require "util.json";
|
4
|
7
|
|
5
|
8
|
local muc_component_host = module:get_option_string("muc_component");
|
6
|
9
|
if muc_component_host == nil then
|
|
@@ -82,10 +85,10 @@ function SpeakerStats:setIsDominantSpeaker(isNowDominantSpeaker)
|
82
|
85
|
"set isDominant %s for %s", tostring(isNowDominantSpeaker), self.nick);
|
83
|
86
|
|
84
|
87
|
if not self._isDominantSpeaker and isNowDominantSpeaker then
|
85
|
|
- self._dominantSpeakerStart = os.time();
|
|
88
|
+ self._dominantSpeakerStart = socket.gettime()*1000;
|
86
|
89
|
elseif self._isDominantSpeaker and not isNowDominantSpeaker then
|
87
|
|
- local now = os.time();
|
88
|
|
- local timeElapsed = now - (self._dominantSpeakerStart or 0);
|
|
90
|
+ local now = socket.gettime()*1000;
|
|
91
|
+ local timeElapsed = math.floor(now - (self._dominantSpeakerStart or 0));
|
89
|
92
|
|
90
|
93
|
self.totalDominantSpeakerTime
|
91
|
94
|
= self.totalDominantSpeakerTime + timeElapsed;
|
|
@@ -109,6 +112,48 @@ function occupant_joined(event)
|
109
|
112
|
local nick = jid_resource(occupant.nick);
|
110
|
113
|
|
111
|
114
|
if room.speakerStats then
|
|
115
|
+ -- lets send the current speaker stats to that user, so he can update
|
|
116
|
+ -- its local stats
|
|
117
|
+ if next(room.speakerStats) ~= nil then
|
|
118
|
+ local users_json = {};
|
|
119
|
+ for jid, values in pairs(room.speakerStats) do
|
|
120
|
+ -- skip reporting those without a nick('dominantSpeakerId')
|
|
121
|
+ -- and skip focus if sneaked into the table
|
|
122
|
+ if values.nick ~= nil and values.nick ~= 'focus' then
|
|
123
|
+ local resultSpeakerStats = {};
|
|
124
|
+ local totalDominantSpeakerTime
|
|
125
|
+ = values.totalDominantSpeakerTime;
|
|
126
|
+
|
|
127
|
+ -- before sending we need to calculate current dominant speaker
|
|
128
|
+ -- state
|
|
129
|
+ if values._dominantSpeakerStart ~= nil then
|
|
130
|
+ local timeElapsed = math.floor(
|
|
131
|
+ socket.gettime()*1000
|
|
132
|
+ - (values._dominantSpeakerStart or 0));
|
|
133
|
+ totalDominantSpeakerTime = totalDominantSpeakerTime
|
|
134
|
+ + timeElapsed;
|
|
135
|
+ end
|
|
136
|
+
|
|
137
|
+ resultSpeakerStats.displayName = values.displayName;
|
|
138
|
+ resultSpeakerStats.totalDominantSpeakerTime
|
|
139
|
+ = totalDominantSpeakerTime;
|
|
140
|
+ users_json[values.nick] = resultSpeakerStats;
|
|
141
|
+ end
|
|
142
|
+ end
|
|
143
|
+
|
|
144
|
+ local body_json = {};
|
|
145
|
+ body_json.type = 'speakerstats';
|
|
146
|
+ body_json.users = users_json;
|
|
147
|
+
|
|
148
|
+ local stanza = st.message({
|
|
149
|
+ from = module.host;
|
|
150
|
+ to = occupant.jid; })
|
|
151
|
+ :tag("json-message", {xmlns='http://jitsi.org/jitmeet'})
|
|
152
|
+ :text(json.encode(body_json)):up();
|
|
153
|
+
|
|
154
|
+ room:route_stanza(stanza);
|
|
155
|
+ end
|
|
156
|
+
|
112
|
157
|
room.speakerStats[occupant.jid] = new_SpeakerStats(nick);
|
113
|
158
|
end
|
114
|
159
|
end
|