Skip to content

Commit

Permalink
Fix content swap with external content endpoints leaking sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
prlanzarin committed Aug 22, 2019
1 parent d98f72f commit fada488
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/screenshare/ScreenshareManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ module.exports = class ScreenshareManager extends BaseManager {
try {
if (floor == null) {
// Content floor was released, forcibly stop the session if it wasn't yet
await this._stopSession(roomId);
await this.closeSession(this._fetchSession(roomId), null, C.SEND_ROLE, roomId);
}
} catch (e) {
Logger.error(LOG_PREFIX, this._handleError(this._logPrefix, null, null, null, e));
Logger.error("[ScreenshareManager]", this._handleError(this._logPrefix, null, null, null, e));
}
}

Expand Down
17 changes: 11 additions & 6 deletions lib/screenshare/screenshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ module.exports = class Screenshare extends BaseProvider {
async _fetchContentFloor () {
try {
const { floor } = await this.mcs.getContentFloor(this._voiceBridge);
const contentFloorId = floor.mediaId;
Logger.debug(LOG_PREFIX, "Content floor for", this._voiceBridge, "is", contentFloorId);
return contentFloorId;
Logger.debug(LOG_PREFIX, `Content floor for ${this._voiceBridge} is ${floor}`);
return floor;
} catch (e) {
throw e;
}
Expand All @@ -383,7 +382,8 @@ module.exports = class Screenshare extends BaseProvider {
}

if (this._presenterEndpoint == null) {
this._presenterEndpoint = await this._fetchContentFloor();;
const floor = await this._fetchContentFloor();
this._presenterEndpoint = floor? floor.mediaId : null
}

const { mediaId, answer } = await this.mcs.subscribe(this.presenterMCSUserId,
Expand Down Expand Up @@ -440,7 +440,8 @@ module.exports = class Screenshare extends BaseProvider {
}

if (this._presenterEndpoint == null) {
this._presenterEndpoint = await this._fetchContentFloor();
const floor = await this._fetchContentFloor();
this._presenterEndpoint = floor? floor.mediaId : null
}

const { mediaId, answer } = await this.mcs.subscribe(mcsUserId,
Expand Down Expand Up @@ -505,7 +506,11 @@ module.exports = class Screenshare extends BaseProvider {
// externally; so don't try to clean presenter stuff here because that's
// the job of who started it.
if (this.presenterMCSUserId && this._presenterEndpoint) {
await this.mcs.releaseContentFloor(this._voiceBridge, this._presenterEndpoint);
const currentFloor = await this._fetchContentFloor(this._voiceBridge);
if (currentFloor && (currentFloor.mediaId === this._presenterEndpoint
|| currentFloor.mediaSessionId === this._presenterEndpoint)) {
await this.mcs.releaseContentFloor(this._voiceBridge, this._presenterEndpoint);
}
await this.mcs.unpublish(this.presenterMCSUserId, this._presenterEndpoint);
}

Expand Down

0 comments on commit fada488

Please sign in to comment.