Skip to content

Commit

Permalink
Avoid sending messages when socket is not connected (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Aug 2, 2017
1 parent 5b6f250 commit 4789eb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions erizo_controller/erizoClient/src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ const Room = (altIo, altConnection, specInput) => {

const clearAll = () => {
that.state = DISCONNECTED;
socket.state = socket.DISCONNECTED;

// Remove all streams
remoteStreams.forEach((stream, id) => {
Expand Down
11 changes: 10 additions & 1 deletion erizo_controller/erizoClient/src/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ const Socket = (newIo) => {
}, error);
};

that.disconnect = () => {
that.state = that.DISCONNECTED;
socket.disconnect();
};

// Function to send a message to the server using socket.io
that.sendMessage = (type, msg, callback = defaultCallback, error = defaultCallback) => {
if (that.state === that.DISCONNECTED && type !== 'token') {
Logger.error('Trying to send a message over a disconnected Socket');
return;
}
socket.emit(type, msg, (respType, resp) => {
if (respType === 'success') {
callback(resp);
Expand All @@ -87,7 +96,7 @@ const Socket = (newIo) => {
// It sends a SDP message to the server using socket.io
that.sendSDP = (type, options, sdp, callback = defaultCallback) => {
if (that.state === that.DISCONNECTED) {
Logger.warning('Trying to send a message over a disconnected Socket');
Logger.error('Trying to send a message over a disconnected Socket');
return;
}
socket.emit(type, options, sdp, (response, respCallback) => {
Expand Down
5 changes: 5 additions & 0 deletions erizo_controller/erizoController/erizoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ var listen = function () {
};

socket.on('signaling_message', function (msg) {
if (socket.room === undefined) {
log.error('message: singaling_message for user in undefined room ' +
msg.streamId + ' user: ' + socket.user);
socket.disconnect();
}
if (socket.room.p2p) {
sendToSocket(msg.peerSocket, 'signaling_message_peer',
{streamId: msg.streamId, peerSocket: socket.id, msg: msg.msg});
Expand Down

0 comments on commit 4789eb1

Please sign in to comment.