瀏覽代碼

FIX: rename disco info component to correct name

FIX: reply to iq only on successful reply from queue server
j8
Aaron van Meerten 5 年之前
父節點
當前提交
828e578af4
共有 2 個檔案被更改,包括 57 行新增17 行删除
  1. 2
    2
      resources/prosody-plugins/mod_jibri_queue.lua
  2. 55
    15
      resources/prosody-plugins/mod_jibri_queue_component.lua

+ 2
- 2
resources/prosody-plugins/mod_jibri_queue.lua 查看文件

@@ -1,5 +1,5 @@
1 1
 local jibri_queue_component
2 2
     = module:get_option_string(
3
-        "jibri_queue_component", "jibri_queue"..module.host);
3
+        "jibri_queue_component", "jibriqueue"..module.host);
4 4
 
5
-module:add_identity("component", "jibri_queue", jibri_queue_component);
5
+module:add_identity("component", "jibri-queue", jibri_queue_component);

+ 55
- 15
resources/prosody-plugins/mod_jibri_queue_component.lua 查看文件

@@ -151,6 +151,12 @@ local function generateToken(audience)
151 151
     end
152 152
 end
153 153
 
154
+local function sendIq(participant,action,participant,time,position,token)
155
+    local outStanza = st.iq({type = 'set', to = participant}):tag("jibri-queue", 
156
+       { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId, action = action }):
157
+
158
+    module:send(outStanza);
159
+end
154 160
 
155 161
 local function cb(content_, code_, response_, request_)
156 162
     if code_ == 200 or code_ == 204 then
@@ -162,7 +168,7 @@ local function cb(content_, code_, response_, request_)
162 168
     end
163 169
 end
164 170
 
165
-local function sendEvent(type,room_address,participant)
171
+local function sendEvent(type,room_address,participant,requestId,replyIq,replyError)
166 172
     local event_ts = round(socket.gettime()*1000);
167 173
     local node, host, resource, target_subdomain = room_jid_split_subdomain(room_address);
168 174
     local room_param = '';
@@ -174,10 +180,11 @@ local function sendEvent(type,room_address,participant)
174 180
 
175 181
     local out_event = {
176 182
         ["conference"] = room_address,
177
-        ["room_param"] = room_param,
178
-        ["event_type"] = type,
183
+        ["roomParam"] = room_param,
184
+        ["eventType"] = type,
179 185
         ["participant"] = participant,
180
-        ["external_api_url"] = external_api_url.."/jibriqueue/update",
186
+        ["externalApiUrl"] = external_api_url.."/jibriqueue/update",
187
+        ["requestId"] = requestId,
181 188
     }
182 189
     module:log("debug","Sending event %s",inspect(out_event));
183 190
 
@@ -189,11 +196,24 @@ local function sendEvent(type,room_address,participant)
189 196
         headers = headers,
190 197
         method = "POST",
191 198
         body = json.encode(out_event)
192
-    }, cb);
199
+    }, function (content_, code_, response_, request_)
200
+        if code_ == 200 or code_ == 204 then
201
+            module:log("debug", "URL Callback: Code %s, Content %s, Request (host %s, path %s, body %s), Response: %s",
202
+                    code_, content_, request_.host, request_.path, inspect(request_.body), inspect(response_));
203
+            module:log("info", "sending reply IQ %s",inspect(replyIq));
204
+            module:send(replyIq);
205
+        else
206
+            module:log("warn", "URL Callback non successful: Code %s, Content %s, Request (%s), Response: %s",
207
+                    code_, content_, inspect(request_), inspect(response_));
208
+            module:log("warn", "sending reply error IQ %s",inspect(replyError));
209
+            module:send(replyError);
210
+        end
211
+    end);
193 212
 end
194 213
 
195 214
 -- receives iq from client currently connected to the room
196 215
 function on_iq(event)
216
+    local requestId;
197 217
     -- Check the type of the incoming stanza to avoid loops:
198 218
     if event.stanza.attr.type == "error" then
199 219
         return; -- We do not want to reply to these, so leave.
@@ -201,11 +221,15 @@ function on_iq(event)
201 221
     if event.stanza.attr.to == module:get_host() then
202 222
         if event.stanza.attr.type == "set" then
203 223
             log("info", "Jibri Queue Messsage Event found: %s ",inspect(event.stanza));
224
+            local reply = st.reply(event.stanza);
225
+            local replyError = st.error_reply(event.stanza,'cancel','internal-server-error',"Queue Server Error");
226
+            module:log("info","Reply stanza %s",inspect(reply));
204 227
 
205 228
             local jibriQueue
206 229
                 = event.stanza:get_child('jibri-queue', 'http://jitsi.org/protocol/jibri-queue');
207 230
             if jibriQueue then
208
-                module:log("info", "Jibri Queue Join Request: %s ",inspect(jibriQueue));
231
+                module:log("info", "Jibri Queue Request: %s ",inspect(jibriQueue));
232
+
209 233
                 local roomAddress = jibriQueue.attr.room;
210 234
                 local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
211 235
 
@@ -222,13 +246,29 @@ function on_iq(event)
222 246
                     return false;
223 247
                 end
224 248
 
225
-                -- now handle new jibri queue message
226
-                room.jibriQueue[occupant.jid] = true;
249
+                local action = jibriQueue.attr.action;
250
+                if action == 'join' then
251
+                    -- join action, so send event out
252
+                    requestId = uuid_gen();
227 253
 
228
-                module:log("Sending JoinQueue event for jid %s occupant %s",roomAddress,occupant.jid)
229
-                sendEvent('JoinQueue',roomAddress,occupant.jid)
254
+                    -- now handle new jibri queue message
255
+                    room.jibriQueue[occupant.jid] = requestId;
256
+                    reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
257
+                    replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
258
+
259
+                    module:log("info","Sending JoinQueue event for jid %s occupant %s reply %s",roomAddress,occupant.jid,inspect(reply));
260
+                    sendEvent('JoinQueue',roomAddress,occupant.jid,requestId,reply,replyError);
261
+                end
262
+                if action == 'leave' then
263
+                    requestId = jibriQueue.attr.requestId;
264
+                    -- TODO: check that requestId is the same as cached value
265
+                    room.jibriQueue[occupant.jid] = nil;
266
+                    reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
267
+                    replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
268
+                    sendEvent('LeaveQueue',roomAddress,occupant.jid,requestId,reply,replyError);
269
+                end
230 270
             else
231
-                module:log("Jibri Queue Stanza missing child %s",inspect(event.stanza))
271
+                module:log("warn","Jibri Queue Stanza missing child %s",inspect(event.stanza))
232 272
             end
233 273
         end
234 274
     end
@@ -255,7 +295,7 @@ function room_destroyed(event)
255 295
     end
256 296
     for jid, x in pairs(room.jibriQueue) do
257 297
         if x then
258
-            sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),jid);
298
+            sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),jid,x);
259 299
         end
260 300
     end
261 301
 end
@@ -269,12 +309,12 @@ function occupant_leaving(event)
269 309
     end
270 310
 
271 311
     local occupant = event.occupant;
272
-
312
+    local requestId = room.jibriQueue[occupant.jid];
273 313
     -- check if user has cached queue request
274
-    if room.jibriQueue[occupant.jid] then
314
+    if requestId then
275 315
         -- remove occupant from queue cache, signal backend
276 316
         room.jibriQueue[occupant.jid] = nil;
277
-        sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),occupant.jid);
317
+        sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),occupant.jid,requestId);
278 318
     end
279 319
 end
280 320
 

Loading…
取消
儲存