Skip to content

Commit

Permalink
Add protections when unpublishing, subscribing and unsubscribing stre…
Browse files Browse the repository at this point in the history
…ams (lynckia#1697)
  • Loading branch information
jcague authored Apr 22, 2021
1 parent cf2ad29 commit 058db9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions erizo_controller/erizoClient/src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {

// It unpublishes the local stream in the room, dispatching a StreamEvent("stream-removed")
that.unpublish = (streamInput, callback = () => {}) => {
const stream = streamInput;
const stream = that.localStreams.get(streamInput.getID());
// Unpublish stream from Erizo-Controller
if (stream && stream.local) {
// Media stream
Expand Down Expand Up @@ -959,11 +959,11 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {

// It subscribe to a remote stream and draws it inside the HTML tag given by the ID='elementID'
that.subscribe = (streamInput, optionsInput = {}, callback = () => {}) => {
const stream = streamInput;
const stream = that.remoteStreams.get(streamInput.getID());
const options = optionsInput;

if (stream && !stream.local && !stream.failed) {
if (stream.state !== 'unsubscribed') {
if (stream.state !== 'unsubscribed' && stream.state !== 'unsubscribing') {
log.warning(`message: Cannot subscribe to a subscribed stream, ${stream.toLog()}, ${toLog()}`);
callback(undefined, 'Stream already subscribed');
return;
Expand Down Expand Up @@ -1024,11 +1024,11 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {

// It unsubscribes from the stream, removing the HTML element.
that.unsubscribe = (streamInput, callback = () => {}) => {
const stream = streamInput;
const stream = that.remoteStreams.get(streamInput.getID());
// Unsubscribe from stream
if (socket !== undefined) {
if (stream && !stream.local) {
if (stream.state !== 'subscribed') {
if (stream.state !== 'subscribed' && stream.state !== 'subscribing') {
log.warning(`message: Cannot unsubscribe to a stream that is not subscribed, ${stream.toLog()}, ${toLog()}`);
callback(undefined, 'Stream not subscribed');
return;
Expand Down

0 comments on commit 058db9c

Please sign in to comment.