Просмотр исходного кода

Sends endpoint information in COLIBRI messages (in 'endpoint' children

of 'conference').
j8
Boris Grozev 11 лет назад
Родитель
Сommit
256694b966
2 измененных файлов: 100 добавлений и 1 удалений
  1. 16
    0
      app.js
  2. 84
    1
      libs/colibri/colibri.focus.js

+ 16
- 0
app.js Просмотреть файл

@@ -632,6 +632,10 @@ $(document).bind('joined.muc', function (event, jid, info) {
632 632
 
633 633
     if (Object.keys(connection.emuc.members).length < 1) {
634 634
         focus = new ColibriFocus(connection, config.hosts.bridge);
635
+        if (nickname !== null) {
636
+            focus.setEndpointDisplayName(connection.emuc.myroomjid,
637
+                                         nickname);
638
+        }
635 639
         showRecordingButton(false);
636 640
     }
637 641
 
@@ -710,6 +714,10 @@ $(document).bind('left.muc', function (event, jid) {
710 714
             && !sessionTerminated) {
711 715
         console.log('welcome to our new focus... myself');
712 716
         focus = new ColibriFocus(connection, config.hosts.bridge);
717
+        if (nickname !== null) {
718
+            focus.setEndpointDisplayName(connection.emuc.myroomjid,
719
+                                         nickname);
720
+        }
713 721
 
714 722
         if (Object.keys(connection.emuc.members).length > 0) {
715 723
             focus.makeConference(Object.keys(connection.emuc.members));
@@ -723,6 +731,10 @@ $(document).bind('left.muc', function (event, jid) {
723 731
         // problems with reinit
724 732
         disposeConference();
725 733
         focus = new ColibriFocus(connection, config.hosts.bridge);
734
+        if (nickname !== null) {
735
+            focus.setEndpointDisplayName(connection.emuc.myroomjid,
736
+                                         nickname);
737
+        }
726 738
         showRecordingButton(false);
727 739
     }
728 740
     if (connection.emuc.getPrezi(jid)) {
@@ -776,6 +788,10 @@ $(document).bind('presence.muc', function (event, jid, info, pres) {
776 788
                 'participant_' + Strophe.getResourceFromJid(jid),
777 789
                 info.displayName);
778 790
     }
791
+
792
+    if (focus !== null && info.displayName !== null) {
793
+        focus.setEndpointDisplayName(jid, info.displayName);
794
+    }
779 795
 });
780 796
 
781 797
 $(document).bind('passwordrequired.muc', function (event, jid) {

+ 84
- 1
libs/colibri/colibri.focus.js Просмотреть файл

@@ -84,6 +84,10 @@ function ColibriFocus(connection, bridgejid) {
84 84
     this.wait = true;
85 85
 
86 86
     this.recordingEnabled = false;
87
+
88
+    // stores information about the endpoints (i.e. display names) to
89
+    // be sent to the videobridge.
90
+    this.endpointsInfo = null;
87 91
 }
88 92
 
89 93
 // creates a conferences with an initial set of peers
@@ -176,7 +180,7 @@ ColibriFocus.prototype.makeConference = function (peers) {
176 180
 // the new recording state, according to the IQ.
177 181
 ColibriFocus.prototype.setRecording = function(state, token, callback) {
178 182
     var self = this;
179
-    var elem = $iq({to: this.bridgejid, type: 'get'});
183
+    var elem = $iq({to: this.bridgejid, type: 'set'});
180 184
     elem.c('conference', {
181 185
         xmlns: 'http://jitsi.org/protocol/colibri',
182 186
         id: this.confid
@@ -199,6 +203,74 @@ ColibriFocus.prototype.setRecording = function(state, token, callback) {
199 203
     );
200 204
 };
201 205
 
206
+/*
207
+ * Updates the display name for an endpoint with a specific jid.
208
+ * jid: the jid associated with the endpoint.
209
+ * displayName: the new display name for the endpoint.
210
+ */
211
+ColibriFocus.prototype.setEndpointDisplayName = function(jid, displayName) {
212
+    var endpointId = jid.substr(1 + jid.lastIndexOf('/'));
213
+    var update = false;
214
+
215
+    if (this.endpointsInfo === null) {
216
+       this.endpointsInfo = {};
217
+    }
218
+
219
+    var endpointInfo = this.endpointsInfo[endpointId];
220
+    if ('undefined' === typeof endpointInfo) {
221
+        endpointInfo = this.endpointsInfo[endpointId] = {};
222
+    }
223
+
224
+    if (endpointInfo['displayname'] !== displayName) {
225
+        endpointInfo['displayname'] = displayName;
226
+        update = true;
227
+    }
228
+
229
+    if (update) {
230
+        this.updateEndpoints();
231
+    }
232
+};
233
+
234
+/*
235
+ * Sends a colibri message to the bridge that contains the
236
+ * current endpoints and their display names.
237
+ */
238
+ColibriFocus.prototype.updateEndpoints = function() {
239
+    if (this.confid === null
240
+        || this.endpointsInfo === null) {
241
+        return;
242
+    }
243
+
244
+    if (this.confid === 0) {
245
+        // the colibri conference is currently initiating
246
+        var self = this;
247
+        window.setTimeout(function() { self.updateEndpoints()}, 1000);
248
+        return;
249
+    }
250
+
251
+    var elem = $iq({to: this.bridgejid, type: 'set'});
252
+    elem.c('conference', {
253
+        xmlns: 'http://jitsi.org/protocol/colibri',
254
+        id: this.confid
255
+    });
256
+
257
+    for (var id in this.endpointsInfo) {
258
+        elem.c('endpoint');
259
+        elem.attrs({ id: id,
260
+                     displayname: this.endpointsInfo[id]['displayname']
261
+        });
262
+        elem.up();
263
+    }
264
+
265
+    //elem.up(); //conference
266
+
267
+    this.connection.sendIQ(
268
+        elem,
269
+        function (result) {},
270
+        function (error) { console.warn(error); }
271
+    );
272
+};
273
+
202 274
 ColibriFocus.prototype._makeConference = function () {
203 275
     var self = this;
204 276
     var elem = $iq({ to: this.bridgejid, type: 'get' });
@@ -235,6 +307,17 @@ ColibriFocus.prototype._makeConference = function () {
235 307
         }
236 308
         elem.up(); // end of content
237 309
     });
310
+
311
+    if (this.endpointsInfo !== null) {
312
+        for (var id in this.endpointsInfo) {
313
+            elem.c('endpoint');
314
+            elem.attrs({ id: id,
315
+                         displayname: this.endpointsInfo[id]['displayname']
316
+            });
317
+            elem.up();
318
+        }
319
+    }
320
+
238 321
     /*
239 322
     var localSDP = new SDP(this.peerconnection.localDescription.sdp);
240 323
     localSDP.media.forEach(function (media, channel) {

Загрузка…
Отмена
Сохранить