Browse Source

fix issues after rebase

master
isymchych 10 years ago
parent
commit
a22393676d
2 changed files with 404 additions and 433 deletions
  1. 56
    119
      JitsiConference.js
  2. 348
    314
      lib-jitsi-meet.js

+ 56
- 119
JitsiConference.js View File

@@ -3,13 +3,13 @@
3 3
 var logger = require("jitsi-meet-logger").getLogger(__filename);
4 4
 var RTC = require("./modules/RTC/RTC");
5 5
 var XMPPEvents = require("./service/xmpp/XMPPEvents");
6
+var StreamEventTypes = require("./service/RTC/StreamEventTypes");
6 7
 var RTCEvents = require("./service/RTC/RTCEvents");
7 8
 var EventEmitter = require("events");
8 9
 var JitsiConferenceEvents = require("./JitsiConferenceEvents");
9 10
 var JitsiParticipant = require("./JitsiParticipant");
10 11
 var Statistics = require("./modules/statistics/statistics");
11 12
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
12
-var JitsiTrackEvents = require("./JitsiTrackEvents");
13 13
 
14 14
 /**
15 15
  * Creates a JitsiConference object with the given name and properties.
@@ -33,7 +33,7 @@ function JitsiConference(options) {
33 33
     this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
34 34
     this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
35 35
     this.rtc = new RTC(this.room, options);
36
-    if(!RTC.options.disableAudioLevels)
36
+    if(!options.config.disableAudioLevels)
37 37
         this.statistics = new Statistics();
38 38
     setupListeners(this);
39 39
     this.participants = {};
@@ -102,8 +102,7 @@ JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
102 102
 JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
103 103
 
104 104
 /**
105
- * Receives notifications from another participants for commands / custom events
106
- * (send by sendPresenceCommand method).
105
+ * Receives notifications from another participants for commands / custom events(send by sendPresenceCommand method).
107 106
  * @param command {String} the name of the command
108 107
  * @param handler {Function} handler for the command
109 108
  */
