From 539a27326398338a9f6e7234d442e404f90dfcee Mon Sep 17 00:00:00 2001 From: Alexis Faizeau Date: Fri, 18 Mar 2022 17:37:02 +0100 Subject: [PATCH] Revert "Stabilize screensharing (#1982)" (#1984) This reverts commit 33e78060d4267170a3c4baf35c22db4c4e478481. --- front/src/WebRtc/SimplePeer.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/front/src/WebRtc/SimplePeer.ts b/front/src/WebRtc/SimplePeer.ts index c2d17241..fdd95748 100644 --- a/front/src/WebRtc/SimplePeer.ts +++ b/front/src/WebRtc/SimplePeer.ts @@ -125,6 +125,7 @@ export class SimplePeer { if (!peerConnexionDeleted) { throw new Error("Error to delete peer connection"); } + //return this.createPeerConnection(user, localStream); } else { peerConnection.toClose = false; return null; @@ -170,7 +171,6 @@ 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,9 +201,6 @@ export class SimplePeer { this.Connection, stream ); - - peer.toClose = false; - this.PeerScreenSharingConnectionArray.set(user.userId, peer); screenSharingPeerStore.pushNewPeer(peer); @@ -268,13 +265,10 @@ 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() { @@ -382,6 +376,11 @@ 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,