Explorar el Código

Properly propagating call id for call response handling.

Previously a new call id was generated for INVITE and CANCEL.
Now the id generated during the initial INVITE will be used for
corresponding CANCEL events. Also, adding the ability to
trigger a call cancel via the poltergeist update api.
master
Jacob MacElroy hace 7 años
padre
commit
e367490839

+ 17
- 5
resources/prosody-plugins/mod_muc_call.lua Ver fichero

67
 	   return
67
 	   return
68
     end
68
     end
69
 
69
 
70
-	local invite = function()
71
-		 local url = assert(url_from_room_jid(event.stanza.attr.from))
72
-		 ext_events.invite(event.stanza, url)
70
+	local call_id = event.stanza:get_child_text("call_id")
71
+	if not call_id then
72
+	   module:log("info", "A call id was not provided in the status.")
73
+	   return
74
+	end
75
+
76
+    local invite = function()
77
+	    local url = assert(url_from_room_jid(event.stanza.attr.from))
78
+		ext_events.invite(event.stanza, url, call_id)
73
 	end
79
 	end
74
 
80
 
75
-	local cancel = function()
81
+    local cancel = function()
76
 	   local url = assert(url_from_room_jid(event.stanza.attr.from))
82
 	   local url = assert(url_from_room_jid(event.stanza.attr.from))
77
 	   local status = event.stanza:get_child_text("status")
83
 	   local status = event.stanza:get_child_text("status")
78
-	   ext_events.cancel(event.stanza, url, string.lower(status))
84
+	   ext_events.cancel(event.stanza, url, string.lower(status), call_id)
79
 	end
85
 	end
80
 
86
 
87
+    local should_cancel = event.stanza:get_child_text("call_cancel")
88
+    if should_cancel == "true" then
89
+        cancel()
90
+        return
91
+    end
92
+
81
 	local switch = function(status)
93
 	local switch = function(status)
82
 	   case = {
94
 	   case = {
83
 		  [calling_status]   = function() invite() end,
95
 		  [calling_status]   = function() invite() end,

+ 83
- 31
resources/prosody-plugins/mod_muc_poltergeist.lua Ver fichero

108
     end
108
     end
109
 end
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
 --- Verifies room name, domain name with the values in the token
132
 --- Verifies room name, domain name with the values in the token
112
 -- @param token the token we received
133
 -- @param token the token we received
113
 -- @param room_name the room name
134
 -- @param room_name the room name
182
         if (have_poltergeist_occupant(room, nick)) then
203
         if (have_poltergeist_occupant(room, nick)) then
183
             -- notify that user connected using the poltergeist
204
             -- notify that user connected using the poltergeist
184
             update_poltergeist_occupant_status(
205
             update_poltergeist_occupant_status(
185
-                room, nick, "connected");
206
+			   room, nick, "connected");
186
             remove_poltergeist_occupant(room, nick, true);
207
             remove_poltergeist_occupant(room, nick, true);
187
         end
208
         end
188
 
209
 
202
 function create_poltergeist_occupant(room, nick, name, avatar, status, context)
223
 function create_poltergeist_occupant(room, nick, name, avatar, status, context)
203
     log("debug", "create_poltergeist_occupant %s", nick);
224
     log("debug", "create_poltergeist_occupant %s", nick);
204
     -- Join poltergeist occupant to room, with the invited JID as their nick
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
     if (name) then
228
     if (name) then
211
         join_presence:tag(
229
         join_presence:tag(
215
     if (avatar) then
233
     if (avatar) then
216
         join_presence:tag("avatar-url"):text(avatar):up();
234
         join_presence:tag("avatar-url"):text(avatar):up();
217
     end
235
     end
218
-    if (status) then
219
-        join_presence:tag("status"):text(status):up();
220
-    end
221
 
236
 
222
     -- If the room has a password set, let the poltergeist enter using it
237
     -- If the room has a password set, let the poltergeist enter using it
223
     local room_password = room:get_password();
238
     local room_password = room:get_password();
226
         join:tag("password", { xmlns = MUC_NS }):text(room_password);
241
         join:tag("password", { xmlns = MUC_NS }):text(room_password);
227
     end
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
     update_presence_identity(
247
     update_presence_identity(
230
         join_presence,
248
         join_presence,
231
         context.user,
249
         context.user,
278
 -- @param room the room instance where to remove the occupant
296
 -- @param room the room instance where to remove the occupant
279
 -- @param nick the nick of the occupant to remove
297
 -- @param nick the nick of the occupant to remove
280
 -- @param status the status to update
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
     local update_presence = get_presence(room, nick);
301
     local update_presence = get_presence(room, nick);
283
 
302
 
284
     if (not update_presence) then
303
     if (not update_presence) then
285
         -- no presence found for occupant, create one
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
     else
306
     else
291
         -- update occupant presence with appropriate to and from
307
         -- update occupant presence with appropriate to and from
292
         -- so we can send it again
308
         -- so we can send it again
295
         update_presence.attr.from = poltergeist_component.."/"..nick;
311
         update_presence.attr.from = poltergeist_component.."/"..nick;
296
     end
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
             else
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
             end
357
             end
311
         end
358
         end
312
-        return tag;
313
     end);
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
 end
362
 end
322
 
363
 
323
 -- Checks for existance of a poltergeist occupant
364
 -- Checks for existance of a poltergeist occupant
436
     local room_name = params["room"];
477
     local room_name = params["room"];
437
     local group = params["group"];
478
     local group = params["group"];
438
     local status = params["status"];
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
     if not verify_token(params["token"], room_name, group, {}) then
487
     if not verify_token(params["token"], room_name, group, {}) then
441
         return 403;
488
         return 403;
452
         return 404;
499
         return 404;
453
     end
500
     end
454
 
501
 
502
+	local call_details = {
503
+	   ["cancel"] = call_cancel;
504
+	   ["id"] = call_id;
505
+	};
506
+
455
     local nick = string.sub(username, 0, 8);
507
     local nick = string.sub(username, 0, 8);
456
     if (have_poltergeist_occupant(room, nick)) then
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
         return 200;
510
         return 200;
459
     else
511
     else
460
         return 404;
512
         return 404;

Loading…
Cancelar
Guardar