Преглед изворни кода

FIX: jibri-queue module log improvements

master
Aaron van Meerten пре 4 година
родитељ
комит
d716665f27
1 измењених фајлова са 31 додато и 24 уклоњено
  1. 31
    24
      resources/prosody-plugins/mod_jibri_queue_component.lua

+ 31
- 24
resources/prosody-plugins/mod_jibri_queue_component.lua Прегледај датотеку

37
     = module:get_option_string("asap_key_server");
37
     = module:get_option_string("asap_key_server");
38
 
38
 
39
 if ASAPKeyServer then
39
 if ASAPKeyServer then
40
-    module:log("info", "ASAP Public Key URL %s", ASAPKeyServer);
40
+    module:log("debug", "ASAP Public Key URL %s", ASAPKeyServer);
41
     token_util:set_asap_key_server(ASAPKeyServer);
41
     token_util:set_asap_key_server(ASAPKeyServer);
42
 end
42
 end
43
 
43
 
56
 local ASAPAcceptedIssuers
56
 local ASAPAcceptedIssuers
57
     = module:get_option_array('asap_accepted_issuers',{'jibri-queue'});
57
     = module:get_option_array('asap_accepted_issuers',{'jibri-queue'});
58
 
58
 
59
-module:log("info", "ASAP Accepted Issuers %s", ASAPAcceptedIssuers);
59
+module:log("debug", "ASAP Accepted Issuers %s", ASAPAcceptedIssuers);
60
 token_util:set_asap_accepted_issuers(ASAPAcceptedIssuers);
60
 token_util:set_asap_accepted_issuers(ASAPAcceptedIssuers);
61
 
61
 
62
 local ASAPAcceptedAudiences
62
 local ASAPAcceptedAudiences
63
     = module:get_option_array('asap_accepted_audiences',{'*'});
63
     = module:get_option_array('asap_accepted_audiences',{'*'});
64
 
64
 
65
-module:log("info", "ASAP Accepted Audiences %s", ASAPAcceptedAudiences);
65
+module:log("debug", "ASAP Accepted Audiences %s", ASAPAcceptedAudiences);
66
 token_util:set_asap_accepted_audiences(ASAPAcceptedAudiences);
66
 token_util:set_asap_accepted_audiences(ASAPAcceptedAudiences);
67
 
67
 
68
 -- do not require room to be set on tokens for jibri queue
68
 -- do not require room to be set on tokens for jibri queue
112
 log("info", "Starting jibri queue handling for %s", muc_component_host);
112
 log("info", "Starting jibri queue handling for %s", muc_component_host);
113
 
113
 
114
 local external_api_url = module:get_option_string("external_api_url",tostring(parentHostName));
114
 local external_api_url = module:get_option_string("external_api_url",tostring(parentHostName));
115
-module:log("info", "External advertised API URL", external_api_url);
115
+module:log("debug", "External advertised API URL", external_api_url);
116
 
116
 
117
 -- Read ASAP key once on module startup
117
 -- Read ASAP key once on module startup
118
 local f = io.open(ASAPKeyPath, "r");
118
 local f = io.open(ASAPKeyPath, "r");
179
 local function sendIq(participant,action,requestId,time,position,token)
179
 local function sendIq(participant,action,requestId,time,position,token)
180
     local iqId = uuid_gen();
180
     local iqId = uuid_gen();
181
     local from = module:get_host();
181
     local from = module:get_host();
182
-    module:log("info","Oubound iq id %s",iqId);
182
+--    module:log("info","Oubound iq id %s",iqId);
183
     local outStanza = st.iq({type = 'set', from = from, to = participant, id = iqId}):tag("jibri-queue", 
183
     local outStanza = st.iq({type = 'set', from = from, to = participant, id = iqId}):tag("jibri-queue", 
184
        { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId, action = action });
184
        { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId, action = action });
185
 
185
 
186
-    module:log("info","Oubound base stanza %s",inspect(outStanza));
186
+--    module:log("info","Oubound base stanza %s",inspect(outStanza));
187
 
187
 
188
     if token then
188
     if token then
189
         outStanza:tag("token"):text(token):up()
189
         outStanza:tag("token"):text(token):up()
194
     if position then
194
     if position then
195
         outStanza:tag("position"):text(tostring(position)):up()
195
         outStanza:tag("position"):text(tostring(position)):up()
196
     end
196
     end
197
-    module:log("info","Oubound stanza %s",inspect(outStanza));
197
+ --    module:log("debug","Oubound stanza %s",inspect(outStanza));
198
     module:send(outStanza);
198
     module:send(outStanza);
199
 end
199
 end
200
 
200
 
245
         if code_ == 200 or code_ == 204 then
245
         if code_ == 200 or code_ == 204 then
246
             module:log("debug", "URL Callback: Code %s, Content %s, Request (host %s, path %s, body %s), Response: %s",
246
             module:log("debug", "URL Callback: Code %s, Content %s, Request (host %s, path %s, body %s), Response: %s",
247
                     code_, content_, request_.host, request_.path, inspect(request_.body), inspect(response_));
247
                     code_, content_, request_.host, request_.path, inspect(request_.body), inspect(response_));
