From b872ea855eaffa9f1fe6c0751b753e8d5ae87e71 Mon Sep 17 00:00:00 2001
From: pangrr <pangrr89@gmail.com>
Date: Tue, 3 May 2022 17:33:38 -0400
Subject: [PATCH] fix(large-video) Fix an infinite loop with source name
 signaling enabled (#11486)

* fix large video updating loop when kicked out

* fix linter issue
---
 modules/UI/videolayout/LargeVideoManager.js | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/modules/UI/videolayout/LargeVideoManager.js b/modules/UI/videolayout/LargeVideoManager.js
index 0f2e3cae3..d87bcc916 100644
--- a/modules/UI/videolayout/LargeVideoManager.js
+++ b/modules/UI/videolayout/LargeVideoManager.js
@@ -160,6 +160,18 @@ export default class LargeVideoManager {
         this.videoContainer.removeResizeListener(
             this._onVideoResolutionUpdate);
 
+        if (getSourceNameSignalingFeatureFlag(APP.store.getState())) {
+            // Remove track streaming status listener.
+            // TODO: when this class is converted to a function react component,
+            // use a custom hook to update a local track streaming status.
+            if (this.videoTrack && !this.videoTrack.local) {
+                this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
+                    this.handleTrackStreamingStatusChanged);
+                APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
+                    this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
+            }
+        }
+
         this.removePresenceLabel();
 
         ReactDOM.unmountComponentAtNode(this._dominantSpeakerAvatarContainer);
@@ -260,14 +272,16 @@ export default class LargeVideoManager {
                 // TODO: when this class is converted to a function react component,
                 // use a custom hook to update a local track streaming status.
                 if (this.videoTrack?.jitsiTrack?.getSourceName() !== videoTrack?.jitsiTrack?.getSourceName()) {
-                    if (this.videoTrack) {
+                    if (this.videoTrack && !this.videoTrack.local) {
                         this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
                             this.handleTrackStreamingStatusChanged);
                         APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
                             this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
                     }
-                    if (videoTrack && !videoTrack.local) {
-                        this.videoTrack = videoTrack;
+
+                    this.videoTrack = videoTrack;
+
+                    if (this.videoTrack && !this.videoTrack.local) {
                         this.videoTrack.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
                             this.handleTrackStreamingStatusChanged);
                         APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,