Permalink
Browse files

ref(RTC): cleanup local track access

  • Loading branch information...
paweldomas committed Jan 12, 2017
1 parent 5d1f40e commit 33866963cd332071296a810c74697073ba723bc7
View
@@ -264,17 +264,27 @@ JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
JitsiConference.prototype.getLocalTracks = function (mediaType) {
let tracks = [];
if (this.rtc) {
tracks = this.rtc.localTracks.slice();
}
if (mediaType !== undefined) {
tracks = tracks.filter(
(track) => {
return track && track.getType && track.getType() === mediaType;
});
tracks = this.rtc.getLocalTracks(mediaType);
}
return tracks;
};
/**
* Obtains local audio track.
* @return {JitsiLocalTrack|undefined}
*/
JitsiConference.prototype.getLocalAudioTrack = function () {
return this.rtc ? this.rtc.getLocalAudioTrack() : undefined;
};
/**
* Obtains local video track.
* @return {JitsiLocalTrack|undefined}
*/
JitsiConference.prototype.getLocalVideoTrack = function () {
return this.rtc ? this.rtc.getLocalVideoTrack() : undefined;
};
/**
* Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
* in JitsiConferenceEvents.
@@ -396,18 +406,15 @@ JitsiConference.prototype.getTranscriber = function(){
if(this.transcriber === undefined){
this.transcriber = new Transcriber();
//add all existing local audio tracks to the transcriber
// FIXME accessing localTracks field directly
this.rtc.localTracks.forEach(function (localTrack) {
if(localTrack.isAudioTrack()){
this.transcriber.addTrack(localTrack);
}
}.bind(this));
this.getLocalTracks(MediaType.AUDIO).forEach(
function (localAudio) {
this.transcriber.addTrack(localAudio);
}, this);
//and all remote audio tracks
this.rtc.getRemoteTracks(MediaType.AUDIO).forEach(
function (remoteTrack) {
this.transcriber.addTrack(remoteTrack);
}.bind(this)
);
}, this);
}
return this.transcriber;
};
@@ -1030,7 +1037,7 @@ function (jingleSession, jingleOffer, now) {
this.rtc.initializeDataChannels(jingleSession.peerconnection);
// Add local Tracks to the ChatRoom
this.rtc.localTracks.forEach(function(localTrack) {
this.getLocalTracks().forEach(function(localTrack) {
var ssrcInfo = null;
/**
* We don't do this for Firefox because, on Firefox, we keep the
@@ -1126,7 +1133,7 @@ JitsiConference.prototype.onCallEnded
// will learn what their SSRC from the new PeerConnection which will be
// created on incoming call event.
var self = this;
this.rtc.localTracks.forEach(function(localTrack) {
this.getLocalTracks().forEach(function(localTrack) {
// Reset SSRC as it will no longer be valid
localTrack._setSSRC(null);
// Bind the handler to fetch new SSRC, it will un register itself once
@@ -1179,21 +1186,25 @@ JitsiConference.prototype.myUserId = function () {
};
JitsiConference.prototype.sendTones = function (tones, duration, pause) {
// FIXME P2P 'dtmfManager' must be cleared, after switching jingleSessions
if (!this.dtmfManager) {
var connection = this.xmpp.connection.jingle.activecall.peerconnection;
if (!connection) {
logger.warn("cannot sendTones: no conneciton");
if (!this.jingleSession) {
logger.warn("cannot sendTones: no jingle session");
return;
}
var tracks = this.getLocalTracks().filter(function (track) {
return track.isAudioTrack();
});
if (!tracks.length) {
const peerConnection = this.jingleSession.peerconnection;
if (!peerConnection) {
logger.warn("cannot sendTones: no peer connection");
return;
}
const localAudio = this.getLocalAudioTrack();
if (!localAudio) {
logger.warn("cannot sendTones: no local audio stream");
return;
}
this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
this.dtmfManager = new JitsiDTMFManager(localAudio, peerConnection);
}
this.dtmfManager.sendTones(tones, duration, pause);
@@ -578,9 +578,9 @@ JitsiConferenceEventManager.prototype.setupStatisticsListeners = function () {
});
conference.statistics.addByteSentStatsListener(function (stats) {
conference.getLocalTracks().forEach(function (track) {
var ssrc = track.getSSRC();
if(!track.isAudioTrack() || !ssrc || !stats.hasOwnProperty(ssrc))
conference.getLocalTracks(MediaType.AUDIO).forEach(function (track) {
const ssrc = track.getSSRC();
if(!ssrc || !stats.hasOwnProperty(ssrc))
return;
track._setByteSent(stats[ssrc]);
@@ -308,15 +308,6 @@ JitsiTrack.prototype.dispose = function () {
JitsiTrack.prototype.isScreenSharing = function() {
};
/**
* FIXME remove hack in SDP.js and this method
* Returns id of the track.
* @returns {string|null} id of the track or null if this is fake track.
*/
JitsiTrack.prototype._getId = function () {
return this.getTrackId();
};
/**
* Returns id of the track.
* @returns {string|null} id of the track or null if this is fake track.
View
@@ -55,8 +55,6 @@ export default class RTC extends Listenable {
this.localTracks = [];
//FIXME: We should support multiple streams per jid.
this.remoteTracks = {};
this.localAudio = null;
this.localVideo = null;
this.options = options;
// A flag whether we had received that the data channel had opened
// we can get this flag out of sync if for some reason data channel got
@@ -255,20 +253,39 @@ export default class RTC extends Listenable {
this.localTracks.push(track);
track.conference = this.conference;
if (track.isAudioTrack()) {
this.localAudio = track;
} else {
this.localVideo = track;
}
}
/**
* Get local video track.
* @returns {JitsiLocalTrack}
* @returns {JitsiLocalTrack|undefined}
*/
getLocalVideoTrack () {
return this.localVideo;
const localVideo = this.getLocalTracks(MediaType.VIDEO);
return localVideo.length ? localVideo[0] : undefined;
}
/**
* Get local audio track.
* @returns {JitsiLocalTrack|undefined}
*/
getLocalAudioTrack () {
const localAudio = this.getLocalTracks(MediaType.AUDIO);
return localAudio.length ? localAudio[0] : undefined;
}
/**
* Returns the local tracks of the given media type, or all local tracks if
* no specific type is given.
* @param {MediaType} [mediaType] optional media type filter
* (audio or video).
*/
getLocalTracks (mediaType) {
let tracks = this.localTracks.slice();
if (mediaType !== undefined) {
tracks = tracks.filter(
(track) => { return track.getType() === mediaType; });
}
return tracks;
}
/**
@@ -342,32 +359,22 @@ export default class RTC extends Listenable {
* @returns {Promise}
*/
setAudioMute (value) {
var mutePromises = [];
for(var i = 0; i < this.localTracks.length; i++) {
var track = this.localTracks[i];
if(track.getType() !== MediaType.AUDIO) {
continue;
}
const mutePromises = [];
this.getLocalTracks(MediaType.AUDIO).forEach(function(audioTrack){
// this is a Promise
mutePromises.push(value ? track.mute() : track.unmute());
}
mutePromises.push(value ? audioTrack.mute() : audioTrack.unmute());
});
// we return a Promise from all Promises so we can wait for their execution
return Promise.all(mutePromises);
}
removeLocalTrack (track) {
var pos = this.localTracks.indexOf(track);
const pos = this.localTracks.indexOf(track);
if (pos === -1) {
return;
}
this.localTracks.splice(pos, 1);
if (track.isAudioTrack()) {
this.localAudio = null;
} else {
this.localVideo = null;
}
}
/**
@@ -635,13 +642,13 @@ export default class RTC extends Listenable {
* @param ssrc the ssrc to check.
*/
getResourceBySSRC (ssrc) {
if((this.localVideo && ssrc == this.localVideo.getSSRC())
|| (this.localAudio && ssrc == this.localAudio.getSSRC())) {
if (this.getLocalTracks().find(
function(localTrack){ return localTrack.getSSRC() == ssrc; })) {
return this.conference.myUserId();
}
var track = this.getRemoteTrackBySSRC(ssrc);
return track? track.getParticipantId() : null;
const track = this.getRemoteTrackBySSRC(ssrc);
return track ? track.getParticipantId() : null;
}
/**
@@ -5,7 +5,6 @@ import {getLogger} from "jitsi-meet-logger";
import RTCBrowserType from "../RTC/RTCBrowserType";
var XMPPEvents = require('../../service/xmpp/XMPPEvents');
var MediaType = require('../../service/RTC/MediaType');
var VideoType = require('../../service/RTC/VideoType');
var Resolutions = require("../../service/RTC/Resolutions");
@@ -359,8 +358,7 @@ export default class ConnectionQuality {
// about the resolution, and they look at their local rendered
// resolution instead. Consider removing this.
let localVideoTrack
= this._conference.getLocalTracks(MediaType.VIDEO)
.find(track => track.isVideoTrack());
= this._conference.getLocalVideoTrack();
if (localVideoTrack && localVideoTrack.resolution) {
data.resolution = localVideoTrack.resolution;
}
@@ -390,9 +388,8 @@ export default class ConnectionQuality {
let key;
let updateLocalConnectionQuality
= !this._conference.isConnectionInterrupted();
let localVideoTrack =
this._conference.getLocalTracks(MediaType.VIDEO)
.find(track => track.isVideoTrack());
let localVideoTrack
= this._conference.getLocalVideoTrack();
let videoType = localVideoTrack ? localVideoTrack.videoType : undefined;
let isMuted = localVideoTrack ? localVideoTrack.isMuted() : true;
let resolution = localVideoTrack ? localVideoTrack.resolution : null;
View
@@ -251,12 +251,14 @@ SDP.prototype.toJingle = function (elem, thecreator) {
elem.c('parameter');
elem.attrs({name: "cname", value:Math.random().toString(36).substring(7)});
elem.up();
var msid = null;
if(mline.media == "audio") {
// FIXME what is this ? global APP.RTC in SDP ?
msid = APP.RTC.localAudio._getId();
} else {
msid = APP.RTC.localVideo._getId();
// FIXME what case does this code handle ? remove ???
let msid = null;
// FIXME what is this ? global APP.RTC in SDP ?
const localTrack = APP.RTC.getLocalTracks(mline.media);
if(localTrack) {
// FIXME before this changes the track id was accessed,
// but msid stands for the stream id, makes no sense ?
msid = localTrack.getTrackId();
}
if(msid != null) {
msid = SDPUtil.filter_special_chars(msid);

0 comments on commit 3386696

Please sign in to comment.