Browse Source

ref(RTC): cleanup local track access

master
paweldomas 8 years ago
parent
commit
3b59cdb080

+ 35
- 23
JitsiConference.js View File

@@ -262,17 +262,27 @@ JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
262 262
 JitsiConference.prototype.getLocalTracks = function (mediaType) {
263 263
     let tracks = [];
264 264
     if (this.rtc) {
265
-        tracks = this.rtc.localTracks.slice();
266
-    }
267
-    if (mediaType !== undefined) {
268
-        tracks = tracks.filter(
269
-            (track) => {
270
-                return track && track.getType && track.getType() === mediaType;
271
-            });
265
+        tracks = this.rtc.getLocalTracks(mediaType);
272 266
     }
273 267
     return tracks;
274 268
 };
275 269
 
270
+/**
271
+ * Obtains local audio track.
272
+ * @return {JitsiLocalTrack|null}
273
+ */
274
+JitsiConference.prototype.getLocalAudioTrack = function () {
275
+    return this.rtc ? this.rtc.getLocalAudioTrack() : null;
276
+};
277
+
278
+/**
279
+ * Obtains local video track.
280
+ * @return {JitsiLocalTrack|null}
281
+ */
282
+JitsiConference.prototype.getLocalVideoTrack = function () {
283
+    return this.rtc ? this.rtc.getLocalVideoTrack() : null;
284
+};
285
+
276 286
 /**
277 287
  * Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
278 288
  * in JitsiConferenceEvents.
@@ -394,12 +404,10 @@ JitsiConference.prototype.getTranscriber = function(){
394 404
     if (this.transcriber === undefined){
395 405
         this.transcriber = new Transcriber();
396 406
         //add all existing local audio tracks to the transcriber
397
-        // FIXME accessing localTracks field directly
398
-        this.rtc.localTracks.forEach(function (localTrack) {
399
-            if (localTrack.isAudioTrack()){
400
-                this.transcriber.addTrack(localTrack);
401
-            }
402
-        }.bind(this));
407
+        const localAudioTracks = this.getLocalTracks(MediaType.AUDIO);
408
+        for (const localAudio of localAudioTracks) {
409
+            this.transcriber.addTrack(localAudio);
410
+        }
403 411
         //and all remote audio tracks
404 412
         const remoteAudioTracks = this.rtc.getRemoteTracks(MediaType.AUDIO);
405 413
         for (const remoteTrack of remoteAudioTracks){
@@ -1028,7 +1036,7 @@ function (jingleSession, jingleOffer, now) {
1028 1036
 
1029 1037
     this.rtc.initializeDataChannels(jingleSession.peerconnection);
1030 1038
     // Add local Tracks to the ChatRoom
1031
-    this.rtc.localTracks.forEach(function(localTrack) {
1039
+    this.getLocalTracks().forEach(function(localTrack) {
1032 1040
         var ssrcInfo = null;
1033 1041
         /**
1034 1042
          * We don't do this for Firefox because, on Firefox, we keep the
@@ -1124,7 +1132,7 @@ JitsiConference.prototype.onCallEnded
1124 1132
     // will learn what their SSRC from the new PeerConnection which will be
1125 1133
     // created on incoming call event.
1126 1134
     var self = this;
1127
-    this.rtc.localTracks.forEach(function(localTrack) {
1135
+    this.getLocalTracks().forEach(function(localTrack) {
1128 1136
         // Reset SSRC as it will no longer be valid
1129 1137
         localTrack._setSSRC(null);
1130 1138
         // Bind the handler to fetch new SSRC, it will un register itself once
@@ -1177,21 +1185,25 @@ JitsiConference.prototype.myUserId = function () {
1177 1185
 };
1178 1186
 
1179 1187
 JitsiConference.prototype.sendTones = function (tones, duration, pause) {
1188
+    // FIXME P2P 'dtmfManager' must be cleared, after switching jingleSessions
1180 1189
     if (!this.dtmfManager) {
1181
-        var connection = this.xmpp.connection.jingle.activecall.peerconnection;
1182
-        if (!connection) {
1183
-            logger.warn("cannot sendTones: no conneciton");
1190
+        if (!this.jingleSession) {
1191
+            logger.warn("cannot sendTones: no jingle session");
1184 1192
             return;
1185 1193
         }
1186 1194
 
1187
-        var tracks = this.getLocalTracks().filter(function (track) {
1188
-            return track.isAudioTrack();
1189
-        });
1190
-        if (!tracks.length) {
1195
+        const peerConnection = this.jingleSession.peerconnection;
1196
+        if (!peerConnection) {
1197
+            logger.warn("cannot sendTones: no peer connection");
1198
+            return;
1199
+        }
1200
+
1201
+        const localAudio = this.getLocalAudioTrack();
1202
+        if (!localAudio) {
1191 1203
             logger.warn("cannot sendTones: no local audio stream");
1192 1204
             return;
1193 1205
         }
1194
-        this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
1206
+        this.dtmfManager = new JitsiDTMFManager(localAudio, peerConnection);
1195 1207
     }
1196 1208
 
1197 1209
     this.dtmfManager.sendTones(tones, duration, pause);

+ 3
- 3
JitsiConferenceEventManager.js View File

@@ -573,9 +573,9 @@ JitsiConferenceEventManager.prototype.setupStatisticsListeners = function () {
573 573
     });
574 574
 
575 575
     conference.statistics.addByteSentStatsListener(function (stats) {
576
-        conference.getLocalTracks().forEach(function (track) {
577
-            var ssrc = track.getSSRC();
578
-            if(!track.isAudioTrack() || !ssrc || !stats.hasOwnProperty(ssrc))
576
+        conference.getLocalTracks(MediaType.AUDIO).forEach(function (track) {
577
+            const ssrc = track.getSSRC();
578
+            if (!ssrc || !stats.hasOwnProperty(ssrc))
579 579
                 return;
580 580
 
581 581
             track._setByteSent(stats[ssrc]);

+ 0
- 9
modules/RTC/JitsiTrack.js View File

@@ -308,15 +308,6 @@ JitsiTrack.prototype.dispose = function () {
308 308
 JitsiTrack.prototype.isScreenSharing = function() {
309 309
 };
310 310
 
311
-/**
312
- * FIXME remove hack in SDP.js and this method
313
- * Returns id of the track.
314
- * @returns {string|null} id of the track or null if this is fake track.
315
- */
316
-JitsiTrack.prototype._getId = function () {
317
-    return this.getTrackId();
318
-};
319
-
320 311
 /**
321 312
  * Returns id of the track.
322 313
  * @returns {string|null} id of the track or null if this is fake track.

+ 36
- 29
modules/RTC/RTC.js View File

@@ -55,8 +55,6 @@ export default class RTC extends Listenable {
55 55
         this.localTracks = [];
56 56
         //FIXME: We should support multiple streams per jid.
57 57
         this.remoteTracks = {};
58
-        this.localAudio = null;
59
-        this.localVideo = null;
60 58
         this.options = options;
61 59
         // A flag whether we had received that the data channel had opened
62 60
         // we can get this flag out of sync if for some reason data channel got
@@ -259,20 +257,39 @@ export default class RTC extends Listenable {
259 257
         this.localTracks.push(track);
260 258
 
261 259
         track.conference = this.conference;
262
-
263
-        if (track.isAudioTrack()) {
264
-            this.localAudio = track;
265
-        } else {
266
-            this.localVideo = track;
267
-        }
268 260
     }
269 261
 
270 262
     /**
271 263
      * Get local video track.
272
-     * @returns {JitsiLocalTrack}
264
+     * @returns {JitsiLocalTrack|undefined}
273 265
      */
