Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect on all ICE failures when using the MCU #1881

Open
wants to merge 2 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -421,6 +421,55 @@ var spreedPeerConnectionTable = [];
OCA.SpreedMe.webrtc.sendDirectlyToAll(channel, message, payload);
};

var forceReconnect = function(signaling, flags) {
if (ownPeer) {
OCA.SpreedMe.webrtc.removePeers(ownPeer.id);
OCA.SpreedMe.speakers.remove(ownPeer.id, true);
OCA.SpreedMe.videos.remove(ownPeer.id);
delete spreedMappingTable[ownPeer.id];
ownPeer.end();
ownPeer = null;
}

usersChanged(signaling, [], previousUsersInRoom);
usersInCallMapping = {};
previousUsersInRoom = [];

// Reconnects with a new session id will trigger "usersChanged"
// with the users in the room and that will re-establish the
// peerconnection streams.
// If flags are undefined the current call flags are used.
signaling.forceReconnect(true, flags);
};

OCA.SpreedMe.webrtc.webrtc.on('videoOn', function () {
var signaling = OCA.SpreedMe.app.signaling;
if (signaling.getSendVideoIfAvailable()) {
return;
}

// When enabling the local video if the video is not being sent a
// reconnection is forced to start sending it.
signaling.setSendVideoIfAvailable(true);

var flags = signaling.getCurrentCallFlags();
flags |= OCA.SpreedMe.app.FLAG_WITH_VIDEO;

forceReconnect(signaling, flags);
});

var handleIceFailedWithMcu = function() {
var signaling = OCA.SpreedMe.app.signaling;
if (!signaling.hasFeature("mcu")) {
// ICE restarts will be handled by "iceConnectionStateChange".
return;
}

// For now assume the connection to the MCU is interrupted on ICE
// failures and force a reconnection of all streams.
forceReconnect(signaling);
};

OCA.SpreedMe.videos = {
videoViews: [],
add: function(id) {
@@ -478,6 +527,13 @@ var spreedPeerConnectionTable = [];
if (peer.id === webrtc.connection.getSessionid()) {
console.log("Not adding video for own peer", peer);
OCA.SpreedMe.videos.startSendingNick(peer);
peer.pc.addEventListener('iceconnectionstatechange', function () {
switch (peer.pc.iceConnectionState) {
case 'failed':
handleIceFailedWithMcu();
break;
}
});
return;
}

@@ -581,6 +637,8 @@ var spreedPeerConnectionTable = [];

videoView.setConnectionStatus(OCA.Talk.Views.VideoView.ConnectionStatus.FAILED_NO_RESTART);
}
} else {
handleIceFailedWithMcu();

This comment has been minimized.

Copy link
@fancycode

fancycode Jun 4, 2019

Member

You are forcing a reconnect if either the own stream or one of the peers fails. Did you test what happens when you are in a call with multiple peers and your connection to the MCU gets interrupted? In that scenario, you will receive a failed event for all of the streams in a short period and will force multiple reconnects from what I understand.

It probably would be better to start a short timer on a failed event to be able to combine multiple events into a single reconnect.

This comment has been minimized.

Copy link
@nickvergessen
}
break;
case 'closed':
@@ -949,56 +1007,6 @@ var spreedPeerConnectionTable = [];
app.disableScreensharingButton();
});

var forceReconnect = function(signaling, flags) {
if (ownPeer) {
OCA.SpreedMe.webrtc.removePeers(ownPeer.id);
OCA.SpreedMe.speakers.remove(ownPeer.id, true);
OCA.SpreedMe.videos.remove(ownPeer.id);
delete spreedMappingTable[ownPeer.id];
ownPeer.end();
ownPeer = null;
}

usersChanged(signaling, [], previousUsersInRoom);
usersInCallMapping = {};
previousUsersInRoom = [];

// Reconnects with a new session id will trigger "usersChanged"
// with the users in the room and that will re-establish the
// peerconnection streams.
// If flags are undefined the current call flags are used.
signaling.forceReconnect(true, flags);
};

OCA.SpreedMe.webrtc.webrtc.on('videoOn', function () {
var signaling = OCA.SpreedMe.app.signaling;
if (signaling.getSendVideoIfAvailable()) {
return;
}

// When enabling the local video if the video is not being sent a
// reconnection is forced to start sending it.
signaling.setSendVideoIfAvailable(true);

var flags = signaling.getCurrentCallFlags();
flags |= OCA.SpreedMe.app.FLAG_WITH_VIDEO;

forceReconnect(signaling, flags);
});

OCA.SpreedMe.webrtc.webrtc.on('iceFailed', function (/* peer */) {
var signaling = OCA.SpreedMe.app.signaling;
if (!signaling.hasFeature("mcu")) {
// ICE restarts will be handled by "iceConnectionStateChange"
// above.
return;
}

// For now assume the connection to the MCU is interrupted on ICE
// failures and force a reconnection of all streams.
forceReconnect(signaling);
});

var localStreamRequestedTimeout = null;
var localStreamRequestedTimeoutNotification = null;

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.