248
-            module:log("info", "sending reply IQ %s",inspect(replyIq));
249
-            module:send(replyIq);
248
+            if (replyIq) then
249
+                module:log("debug", "sending reply IQ %s",inspect(replyIq));
250
+                module:send(replyIq);
251
+            end
250
         else
252
         else
251
             module:log("warn", "URL Callback non successful: Code %s, Content %s, Request (%s), Response: %s",
253
             module:log("warn", "URL Callback non successful: Code %s, Content %s, Request (%s), Response: %s",
252
                     code_, content_, inspect(request_), inspect(response_));
254
                     code_, content_, inspect(request_), inspect(response_));
253
-            module:log("warn", "sending reply error IQ %s",inspect(replyError));
254
-            module:send(replyError);
255
+            if (replyError) then
256
+                module:log("warn", "sending reply error IQ %s",inspect(replyError));
257
+                module:send(replyError);
258
+            end
255
         end
259
         end
256
     end);
260
     end);
257
 end
261
 end
265
     end
269
     end
266
     if event.stanza.attr.to == module:get_host() then
270
     if event.stanza.attr.to == module:get_host() then
267
         if event.stanza.attr.type == "set" then
271
         if event.stanza.attr.type == "set" then
268
-            log("info", "Jibri Queue Messsage Event found: %s ",inspect(event.stanza));
269
             local reply = st.reply(event.stanza);
272
             local reply = st.reply(event.stanza);
270
             local replyError = st.error_reply(event.stanza,'cancel','internal-server-error',"Queue Server Error");
273
             local replyError = st.error_reply(event.stanza,'cancel','internal-server-error',"Queue Server Error");
271
-            module:log("info","Reply stanza %s",inspect(reply));
272
 
274
 
273
             local jibriQueue
275
             local jibriQueue
274
                 = event.stanza:get_child('jibri-queue', 'http://jitsi.org/protocol/jibri-queue');
276
                 = event.stanza:get_child('jibri-queue', 'http://jitsi.org/protocol/jibri-queue');
275
             if jibriQueue then
277
             if jibriQueue then
276
-                module:log("info", "Jibri Queue Request: %s ",inspect(jibriQueue));
278
+                module:log("debug", "Received Jibri Queue Request: %s ",inspect(jibriQueue));
277
 
279
 
278
                 local roomAddress = jibriQueue.attr.room;
280
                 local roomAddress = jibriQueue.attr.room;
279
                 local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
281
                 local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
295
                 if action == 'join' then
297
                 if action == 'join' then
296
                     -- join action, so send event out
298
                     -- join action, so send event out
297
                     requestId = uuid_gen();
299
                     requestId = uuid_gen();
300
+                    module:log("debug","Received join queue request for jid %s occupant %s requestId %s",roomAddress,occupant.jid,requestId);
298
 
301
 
299
                     -- now handle new jibri queue message
302
                     -- now handle new jibri queue message
300
                     room.jibriQueue[occupant.jid] = requestId;
303
                     room.jibriQueue[occupant.jid] = requestId;
301
                     reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
304
                     reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
302
                     replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
305
                     replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
303
 
306
 
304
-                    module:log("info","Sending JoinQueue event for jid %s occupant %s reply %s",roomAddress,occupant.jid,inspect(reply));
307
+                    module:log("debug","Sending JoinQueue event for jid %s occupant %s reply %s",roomAddress,occupant.jid,inspect(reply));
305
                     sendEvent('JoinQueue',roomAddress,occupant.jid,requestId,reply,replyError);
308
                     sendEvent('JoinQueue',roomAddress,occupant.jid,requestId,reply,replyError);
306
                 end
309
                 end
307
                 if action == 'leave' then
310
                 if action == 'leave' then
308
                     requestId = jibriQueue.attr.requestId;
311
                     requestId = jibriQueue.attr.requestId;
312
+                    module:log("debug","Received leave queue request for jid %s occupant %s requestId %s",roomAddress,occupant.jid,requestId);
313
+
309
                     -- TODO: check that requestId is the same as cached value
314
                     -- TODO: check that requestId is the same as cached value
310
                     room.jibriQueue[occupant.jid] = nil;
315
                     room.jibriQueue[occupant.jid] = nil;
311
                     reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
316
                     reply:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
312
                     replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
317
                     replyError:add_child(st.stanza("jibri-queue", { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId})):up()
318
+
319
+                    module:log("debug","Sending LeaveQueue event for jid %s occupant %s reply %s",roomAddress,occupant.jid,inspect(reply));
313
                     sendEvent('LeaveQueue',roomAddress,occupant.jid,requestId,reply,replyError);
320
                     sendEvent('LeaveQueue',roomAddress,occupant.jid,requestId,reply,replyError);
314
                 end
321
                 end
315
             else
322
             else
368
 -- executed on every host added internally in prosody, including components
375
 -- executed on every host added internally in prosody, including components
369
 function process_host(host)
376
 function process_host(host)
370
     if host == muc_component_host then -- the conference muc component
377
     if host == muc_component_host then -- the conference muc component
