Skip to content

Commit

Permalink
Add origin info to streamEvent failed (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jun 20, 2019
1 parent 9ecd6b5 commit 28ba178
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion doc/client_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ room.startRecording(localStream, function(recordingId, error) {
} else {
console.log("Recording started, the id of the recording is ", recordingId);
}
});
});
```

## Stop Recording
Expand Down Expand Up @@ -810,6 +810,8 @@ You can access the related stream by `streamEvent.stream`.

Some of them have a more detailed message in `streamEvent.msg`.

For `stream-failed` events there is another field `streamEvent.origin` to give us more info about the reason of the failure.

There are the different types of Stream events:

- *access-accepted*: indicates that the user has accepted to share his camera and microphone.
Expand Down
1 change: 1 addition & 0 deletions erizo_controller/erizoClient/src/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const StreamEvent = (spec) => {
that.stream = spec.stream;

that.msg = spec.msg;
that.origin = spec.origin;
that.bandwidth = spec.bandwidth;
that.attrs = spec.attrs;

Expand Down
18 changes: 11 additions & 7 deletions erizo_controller/erizoClient/src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
}
};

const onStreamFailed = (streamInput, message) => {
const onStreamFailed = (streamInput, message, origin = 'unknown') => {
const stream = streamInput;
if (that.state !== DISCONNECTED && stream && !stream.failed) {
stream.failed = true;

const streamFailedEvt = StreamEvent(
{ type: 'stream-failed',
msg: message || 'Stream failed after connection',
stream });
stream,
origin });
that.dispatchEvent(streamFailedEvt);
const connection = stream.pc;

Expand Down Expand Up @@ -163,7 +164,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
stream.on('icestatechanged', (evt) => {
Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`);
if (evt.msg.state === 'failed') {
onStreamFailed(stream);
const message = 'ICE Connection Failed';
onStreamFailed(stream, message, 'ice-client');
}
});
};
Expand Down Expand Up @@ -255,7 +257,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
stream.on('icestatechanged', (evt) => {
Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`);
if (evt.msg.state === 'failed') {
onStreamFailed(stream);
const message = 'ICE Connection Failed';
onStreamFailed(stream, message, 'ice-client');
if (spec.singlePC) {
connectionOpts.callback({ type: 'failed' });
}
Expand All @@ -273,7 +276,8 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
stream.on('icestatechanged', (evt) => {
Logger.info(`${stream.getID()} - iceConnectionState: ${evt.msg.state}`);
if (evt.msg.state === 'failed') {
onStreamFailed(stream);
const message = 'ICE Connection Failed';
onStreamFailed(stream, message, 'ice-client');
if (spec.singlePC) {
connectionOpts.callback({ type: 'failed' });
}
Expand Down Expand Up @@ -432,7 +436,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
const socketOnRemoveStream = (arg) => {
let stream = localStreams.get(arg.id);
if (stream) {
onStreamFailed(stream);
onStreamFailed(stream, 'Stream removed from server', 'server');
return;
}
stream = remoteStreams.get(arg.id);
Expand Down Expand Up @@ -467,7 +471,7 @@ const Room = (altIo, altConnectionHelpers, altConnectionManager, specInput) => {
} else {
stream = remoteStreams.get(arg.streamId);
}
onStreamFailed(stream, message);
onStreamFailed(stream, message, 'ice-server');
};

const socketOnError = (e) => {
Expand Down

0 comments on commit 28ba178

Please sign in to comment.