|
@@ -108,6 +108,27 @@ function remove_username(room, nick)
|
108
|
108
|
end
|
109
|
109
|
end
|
110
|
110
|
|
|
111
|
+-- Provides a new presence stanza for a poltergeist.
|
|
112
|
+-- @param room the room instance
|
|
113
|
+-- @param nick the user nick
|
|
114
|
+function generate_poltergeist_presence(room, nick, status)
|
|
115
|
+ local presence_stanza = st.presence({
|
|
116
|
+ to = room.jid.."/"..nick,
|
|
117
|
+ from = poltergeist_component.."/"..nick,
|
|
118
|
+ }):tag("x", { xmlns = MUC_NS }):up();
|
|
119
|
+
|
|
120
|
+ presence_stanza:tag("call_cancel"):text(nil):up();
|
|
121
|
+ presence_stanza:tag("call_id"):text(nil):up();
|
|
122
|
+
|
|
123
|
+ if status then
|
|
124
|
+ presence_stanza:tag("status"):text(status):up();
|
|
125
|
+ else
|
|
126
|
+ presence_stanza:tag("status"):text(nil):up();
|
|
127
|
+ end
|
|
128
|
+
|
|
129
|
+ return presence_stanza;
|
|
130
|
+end
|
|
131
|
+
|
111
|
132
|
--- Verifies room name, domain name with the values in the token
|
112
|
133
|
-- @param token the token we received
|
113
|
134
|
-- @param room_name the room name
|
|
@@ -182,7 +203,7 @@ prosody.events.add_handler("pre-jitsi-authentication", function(session)
|
182
|
203
|
if (have_poltergeist_occupant(room, nick)) then
|
183
|
204
|
-- notify that user connected using the poltergeist
|
184
|
205
|
update_poltergeist_occupant_status(
|
185
|
|
- room, nick, "connected");
|
|
206
|
+ room, nick, "connected");
|
186
|
207
|
remove_poltergeist_occupant(room, nick, true);
|
187
|
208
|
end
|
188
|
209
|
|
|
@@ -202,10 +223,7 @@ end);
|
202
|
223
|
function create_poltergeist_occupant(room, nick, name, avatar, status, context)
|
203
|
224
|
log("debug", "create_poltergeist_occupant %s", nick);
|
204
|
225
|
-- Join poltergeist occupant to room, with the invited JID as their nick
|
205
|
|
- local join_presence = st.presence({
|
206
|
|
- to = room.jid.."/"..nick,
|
207
|
|
- from = poltergeist_component.."/"..nick
|
208
|
|
- }):tag("x", { xmlns = MUC_NS }):up();
|
|
226
|
+ local join_presence = generate_poltergeist_presence(room, nick, status)
|
209
|
227
|
|
210
|
228
|
if (name) then
|
211
|
229
|
join_presence:tag(
|
|
@@ -215,9 +233,6 @@ function create_poltergeist_occupant(room, nick, name, avatar, status, context)
|
215
|
233
|
if (avatar) then
|
216
|
234
|
join_presence:tag("avatar-url"):text(avatar):up();
|
217
|
235
|
end
|
218
|
|
- if (status) then
|
219
|
|
- join_presence:tag("status"):text(status):up();
|
220
|
|
- end
|
221
|
236
|
|
222
|
237
|
-- If the room has a password set, let the poltergeist enter using it
|
223
|
238
|
local room_password = room:get_password();
|
|
@@ -226,6 +241,9 @@ function create_poltergeist_occupant(room, nick, name, avatar, status, context)
|
226
|
241
|
join:tag("password", { xmlns = MUC_NS }):text(room_password);
|
227
|
242
|
end
|
228
|
243
|
|
|
244
|
+ local call_id = get_username(room, context.user.id);
|
|
245
|
+ join_presence:tag("call_id"):text(get_username(room, context.user.id)):up();
|
|
246
|
+
|
229
|
247
|
update_presence_identity(
|
230
|
248
|
join_presence,
|
231
|
249
|
context.user,
|
|
@@ -278,15 +296,13 @@ end
|
278
|
296
|
-- @param room the room instance where to remove the occupant
|
279
|
297
|
-- @param nick the nick of the occupant to remove
|
280
|
298
|
-- @param status the status to update
|
281
|
|
-function update_poltergeist_occupant_status(room, nick, status)
|
|
299
|
+-- @param call_details is a table of call flow details
|
|
300
|
+function update_poltergeist_occupant_status(room, nick, status, call_details)
|
282
|
301
|
local update_presence = get_presence(room, nick);
|
283
|
302
|
|
284
|
303
|
if (not update_presence) then
|
285
|
304
|
-- no presence found for occupant, create one
|
286
|
|
- update_presence = st.presence({
|
287
|
|
- to = room.jid.."/"..nick,
|
288
|
|
- from = poltergeist_component.."/"..nick
|
289
|
|
- });
|
|
305
|
+ update_presence = generate_poltergeist_presence(room, nick)
|
290
|
306
|
else
|
291
|
307
|
-- update occupant presence with appropriate to and from
|
292
|
308
|
-- so we can send it again
|
|
@@ -295,29 +311,54 @@ function update_poltergeist_occupant_status(room, nick, status)
|
295
|
311
|
update_presence.attr.from = poltergeist_component.."/"..nick;
|
296
|
312
|
end
|
297
|
313
|
|
298
|
|
- local once = false;
|
299
|
|
- -- the status tag we will attach
|
300
|
|
- local statusTag = st.stanza("status"):text(status);
|
|
314
|
+ update_presence = update_presence_tags(update_presence, status, call_details)
|
301
|
315
|
|
302
|
|
- -- if there is already a status tag replace it
|
303
|
|
- update_presence:maptags(function (tag)
|
304
|
|
- if tag.name == statusTag.name then
|
305
|
|
- if not once then
|
306
|
|
- once = true;
|
307
|
|
- return statusTag;
|
|
316
|
+ room:handle_normal_presence(
|
|
317
|
+ prosody.hosts[poltergeist_component], update_presence);
|
|
318
|
+end
|
|
319
|
+
|
|
320
|
+-- Updates the status tags and call flow tags of an existing poltergeist's
|
|
321
|
+-- presence.
|
|
322
|
+-- @param presence_stanza is the actual presence stanza for a poltergeist.
|
|
323
|
+-- @param status is the new status to be updated in the stanza.
|
|
324
|
+-- @param call_details is a table of call flow signal information.
|
|
325
|
+function update_presence_tags(presence_stanza, status, call_details)
|
|
326
|
+ local call_cancel = false;
|
|
327
|
+ local call_id = nil;
|
|
328
|
+
|
|
329
|
+ -- Extract optional call flow signal information.
|
|
330
|
+ if call_details then
|
|
331
|
+ call_id = call_details["id"];
|
|
332
|
+
|
|
333
|
+ if call_details["cancel"] then
|
|
334
|
+ call_cancel = call_details["cancel"];
|
|
335
|
+ end
|
|
336
|
+ end
|
|
337
|
+
|
|
338
|
+ presence_stanza:maptags(function (tag)
|
|
339
|
+ if tag.name == "status" then
|
|
340
|
+ if call_cancel then
|
|
341
|
+ -- If call cancel is set then the status should not be changed.
|
|
342
|
+ return tag
|
|
343
|
+ end
|
|
344
|
+ return st.stanza("status"):text(status);
|
|
345
|
+ elseif tag.name == "call_id" then
|
|
346
|
+ if call_id then
|
|
347
|
+ return st.stanza("call_id"):text(call_id);
|
308
|
348
|
else
|
309
|
|
- return nil;
|
|
349
|
+ -- If no call id is provided the re-use the existing id.
|
|
350
|
+ return tag;
|
|
351
|
+ end
|
|
352
|
+ elseif tag.name == "call_cancel" then
|
|
353
|
+ if call_cancel then
|
|
354
|
+ return st.stanza("call_cancel"):text("true");
|
|
355
|
+ else
|
|
356
|
+ return st.stanza("call_cancel"):text("false");
|
310
|
357
|
end
|
311
|
358
|
end
|
312
|
|
- return tag;
|
313
|
359
|
end);
|
314
|
|
- if (not once) then
|
315
|
|
- -- no status tag was repleced, attach it
|
316
|
|
- update_presence:add_child(statusTag);
|
317
|
|
- end
|
318
|
360
|
|
319
|
|
- room:handle_normal_presence(
|
320
|
|
- prosody.hosts[poltergeist_component], update_presence);
|
|
361
|
+ return presence_stanza
|
321
|
362
|
end
|
322
|
363
|
|
323
|
364
|
-- Checks for existance of a poltergeist occupant
|
|
@@ -436,6 +477,12 @@ function handle_update_poltergeist (event)
|
436
|
477
|
local room_name = params["room"];
|
437
|
478
|
local group = params["group"];
|
438
|
479
|
local status = params["status"];
|
|
480
|
+ local call_id = params["callid"];
|
|
481
|
+
|
|
482
|
+ local call_cancel = false
|
|
483
|
+ if params["callcancel"] == "true" then
|
|
484
|
+ call_cancel = true;
|
|
485
|
+ end
|
439
|
486
|
|
440
|
487
|
if not verify_token(params["token"], room_name, group, {}) then
|
441
|
488
|
return 403;
|
|
@@ -452,9 +499,14 @@ function handle_update_poltergeist (event)
|
452
|
499
|
return 404;
|
453
|
500
|
end
|
454
|
501
|
|
|
502
|
+ local call_details = {
|
|
503
|
+ ["cancel"] = call_cancel;
|
|
504
|
+ ["id"] = call_id;
|
|
505
|
+ };
|
|
506
|
+
|
455
|
507
|
local nick = string.sub(username, 0, 8);
|
456
|
508
|
if (have_poltergeist_occupant(room, nick)) then
|
457
|
|
- update_poltergeist_occupant_status(room, nick, status);
|
|
509
|
+ update_poltergeist_occupant_status(room, nick, status, call_details);
|
458
|
510
|
return 200;
|
459
|
511
|
else
|
460
|
512
|
return 404;
|