274 266
     getLocalVideoTrack () {
275
-        return this.localVideo;
267
+        const localVideo = this.getLocalTracks(MediaType.VIDEO);
268
+        return localVideo.length ? localVideo[0] : undefined;
269
+    }
270
+
271
+    /**
272
+     * Get local audio track.
273
+     * @returns {JitsiLocalTrack|undefined}
274
+     */
275
+    getLocalAudioTrack () {
276
+        const localAudio = this.getLocalTracks(MediaType.AUDIO);
277
+        return localAudio.length ? localAudio[0] : undefined;
278
+    }
279
+
280
+    /**
281
+     * Returns the local tracks of the given media type, or all local tracks if
282
+     * no specific type is given.
283
+     * @param {MediaType} [mediaType] optional media type filter
284
+     * (audio or video).
285
+     */
286
+    getLocalTracks (mediaType) {
287
+        let tracks = this.localTracks.slice();
288
+        if (mediaType !== undefined) {
289
+            tracks = tracks.filter(
290
+                (track) => { return track.getType() === mediaType; });
291
+        }
292
+        return tracks;
276 293
     }
277 294
 
278 295
     /**
@@ -344,32 +361,22 @@ export default class RTC extends Listenable {
344 361
      * @returns {Promise}
345 362
      */
346 363
     setAudioMute (value) {
347
-        var mutePromises = [];
348
-        for(var i = 0; i < this.localTracks.length; i++) {
349
-            var track = this.localTracks[i];
350
-            if(track.getType() !== MediaType.AUDIO) {
351
-                continue;
352
-            }
364
+        const mutePromises = [];
365
+        this.getLocalTracks(MediaType.AUDIO).forEach(function(audioTrack){
353 366
             // this is a Promise
354
-            mutePromises.push(value ? track.mute() : track.unmute());
355
-        }
367
+            mutePromises.push(value ? audioTrack.mute() : audioTrack.unmute());
368
+        });
356 369
         // we return a Promise from all Promises so we can wait for their execution
357 370
         return Promise.all(mutePromises);
358 371
     }
