Skip to content

Commit

Permalink
Refactor Stream Management in ErizoController (#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Sep 26, 2019
1 parent edac94f commit a54eb4a
Show file tree
Hide file tree
Showing 12 changed files with 1,435 additions and 732 deletions.
66 changes: 66 additions & 0 deletions erizo_controller/erizoController/StreamManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* global exports */

/* eslint-disable no-param-reassign */

const StreamStates = require('./models/Stream').StreamStates;


class StreamManager {
constructor() {
this.publishedStreams = new Map();
}

addPublishedStream(streamId, publishedStream) {
this.publishedStreams.set(streamId, publishedStream);
}

removePublishedStream(id) {
return this.publishedStreams.delete(id);
}

forEachPublishedStream(doSomething) {
this.publishedStreams.forEach((stream) => {
doSomething(stream);
});
}

getPublishedStreamById(id) {
return this.publishedStreams.get(id);
}

hasPublishedStream(id) {
return this.publishedStreams.has(id);
}

getPublishedStreamState(id) {
if (this.hasPublishedStream(id)) {
return this.publishedStreams.get(id).state;
}
return StreamStates.PUBLISHER_UNKNOWN;
}

getErizoIdForPublishedStreamId(id) {
if (this.publishedStreams.has(id)) {
return this.publishedStreams.get(id).erizoId;
}
return undefined;
}

getPublishersInErizoId(erizoId) {
const streamsInErizo = [];
this.publishedStreams.forEach((stream) => {
if (stream.erizoId === erizoId) {
streamsInErizo.push(stream);
}
});
return streamsInErizo;
}

updateErizoIdForPublishedStream(streamId, erizoId) {
if (this.publishedStreams.has(streamId)) {
this.publishedStreams.get(streamId).erizoId = erizoId;
}
}
}

exports.StreamManager = StreamManager;
8 changes: 4 additions & 4 deletions erizo_controller/erizoController/erizoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const listen = () => {
}

const streamList = [];
room.forEachStream((stream) => {
room.streamManager.forEachPublishedStream((stream) => {
streamList.push(stream.getPublicStream());
});

Expand Down Expand Up @@ -408,7 +408,6 @@ exports.deleteUser = (user, roomId, callback) => {
*/
exports.deleteRoom = (roomId, callback) => {
log.info(`message: deleteRoom, roomId: ${roomId}`);

const room = rooms.getRoomById(roomId);

if (room === undefined) {
Expand All @@ -418,13 +417,14 @@ exports.deleteRoom = (roomId, callback) => {

if (!room.p2p) {
room.forEachClient((client) => {
room.controller.removeSubscriptions(client.id);
client.removeSubscriptions();
});
room.forEachStream((stream) => {
room.streamManager.forEachPublishedStream((stream) => {
if (stream.hasAudio() || stream.hasVideo() || stream.hasScreen()) {
room.controller.removePublisher(stream.getID());
}
});
room.streamManager.publishedStreams.clear();
}

room.forEachClient((client) => {
Expand Down
Loading

0 comments on commit a54eb4a

Please sign in to comment.