Browse Source

FEATURE: proper outbound iq handler for REST requests

master
Aaron van Meerten 4 years ago
parent
commit
7858f12df2
1 changed files with 59 additions and 15 deletions
  1. 59
    15
      resources/prosody-plugins/mod_jibri_queue_component.lua

+ 59
- 15
resources/prosody-plugins/mod_jibri_queue_component.lua View File

151
     end
151
     end
152
 end
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 }):
154
+local function sendIq(participant,action,requestId,time,position,token)
155
+    local iqId = uuid_gen();
156
+    local from = module:get_host();
157
+    module:log("info","Oubound iq id %s",iqId);
158
+    local outStanza = st.iq({type = 'set', from = from, to = participant, id = iqId}):tag("jibri-queue", 
159
+       { xmlns = 'http://jitsi.org/protocol/jibri-queue', requestId = requestId, action = action });
157
 
160
 
161
+    module:log("info","Oubound base stanza %s",inspect(outStanza));
162
+
163
+    if token then
164
+        outStanza:tag("token"):text(token):up()
165
+    end
166
+    if time then
167
+        outStanza:tag("time"):text(time):up()
168
+    end
169
+    if position then
170
+        outStanza:tag("position"):text(position):up()
171
+    end
172
+    module:log("info","Oubound stanza %s",inspect(outStanza));
158
     module:send(outStanza);
173
     module:send(outStanza);
159
 end
174
 end
160
 
175
 
391
 -- @param event the http event, holds the request query
406
 -- @param event the http event, holds the request query
392
 -- @return GET response, containing a json with response details
407
 -- @return GET response, containing a json with response details
393
 function handle_update_jibri_queue(event)
408
 function handle_update_jibri_queue(event)
394
-    if (not event.request.url.query) then
395
-        return { status_code = 400; };
396
-    end
409
+    module:log("info","Update Jibri Queue Event Received");
410
+    -- if (not event.request.url.query) then
411
+    --     return { status_code = 400; };
412
+    -- end
397
 
413
 
398
     local body = json.decode(event.request.body);
414
     local body = json.decode(event.request.body);
399
-    local params = parse(event.request.url.query);
415
+--    local params = parse(event.request.url.query);
400
 
416
 
401
-    local token = params["token"];
417
+    module:log("info","Update Jibri Event Body %s",inspect(body));
418
+
419
+--    local token = params["token"];
420
+    local token
402
     if not token then
421
     if not token then
403
         token = event.request.headers["authorization"];
422
         token = event.request.headers["authorization"];
404
-        local prefixStart, prefixEnd = token:find("Bearer ");
405
-        if prefixStart ~= 1 then
406
-            module:log("error", "Invalid authorization header format. The header must start with the string 'Bearer '");
407
-            return 403
423
+        if not token then
424
+            token = ''
425
+        else
426
+            local prefixStart, prefixEnd = token:find("Bearer ");
427
+            if prefixStart ~= 1 then
428
+                module:log("error", "Invalid authorization header format. The header must start with the string 'Bearer '");
429
+                return 403
430
+            end
431
+            token = token:sub(prefixEnd + 1);
408
         end
432
         end
409
-        token = token:sub(prefixEnd + 1);
410
     end
433
     end
411
     
434
     
412
     local user_jid = body["participant"];
435
     local user_jid = body["participant"];
413
     local roomAddress = body["conference"];
436
     local roomAddress = body["conference"];
414
     local userJWT = body["token"];
437
     local userJWT = body["token"];
438
+    local action = body["action"];
439
+    local time = body["time"];
440
+    local position = body["position"];
441
+    local requestId = body["requestId"];
415
 
442
 
416
     if not verify_token(token, roomAddress, {}) then
443
     if not verify_token(token, roomAddress, {}) then
417
         return { status_code = 403; };
444
         return { status_code = 403; };
429
         return { status_code = 404; };
456
         return { status_code = 404; };
430
     end
457
     end
431
 
458
 
432
-    -- TODO: actually implement udpate code here
459
+    if not room.jibriQueue[occupant.jid] then
460
+        log("warn", "No queue request found for occupant %s in conference %s",occupant.jid,room.jid)
461
+        return { status_code = 404; };
462
+    end
433
 
463
 
464
+    if not action then
465
+        if userJWT then
466
+            action = 'token';
467
+        else
468
+            action = 'info';
469
+        end
470
+    end
471
+
472
+    if not requestId then
473
+        requestId = room.jibriQueue[occupant.jid];
474
+    end
475
+
476
+    -- TODO: actually implement udpate code here
477
+    sendIq(occupant.jid,action,requestId,time,position,userJWT);
434
     return { status_code = 200; };
478
     return { status_code = 200; };
435
 end
479
 end
436
 
480
 
439
     default_path = "/";
483
     default_path = "/";
440
     name = "jibriqueue";
484
     name = "jibriqueue";
441
     route = {
485
     route = {
442
-        ["GET /jibriqueue/update"] = function (event) return async_handler_wrapper(event,handle_update_jibri_queue) end;
486
+        ["POST /jibriqueue/update"] = function (event) return async_handler_wrapper(event,handle_update_jibri_queue) end;
443
     };
487
     };
444
 });
488
 });

Loading…
Cancel
Save