Skip to content

Commit

Permalink
Add more info with connection-failed events (#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague committed Sep 11, 2020
1 parent 1d97c8a commit 6038d5c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 33 deletions.
5 changes: 3 additions & 2 deletions erizo_controller/erizoClient/src/ErizoConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class ErizoConnection extends EventEmitterConst {
this.qualityLevel = QUALITY_LEVEL_GOOD;

log.debug(`message: Building a new Connection, ${this.toLog()}`);
spec.onEnqueueingTimeout = () => {
this.emit(ConnectionEvent({ type: 'connection-failed', id: this.connectionId }));
spec.onEnqueueingTimeout = (step) => {
const message = `reason: Timeout in ${step}`;
this.emit(ConnectionEvent({ type: 'connection-failed', connection: this, message }));
};

if (!spec.streamRemovedListener) {
Expand Down
2 changes: 2 additions & 0 deletions erizo_controller/erizoClient/src/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const ConnectionEvent = (spec) => {
const that = LicodeEvent(spec);

that.stream = spec.stream;
that.connection = spec.connection;
that.state = spec.state;
that.message = spec.message;

return that;
};
Expand Down
25 changes: 6 additions & 19 deletions erizo_controller/erizoClient/src/Room.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ErizoConnectionManager from './ErizoConnectionManager';
import ConnectionHelpers from './utils/ConnectionHelpers';
import { EventDispatcher, StreamEvent, RoomEvent, ConnectionEvent } from './Events';
import { EventDispatcher, StreamEvent, RoomEvent } from './Events';
import { Socket } from './Socket';
import Stream from './Stream';
import ErizoMap from './utils/ErizoMap';
Expand Down Expand Up @@ -110,12 +110,6 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
}
};

const onConnectionFailed = () => {
const connectionFailedEvt = ConnectionEvent(
{ type: 'connection-failed' });
that.dispatchEvent(connectionFailedEvt);
};

const onStreamFailed = (streamInput, message, origin = 'unknown') => {
const stream = streamInput;
if (that.state !== DISCONNECTED && stream && !stream.failed) {
Expand Down Expand Up @@ -171,9 +165,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
const connection = that.erizoConnectionManager.getOrBuildErizoConnection(
getP2PConnectionOptions(stream, peerSocket));
stream.addPC(connection);
connection.on('connection-failed', () => {
onConnectionFailed(connection);
});
connection.on('connection-failed', that.dispatchEvent.bind(this));
stream.on('added', dispatchStreamSubscribed.bind(null, stream));
stream.on('icestatechanged', (evt) => {
log.debug(`message: icestatechanged, ${stream.toLog()}, iceConnectionState: ${evt.msg.state}, ${toLog()}`);
Expand All @@ -190,9 +182,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
getP2PConnectionOptions(stream, peerSocket));

stream.addPC(connection, peerSocket);
connection.on('connection-failed', () => {
onConnectionFailed(connection);
});
connection.on('connection-failed', that.dispatchEvent.bind(this));

stream.on('icestatechanged', (evt) => {
log.debug(`message: icestatechanged, streamId: ${stream.getID()}, iceConnectionState: ${evt.msg.state}, ${toLog()}`);
Expand Down Expand Up @@ -270,9 +260,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
const connection = that.erizoConnectionManager
.getOrBuildErizoConnection(connectionOpts, erizoId, spec.singlePC);
stream.addPC(connection);
connection.on('connection-failed', () => {
onConnectionFailed(connection);
});
connection.on('connection-failed', that.dispatchEvent.bind(this));

stream.on('added', dispatchStreamSubscribed.bind(null, stream));
stream.on('icestatechanged', (evt) => {
log.debug(`message: icestatechanged, ${stream.toLog()}, iceConnectionState: ${evt.msg.state}, ${toLog()}`);
Expand All @@ -292,9 +281,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
const connection = that.erizoConnectionManager
.getOrBuildErizoConnection(connectionOpts, erizoId, spec.singlePC);
stream.addPC(connection);
connection.on('connection-failed', () => {
onConnectionFailed(connection);
});
connection.on('connection-failed', that.dispatchEvent.bind(this));
stream.on('icestatechanged', (evt) => {
log.debug(`message: icestatechanged, ${stream.toLog()}, iceConnectionState: ${evt.msg.state}, ${toLog()}`);
if (evt.msg.state === 'failed') {
Expand Down
4 changes: 2 additions & 2 deletions erizo_controller/erizoClient/src/utils/FunctionQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class FunctionQueue {
return this._enqueuing;
}

startEnqueuing() {
startEnqueuing(step) {
this._enqueuing = true;
clearTimeout(this._enqueueingTimeout);
this._enqueueingTimeout = setTimeout(() => {
if (this.onEnqueueingTimeout) {
this.onEnqueueingTimeout();
this.onEnqueueingTimeout(step);
}
}, this.maxEnqueueingTime);
}
Expand Down
20 changes: 10 additions & 10 deletions erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const NEGOTIATION_TIMEOUT = 30000;
const BaseStack = (specInput) => {
const that = {};
const specBase = specInput;
const negotiationQueue = new FunctionQueue(NEGOTIATION_TIMEOUT, () => {
const negotiationQueue = new FunctionQueue(NEGOTIATION_TIMEOUT, (step) => {
if (specBase.onEnqueueingTimeout) {
specBase.onEnqueueingTimeout();
specBase.onEnqueueingTimeout(step);
}
});
that._queue = negotiationQueue;
Expand Down Expand Up @@ -162,7 +162,7 @@ const BaseStack = (specInput) => {
createOffer: negotiationQueue.protectFunction((isSubscribe = false,
forceOfferToReceive = false) => {
logSDP('queue - createOffer');
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('createOffer');
if (!isSubscribe && !forceOfferToReceive) {
that.mediaConstraints = {
offerToReceiveVideo: false,
Expand All @@ -180,7 +180,7 @@ const BaseStack = (specInput) => {

processOffer: negotiationQueue.protectFunction((message) => {
logSDP('queue - processOffer');
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('processOffer');
const promise = that.peerConnectionFsm.processOffer(message);
if (promise) {
promise.catch(onFsmError.bind(this));
Expand Down Expand Up @@ -219,7 +219,7 @@ const BaseStack = (specInput) => {
obj.sdpMLineIndex = parseInt(obj.sdpMLineIndex, 10);
const candidate = new RTCIceCandidate(obj);
if (specBase.remoteDescriptionSet) {
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('processNewCandidate');
that.peerConnectionFsm.addIceCandidate(candidate).catch(onFsmError.bind(this));
} else {
specBase.remoteCandidates.push(candidate);
Expand All @@ -231,7 +231,7 @@ const BaseStack = (specInput) => {

addStream: negotiationQueue.protectFunction((stream) => {
logSDP('queue - addStream');
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('addStream');
const promise = that.peerConnectionFsm.addStream(stream);
if (promise) {
promise.catch(onFsmError.bind(this));
Expand All @@ -243,7 +243,7 @@ const BaseStack = (specInput) => {

removeStream: negotiationQueue.protectFunction((stream) => {
logSDP('queue - removeStream');
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('removeStream');
const promise = that.peerConnectionFsm.removeStream(stream);
if (promise) {
promise.catch(onFsmError.bind(this));
Expand All @@ -255,7 +255,7 @@ const BaseStack = (specInput) => {

close: negotiationQueue.protectFunction(() => {
logSDP('queue - close');
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('close');
const promise = that.peerConnectionFsm.close();
if (promise) {
promise.catch(onFsmError.bind(this));
Expand Down Expand Up @@ -299,7 +299,7 @@ const BaseStack = (specInput) => {
},

protectedCreateOffer: (isSubscribe = false) => {
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('protectedCreateOffer');
logSDP('Creating offer', that.mediaConstraints);
const rejectMessages = [];
return that.prepareCreateOffer(isSubscribe)
Expand Down Expand Up @@ -448,7 +448,7 @@ const BaseStack = (specInput) => {
protectedNegotiateMaxBW: (configInput, callback) => {
const config = configInput;
if (config.Sdp || config.maxAudioBW) {
negotiationQueue.startEnqueuing();
negotiationQueue.startEnqueuing('protectedNegotiateMaxBW');
const rejectMessages = [];

configureLocalSdpAsOffer();
Expand Down
1 change: 1 addition & 0 deletions extras/basic_example/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const startBasicExample = () => {
}
});
};
room.on('connection-failed', console.log.bind(console));

room.addEventListener('room-connected', (roomEvent) => {
const options = { metadata: { type: 'publisher' } };
Expand Down

0 comments on commit 6038d5c

Please sign in to comment.