Skip to content

Commit

Permalink
ref(JitsiConference): use promises for mute
Browse files Browse the repository at this point in the history
  • Loading branch information
paweldomas committed Feb 27, 2017
1 parent 6ac0854 commit be17176
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
31 changes: 14 additions & 17 deletions JitsiConference.js
Expand Up @@ -551,13 +551,15 @@ JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
* the process or <tt>null</t> if the method should act as "add track" * 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 * @param {JitsiLocalTrack|null} newTrack the new track to be added or
* <tt>null</tt> if the method should act as "remove track" * <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 * @private
*/ */
JitsiConference.prototype._doReplaceTrack = function (oldTrack, newTrack) { JitsiConference.prototype._doReplaceTrack = function (oldTrack, newTrack) {
if (this.jingleSession) { if (this.jingleSession) {
return this.jingleSession.replaceTrack(oldTrack, newTrack); return this.jingleSession.replaceTrack(oldTrack, newTrack);
} else { } else {
logger.info("_doReplaceTrack - no JVB JingleSession");
return Promise.resolve(); return Promise.resolve();
} }
}; };
Expand Down Expand Up @@ -624,38 +626,33 @@ JitsiConference.prototype._setupNewTrack = function (newTrack) {
* Add track stream. * Add track stream.
* @param {JitsiLocalTrack} track the local track that will be added as part of * @param {JitsiLocalTrack} track the local track that will be added as part of
* the unmute operation. * the unmute operation.
* @param {function} callback callback executed, after successful stream * @return {Promise} resolved when the process is done or rejected with a string
* addition. * which describes the error.
* @param {function} errorCallback callback executed if stream addition fails.
*/ */
JitsiConference.prototype._addLocalTrackAsUnmute JitsiConference.prototype._addLocalTrackAsUnmute = function (track) {
= function (track, callback, errorCallback) {
if (this.jingleSession) { if (this.jingleSession) {
this.jingleSession.addTrackAsUnmute(track) return this.jingleSession.addTrackAsUnmute(track);
.then(callback).catch(errorCallback);
} else { } else {
// We are done immediately // We are done immediately
logger.warn( logger.warn(
"Add local MediaStream as unmute - no JingleSession started yet"); "Add local MediaStream as unmute - no JingleSession started yet");
callback(); return Promise.resolve();
} }
}; };


/** /**
* Removes given local track, as part of the mute operation. * Removes given local track, as part of the mute operation.
* @param {JitsiLocalTrack} track the local track that will be removed. * @param {JitsiLocalTrack} track the local track that will be removed.
* @param {function} callback callback executed after successful track removal. * @return {Promise}
* @param {function} errorCallback callback executed if track removal fails.
*/ */
JitsiConference.prototype._removeTrackAsMute JitsiConference.prototype._removeTrackAsMute = function (track) {
= function (track, callback, errorCallback) {
if (this.jingleSession) { if (this.jingleSession) {
this.jingleSession.removeTrackAsMute(track) return this.jingleSession.removeTrackAsMute(track);
.then(callback).catch(errorCallback);
} else { } else {
// We are done immediately // We are done immediately
logger.warn("Remove local MediaStream - no JingleSession started yet"); logger.warn(
callback(); "Remove local MediaStream - no JVB JingleSession started yet");
return Promise.resolve();
} }
}; };


Expand Down
22 changes: 16 additions & 6 deletions modules/RTC/JitsiLocalTrack.js
Expand Up @@ -331,6 +331,10 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
// Local track can be used out of conference, so we need to handle that // 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 // case and mark that track should start muted or not when added to
// conference. // 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) { if(!this.conference || !this.conference.room) {
this.startMuted = mute; this.startMuted = mute;
} }
Expand Down Expand Up @@ -425,10 +429,18 @@ JitsiLocalTrack.prototype._addStreamToConferenceAsUnmute = function () {
return Promise.resolve(); 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) => { return new Promise((resolve, reject) => {
this.conference._addLocalTrackAsUnmute( this.conference._addLocalTrackAsUnmute(this)
this, resolve, (error) => reject(new Error(error))); .then(resolve, (error) => reject(new Error(error)));
}); });
}; };


Expand All @@ -444,9 +456,7 @@ function (successCallback, errorCallback) {
successCallback(); successCallback();
return; return;
} }
// FXIME make removeLocalWebRTCStream accept callbacks this.conference._removeTrackAsMute(this).then(
this.conference._removeTrackAsMute(
this,
successCallback, successCallback,
(error) => errorCallback(new Error(error))); (error) => errorCallback(new Error(error)));
}; };
Expand Down

0 comments on commit be17176

Please sign in to comment.