Stabilize screensharing (#1982)

Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
This commit is contained in:
Alexis Faizeau 2022-03-17 17:50:39 +01:00 committed by GitHub
parent d9407a3428
commit 33e78060d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,7 +125,6 @@ export class SimplePeer {
if (!peerConnexionDeleted) {
throw new Error("Error to delete peer connection");
}
//return this.createPeerConnection(user, localStream);
} else {
peerConnection.toClose = false;
return null;
@ -171,6 +170,7 @@ export class SimplePeer {
stream: MediaStream | null
): ScreenSharingPeer | null {
const peerConnection = this.PeerScreenSharingConnectionArray.get(user.userId);
if (peerConnection) {
if (peerConnection.destroyed) {
peerConnection.toClose = true;
@ -182,8 +182,8 @@ export class SimplePeer {
this.createPeerConnection(user);
} else {
peerConnection.toClose = false;
return null;
}
return null;
}
// Enrich the user with last known credentials (if they are not set in the user object, which happens when a user triggers the screen sharing)
@ -201,6 +201,9 @@ export class SimplePeer {
this.Connection,
stream
);
peer.toClose = false;
this.PeerScreenSharingConnectionArray.set(user.userId, peer);
screenSharingPeerStore.pushNewPeer(peer);
@ -265,10 +268,13 @@ export class SimplePeer {
}
// FIXME: I don't understand why "Closing connection with" message is displayed TWICE before "Nb users in peerConnectionArray"
// I do understand the method closeConnection is called twice, but I don't understand how they manage to run in parallel.
peer.toClose = true;
peer.destroy();
} catch (err) {
console.error("closeConnection", err);
}
screenSharingPeerStore.removePeer(userId);
}
public closeAllConnections() {
@ -376,11 +382,6 @@ export class SimplePeer {
private sendLocalScreenSharingStreamToUser(userId: number, localScreenCapture: MediaStream): void {
const uuid = playersStore.getPlayerById(userId)?.userUuid || "";
if (blackListManager.isBlackListed(uuid)) return;
// If a connection already exists with user (because it is already sharing a screen with us... let's use this connection)
if (this.PeerScreenSharingConnectionArray.has(userId)) {
this.pushScreenSharingToRemoteUser(userId, localScreenCapture);
return;
}
const screenSharingUser: UserSimplePeerInterface = {
userId,