@@ -169,7 +168,11 @@ JitsiConference.prototype.removeCommand = function (name) {
169 168
  */
170 169
 JitsiConference.prototype.setDisplayName = function(name) {
171 170
     if(this.room){
172
-        this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
171
+        this.room.addToPresence("nick", {
172
+            attributes: {
173
+                xmlns: 'http://jabber.org/protocol/nick'
174
+            }, value: name
175
+        });
173 176
         this.room.sendPresence();
174 177
     }
175 178
 };
@@ -179,42 +182,8 @@ JitsiConference.prototype.setDisplayName = function(name) {
179 182
  * @param track the JitsiLocalTrack object.
180 183
  */
181 184
 JitsiConference.prototype.addTrack = function (track) {
182
-    this.room.addStream(track.getOriginalStream(), function () {
183
-        this.rtc.addLocalStream(track);
184
-        var muteHandler = this._fireMuteChangeEvent.bind(this, track);
185
-        var stopHandler = this.removeTrack.bind(this, track);
186
-        var audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
187
-        track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
188
-        track.addEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
189
-        track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
190
-        this.addEventListener(JitsiConferenceEvents.TRACK_REMOVED, function (someTrack) {
191
-            if (someTrack !== track) {
192
-                return;
193
-            }
194
-            track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
195
-            track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
196
-            track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
197
-        });
198
-        this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
199
-    }.bind(this));
200
-};
201
-
202
-/**
203
- * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
204
- * @param audioLevel the audio level
205
- */
206
-JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
207
-    this.eventEmitter.emit(
208
-        JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
209
-        this.myUserId(), audioLevel);
210
-};
211
-
212
-/**
213
- * Fires TRACK_MUTE_CHANGED change conference event.
214
- * @param track the JitsiTrack object related to the event.
215
- */
216
-JitsiConference.prototype._fireMuteChangeEvent = function (track) {
217
-    this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
185
+    this.rtc.addLocalStream(track);
186
+    this.room.addStream(track.getOriginalStream(), function () {});
218 187
 };
219 188
 
220 189
 /**
@@ -222,26 +191,8 @@ JitsiConference.prototype._fireMuteChangeEvent = function (track) {
222 191
  * @param track the JitsiLocalTrack object.
223 192
  */
224 193
 JitsiConference.prototype.removeTrack = function (track) {
225
-    this.room.removeStream(track.getOriginalStream(), function(){
226
-        this.rtc.removeLocalStream(track);
227
-        this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
228
-    }.bind(this));
229
-};
230
-
231
-/**
232
- * Get role of the local user.
233
- * @returns {string} user role: 'moderator' or 'none'
234
- */
235
-JitsiConference.prototype.getRole = function () {
236
-    return this.room.role;
237
-};
238
-
239
-/**
240
- * Check if local user is moderator.
241
- * @returns {boolean} true if local user is moderator, false otherwise.
242
- */
243
-JitsiConference.prototype.isModerator = function () {
244
-    return this.room.isModerator();
194
+    this.room.removeStream(track.getOriginalStream());
195
+    this.rtc.removeLocalStream(track);
245 196
 };
246 197
 
247 198
 /**
@@ -302,16 +253,6 @@ JitsiConference.prototype.onMemberLeft = function (jid) {
302 253
     this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id);
303 254
 };
304 255
 
305
-JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
306
-    var id = Strophe.getResourceFromJid(jid);
307
-    var participant = this.getParticipantById(id);
308
-    if (!participant) {
309
-        return;
310
-    }
311
-    participant._role = role;
312
-    this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
313
-};
314
-
315 256
 JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
316 257
     var id = Strophe.getResourceFromJid(jid);
317 258
     var participant = this.getParticipantById(id);
@@ -322,43 +263,24 @@ JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
322 263
     this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
323 264
 };
324 265
 
266
+
325 267
 JitsiConference.prototype.onTrackAdded = function (track) {
326 268
     var id = track.getParticipantId();
327 269
     var participant = this.getParticipantById(id);
328
-    if (!participant) {
329
-        return;
330
-    }
331
-    // add track to JitsiParticipant
332 270
     participant._tracks.push(track);
333
-
334
-    var emitter = this.eventEmitter;
335
-    track.addEventListener(
336
-        JitsiTrackEvents.TRACK_STOPPED,
337
-        function () {
338
-            // remove track from JitsiParticipant
339
-            var pos = participant._tracks.indexOf(track);
340
-            if (pos > -1) {
341
-                participant._tracks.splice(pos, 1);
342
-            }
343
-            emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
344
-        }
345
-    );
346
-    track.addEventListener(
347
-        JitsiTrackEvents.TRACK_MUTE_CHANGED,
348
-        function () {
349
-            emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
350
-        }
351
-    );
352
-    track.addEventListener(
353
-        JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
354
-        function (audioLevel) {
355
-            emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
356
-        }
357
-    );
358
-
359 271
     this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
360 272
 };
361 273
 
274
+JitsiConference.prototype.onTrackRemoved = function (track) {
275
+    var id = track.getParticipantId();
276
+    var participant = this.getParticipantById(id);
277
+    var pos = participant._tracks.indexOf(track);
278
+    if (pos > -1) {
279
+        participant._tracks.splice(pos, 1);
280
+    }
281
+    this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
282
+};
283
+
362 284
 JitsiConference.prototype.updateDTMFSupport = function () {
363 285
     var somebodySupportsDTMF = false;
364 286
     var participants = this.getParticipants();
@@ -424,15 +346,8 @@ function setupListeners(conference) {
424 346
         if(conference.statistics)
425 347
             conference.statistics.startRemoteStats(event.peerconnection);
426 348
     });
427
-
428 349
     conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
429
-        function (data, sid, thessrc) {
430
-            var track = conference.rtc.createRemoteStream(data, sid, thessrc);
431
-            if (track) {
432
-                conference.onTrackAdded(track);
433
-            }
434
-        }
435
-    );
350
+        conference.rtc.createRemoteStream.bind(conference.rtc));
436 351
 
437 352
     conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
438 353
         conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
@@ -447,11 +362,6 @@ function setupListeners(conference) {
447 362
 
448 363
     conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
449 364
 
450
-    conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
451
-        conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
452
-    });
453
-    conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
454
-
455 365
     conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
456 366
         conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
457 367
     });
@@ -463,6 +373,24 @@ function setupListeners(conference) {
463 373
         conference.eventEmitter.emit(JitsiConferenceEvents.SETUP_FAILED);
464 374
     });
465 375
 
376
+    conference.rtc.addListener(
377
+        StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, conference.onTrackAdded.bind(conference)
378
+    );
379
+
380
+//FIXME: Maybe remove event should not be associated with the conference.
381
+    conference.rtc.addListener(
382
+        StreamEventTypes.EVENT_TYPE_REMOTE_ENDED, conference.onTrackRemoved.bind(conference)
383
+    );
384
+//FIXME: Maybe remove event should not be associated with the conference.
385
+    conference.rtc.addListener(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, function (stream) {
386
+        conference.removeTrack(stream);
387
+        conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, stream);
388
+    });
389
+
390
+    conference.rtc.addListener(StreamEventTypes.TRACK_MUTE_CHANGED, function (track) {
391
+        conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
392
+    });
393
+
466 394
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
467 395
         if(conference.lastActiveSpeaker !== id && conference.room) {
468 396
             conference.lastActiveSpeaker = id;
@@ -484,11 +412,20 @@ function setupListeners(conference) {
484 412
         //FIXME: Maybe remove event should not be associated with the conference.
485 413
         conference.statistics.addAudioLevelListener(function (ssrc, level) {
486 414
             var userId = null;
487
-            var jid = conference.room.getJidBySSRC(ssrc);
488
-            if (!jid)
489
-                return;
490
-
491
-            conference.rtc.setAudioLevel(jid, level);
415
+            if (ssrc === Statistics.LOCAL_JID) {
416
+                userId = conference.myUserId();
417
+            } else {
418
+                var jid = conference.room.getJidBySSRC(ssrc);
419
+                if (!jid)
420
+                    return;
421
+
422
+                userId = Strophe.getResourceFromJid(jid);
423
+            }
424
+            conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
425
+                userId, level);
426
+        });
427
+        conference.rtc.addListener(StreamEventTypes.EVENT_TYPE_LOCAL_CREATED, function (stream) {
428
+            conference.statistics.startLocalStats(stream);
492 429
         });
493 430
         conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
494 431
             function () {

+ 348
- 314
lib-jitsi-meet.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save