Permalink
Browse files

ref(JitsiConference): use promises for mute

  • Loading branch information...
paweldomas committed Feb 15, 2017
1 parent 6ac0854 commit be171765986fbc751e2e24b965021875d04e0bc7
Showing with 30 additions and 23 deletions.
  1. +14 −17 JitsiConference.js
  2. +16 −6 modules/RTC/JitsiLocalTrack.js
View
@@ -551,13 +551,15 @@ JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
* the process or <tt>null</t> if the method should act as "add track"
* @param {JitsiLocalTrack|null} newTrack the new track to be added or
* <tt>null</tt> if the method should act as "remove track"
* @return {Promise}
* @return {Promise} resolved when the process is done or rejected with a string
* which describes the error.
* @private
*/
JitsiConference.prototype._doReplaceTrack = function (oldTrack, newTrack) {
if (this.jingleSession) {
return this.jingleSession.replaceTrack(oldTrack, newTrack);
} else {
logger.info("_doReplaceTrack - no JVB JingleSession");
return Promise.resolve();
}
};
@@ -624,38 +626,33 @@ JitsiConference.prototype._setupNewTrack = function (newTrack) {
* Add track stream.
* @param {JitsiLocalTrack} track the local track that will be added as part of
* the unmute operation.
* @param {function} callback callback executed, after successful stream
* addition.
* @param {function} errorCallback callback executed if stream addition fails.
* @return {Promise} resolved when the process is done or rejected with a string
* which describes the error.
*/
JitsiConference.prototype._addLocalTrackAsUnmute
= function (track, callback, errorCallback) {
JitsiConference.prototype._addLocalTrackAsUnmute = function (track) {
if (this.jingleSession) {
this.jingleSession.addTrackAsUnmute(track)
.then(callback).catch(errorCallback);
return this.jingleSession.addTrackAsUnmute(track);
} else {
// We are done immediately
logger.warn(
"Add local MediaStream as unmute - no JingleSession started yet");
callback();
return Promise.resolve();
}
};
/**
* Removes given local track, as part of the mute operation.
* @param {JitsiLocalTrack} track the local track that will be removed.
* @param {function} callback callback executed after successful track removal.
* @param {function} errorCallback callback executed if track removal fails.
* @return {Promise}
*/
JitsiConference.prototype._removeTrackAsMute
= function (track, callback, errorCallback) {
JitsiConference.prototype._removeTrackAsMute = function (track) {
if (this.jingleSession) {
this.jingleSession.removeTrackAsMute(track)
.then(callback).catch(errorCallback);
return this.jingleSession.removeTrackAsMute(track);
} else {
// We are done immediately
logger.warn("Remove local MediaStream - no JingleSession started yet");
callback();
logger.warn(
"Remove local MediaStream - no JVB JingleSession started yet");
return Promise.resolve();
}
};
@@ -331,6 +331,10 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
// Local track can be used out of conference, so we need to handle that
// case and mark that track should start muted or not when added to
// conference.
// Pawel: track's muted status should be taken into account when track is
// being added to the conference/JingleSessionPC/TraceablePeerConnection.
// There's no need to add such fields. It is logical that when muted track
// is being added to a conference it "starts muted"...
if(!this.conference || !this.conference.room) {
this.startMuted = mute;
}
@@ -425,10 +429,18 @@ JitsiLocalTrack.prototype._addStreamToConferenceAsUnmute = function () {
return Promise.resolve();
}
// FIXME deal with unmute (should be done by the traceable peer connection)
// FIXME it would be good to not included conference as part of this process
// Only TraceablePeerConnections to which the track is attached should care
// about this action. The TPCs to which the track is not attached can sync
// up when track is re-attached.
// A problem with that is that the "modify sources" queue is part of
// the JingleSessionPC and it would be excluded from the process. One
// solution would be to extract class between TPC and JingleSessionPC which
// would contain the queue and would notify the signalling layer when local
// SSRCs are changed. This would help to separate XMPP from the RTC module.
return new Promise((resolve, reject) => {
this.conference._addLocalTrackAsUnmute(
this, resolve, (error) => reject(new Error(error)));
this.conference._addLocalTrackAsUnmute(this)
.then(resolve, (error) => reject(new Error(error)));
});
};
@@ -444,9 +456,7 @@ function (successCallback, errorCallback) {
successCallback();
return;
}
// FXIME make removeLocalWebRTCStream accept callbacks
this.conference._removeTrackAsMute(
this,
this.conference._removeTrackAsMute(this).then(
successCallback,
(error) => errorCallback(new Error(error)));
};

0 comments on commit be17176

Please sign in to comment.