|
@@ -151,10 +151,25 @@ 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 }):
|
|
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
|
173
|
module:send(outStanza);
|
159
|
174
|
end
|
160
|
175
|
|
|
@@ -391,27 +406,39 @@ end
|
391
|
406
|
-- @param event the http event, holds the request query
|
392
|
407
|
-- @return GET response, containing a json with response details
|
393
|
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
|
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
|
421
|
if not token then
|
403
|
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
|
432
|
end
|
409
|
|
- token = token:sub(prefixEnd + 1);
|
410
|
433
|
end
|
411
|
434
|
|
412
|
435
|
local user_jid = body["participant"];
|
413
|
436
|
local roomAddress = body["conference"];
|
414
|
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
|
443
|
if not verify_token(token, roomAddress, {}) then
|
417
|
444
|
return { status_code = 403; };
|
|
@@ -429,8 +456,25 @@ function handle_update_jibri_queue(event)
|
429
|
456
|
return { status_code = 404; };
|
430
|
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
|
478
|
return { status_code = 200; };
|
435
|
479
|
end
|
436
|
480
|
|
|
@@ -439,6 +483,6 @@ module:provides("http", {
|
439
|
483
|
default_path = "/";
|
440
|
484
|
name = "jibriqueue";
|
441
|
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
|
});
|