371
-        module:log("info","Hook to muc events on %s", host);
378
+        module:log("debug","Hook to muc events on %s", host);
372
 
379
 
373
         local muc_module = module:context(host);
380
         local muc_module = module:context(host);
374
         muc_module:hook("muc-room-created", room_created, -1);
381
         muc_module:hook("muc-room-created", room_created, -1);
379
 end
386
 end
380
 
387
 
381
 if prosody.hosts[muc_component_host] == nil then
388
 if prosody.hosts[muc_component_host] == nil then
382
-    module:log("info","No muc component found, will listen for it: %s", muc_component_host)
389
+    module:log("debug","No muc component found, will listen for it: %s", muc_component_host)
383
 
390
 
384
     -- when a host or component is added
391
     -- when a host or component is added
385
     prosody.events.add_handler("host-activated", process_host);
392
     prosody.events.add_handler("host-activated", process_host);
430
 -- @param event the http event, holds the request query
437
 -- @param event the http event, holds the request query
431
 -- @return GET response, containing a json with response details
438
 -- @return GET response, containing a json with response details
432
 function handle_update_jibri_queue(event)
439
 function handle_update_jibri_queue(event)
433
-    module:log("info","Update Jibri Queue Event Received");
434
     -- if (not event.request.url.query) then
440
     -- if (not event.request.url.query) then
435
     --     return { status_code = 400; };
441
     --     return { status_code = 400; };
436
     -- end
442
     -- end
438
     local body = json.decode(event.request.body);
444
     local body = json.decode(event.request.body);
439
 --    local params = parse(event.request.url.query);
445
 --    local params = parse(event.request.url.query);
440
 
446
 
441
-    module:log("info","Update Jibri Event Body %s",inspect(body));
447
+    module:log("debug","Update Jibri Queue Event Received: %s",inspect(body));
442
 
448
 
443
 --    local token = params["token"];
449
 --    local token = params["token"];
444
     local token
450
     local token
449
         else
455
         else
450
             local prefixStart, prefixEnd = token:find("Bearer ");
456
             local prefixStart, prefixEnd = token:find("Bearer ");
451
             if prefixStart ~= 1 then
457
             if prefixStart ~= 1 then
452
-                module:log("error", "Invalid authorization header format. The header must start with the string 'Bearer '");
458
+                module:log("error", "REST event: Invalid authorization header format. The header must start with the string 'Bearer '");
453
                 return 403
459
                 return 403
454
             end
460
             end
455
             token = token:sub(prefixEnd + 1);
461
             token = token:sub(prefixEnd + 1);
467
     local room_jid = room_jid_match_rewrite(roomAddress);
473
     local room_jid = room_jid_match_rewrite(roomAddress);
468
 
474
 
469
     if not verify_token(token, room_jid, {}) then
475
     if not verify_token(token, room_jid, {}) then
476
+        log("error", "REST event: Invalid token for room %s to route action %s for requestId %s", roomAddress, action, requestId);
470
         return { status_code = 403; };
477
         return { status_code = 403; };
471
     end
478
     end
472
 
479
 
473
     local room = get_room_from_jid(room_jid);
480
     local room = get_room_from_jid(room_jid);
474
     if (not room) then
481
     if (not room) then
475
-        log("error", "no room found %s", roomAddress);
482
+        log("error", "REST event: no room found %s to route action %s for requestId %s", roomAddress, action, requestId);
476
         return { status_code = 404; };
483
         return { status_code = 404; };
477
     end
484
     end
478
 
485
 
479
     local occupant = room:get_occupant_by_real_jid(user_jid);
486
     local occupant = room:get_occupant_by_real_jid(user_jid);
480
     if not occupant then
487
     if not occupant then
481
-        log("warn", "No occupant %s found for %s", user_jid, roomAddress);
488
+        log("warn", "REST event: No occupant %s found for %s to route action %s for requestId %s", user_jid, roomAddress, action, requestId);
482
         return { status_code = 404; };
489
         return { status_code = 404; };
483
     end
490
     end
484
 
491
 
485
     if not room.jibriQueue[occupant.jid] then
492
     if not room.jibriQueue[occupant.jid] then
486
-        log("warn", "No queue request found for occupant %s in conference %s",occupant.jid,room.jid)
493
+        log("warn", "REST event: No queue request found for occupant %s in conference %s to route action %s for requestId %s",occupant.jid,room.jid, action, requestId)
487
         return { status_code = 404; };
494
         return { status_code = 404; };
488
     end
495
     end
489
 
496
 
499
         requestId = room.jibriQueue[occupant.jid];
506
         requestId = room.jibriQueue[occupant.jid];
500
     end
507
     end
501
 
508
 
502
-    -- TODO: actually implement udpate code here
509
+    log("debug", "REST event: Sending update for occupant %s in conference %s to route action %s for requestId %s",occupant.jid,room.jid, action, requestId)
503
     sendIq(occupant.jid,action,requestId,time,position,userJWT);
510
     sendIq(occupant.jid,action,requestId,time,position,userJWT);
504
     return { status_code = 200; };
511
     return { status_code = 200; };
505
 end
512
 end

Loading…
Откажи
Сачувај