359 372
 
360 373
     removeLocalTrack (track) {
361
-        var pos = this.localTracks.indexOf(track);
374
+        const pos = this.localTracks.indexOf(track);
362 375
         if (pos === -1) {
363 376
             return;
364 377
         }
365 378
 
366 379
         this.localTracks.splice(pos, 1);
367
-
368
-        if (track.isAudioTrack()) {
369
-            this.localAudio = null;
370
-        } else {
371
-            this.localVideo = null;
372
-        }
373 380
     }
374 381
 
375 382
     /**
@@ -636,13 +643,13 @@ export default class RTC extends Listenable {
636 643
      * @param ssrc the ssrc to check.
637 644
      */
638 645
     getResourceBySSRC (ssrc) {
639
-        if((this.localVideo && ssrc == this.localVideo.getSSRC())
640
-            || (this.localAudio && ssrc == this.localAudio.getSSRC())) {
646
+        if (this.getLocalTracks().find(
647
+                localTrack => { return localTrack.getSSRC() == ssrc; })) {
641 648
             return this.conference.myUserId();
642 649
         }
643 650
 
644
-        var track = this.getRemoteTrackBySSRC(ssrc);
645
-        return track? track.getParticipantId() : null;
651
+        const track = this.getRemoteTrackBySSRC(ssrc);
652
+        return track ? track.getParticipantId() : null;
646 653
     }
647 654
 
648 655
     /**

+ 3
- 6
modules/connectivity/ConnectionQuality.js View File

@@ -5,7 +5,6 @@ import {getLogger} from "jitsi-meet-logger";
5 5
 import RTCBrowserType from "../RTC/RTCBrowserType";
6 6
 
7 7
 var XMPPEvents = require('../../service/xmpp/XMPPEvents');
8
-var MediaType = require('../../service/RTC/MediaType');
9 8
 var VideoType = require('../../service/RTC/VideoType');
10 9
 var Resolutions = require("../../service/RTC/Resolutions");
11 10
 
@@ -359,8 +358,7 @@ export default class ConnectionQuality {
359 358
         // about the resolution, and they look at their local rendered
360 359
         // resolution instead. Consider removing this.
361 360
         let localVideoTrack
362
-            = this._conference.getLocalTracks(MediaType.VIDEO)
363
-                .find(track => track.isVideoTrack());
361
+            = this._conference.getLocalVideoTrack();
364 362
         if (localVideoTrack && localVideoTrack.resolution) {
365 363
             data.resolution = localVideoTrack.resolution;
366 364
         }
@@ -390,9 +388,8 @@ export default class ConnectionQuality {
390 388
         let key;
391 389
         let updateLocalConnectionQuality
392 390
             = !this._conference.isConnectionInterrupted();
393
-        let localVideoTrack =
394
-                this._conference.getLocalTracks(MediaType.VIDEO)
395
-                    .find(track => track.isVideoTrack());
391
+        let localVideoTrack
392
+            = this._conference.getLocalVideoTrack();
396 393
         let videoType = localVideoTrack ? localVideoTrack.videoType : undefined;
397 394
         let isMuted = localVideoTrack ? localVideoTrack.isMuted() : true;
398 395
         let resolution = localVideoTrack ? localVideoTrack.resolution : null;

+ 8
- 6
modules/xmpp/SDP.js View File

@@ -251,12 +251,14 @@ SDP.prototype.toJingle = function (elem, thecreator) {
251 251
                     elem.c('parameter');
252 252
                     elem.attrs({name: "cname", value:Math.random().toString(36).substring(7)});
253 253
                     elem.up();
254
-                    var msid = null;
255
-                    if(mline.media == "audio") {
256
-                        // FIXME what is this ? global APP.RTC in SDP ?
257
-                        msid = APP.RTC.localAudio._getId();
258
-                    } else {
259
-                        msid = APP.RTC.localVideo._getId();
254
+                    // FIXME what case does this code handle ? remove ???
255
+                    let msid = null;
256
+                    // FIXME what is this ? global APP.RTC in SDP ?
257
+                    const localTrack = APP.RTC.getLocalTracks(mline.media);
258
+                    if (localTrack) {
259
+                        // FIXME before this changes the track id was accessed,
260
+                        // but msid stands for the stream id, makes no sense ?
261
+                        msid = localTrack.getTrackId();
260 262
                     }
261 263
                     if(msid != null) {
262 264
                         msid = SDPUtil.filter_special_chars(msid);

Loading…
Cancel
Save