@@ -11,6 +11,7 @@ import { getReceiverVideoQualityLevel } from '../video-quality/functions';
1111import { getMinHeightForQualityLvlMap } from '../video-quality/selector' ;
1212
1313import { LAYOUTS } from './constants' ;
14+ import logger from './logger' ;
1415
1516/**
1617 * A selector for retrieving the current automatic pinning setting.
@@ -113,39 +114,49 @@ export function shouldDisplayTileView(state: IReduxState) {
113114 * Private helper to automatically pin the latest screen share stream or unpin
114115 * if there are no more screen share streams.
115116 *
116- * @param {Array<string> } screenShares - Array containing the list of all the screen sharing endpoints
117+ * @param {Array<string> } previousScreenShares - Array containing the list of all the screen sharing endpoints
117118 * before the update was triggered (including the ones that have been removed from redux because of the update).
119+ * @param {Array<string> } currentScreenShares - Array containing the current list of screen sharing endpoints.
118120 * @param {Store } store - The redux store.
119121 * @returns {void }
120122 */
121123export function updateAutoPinnedParticipant (
122- screenShares : Array < string > , { dispatch , getState } : IStore ) {
123- const state = getState ( ) ;
124- const remoteScreenShares = state [ 'features/video-layout' ] . remoteScreenShares ;
124+ previousScreenShares : Array < string > ,
125+ currentScreenShares : Array < string > ,
126+ { dispatch , getState } : IStore ) {
125127 const pinned = getPinnedParticipant ( getState ) ;
126128
127129 // if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
128130 if ( pinned ?. fakeParticipant && pinned . fakeParticipant !== FakeParticipant . RemoteScreenShare ) {
131+ logger . debug ( 'Skipping auto-pin: pinned participant is non-screenshare virtual participant' , pinned . id ) ;
132+
129133 return ;
130134 }
131135
132136 // Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
133137 // participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
134- if ( ! remoteScreenShares ?. length ) {
138+ if ( ! currentScreenShares ?. length ) {
135139 let participantId = null ;
136140
137- if ( pinned && ! screenShares . find ( share => share === pinned . id ) ) {
141+ if ( pinned && ! previousScreenShares . find ( ( share : string ) => share === pinned . id ) ) {
138142 participantId = pinned . id ;
139143 }
144+
145+ logger . debug ( 'No more screenshares, unpinning or restoring previous pin' , participantId ) ;
140146 dispatch ( pinParticipant ( participantId ) ) ;
141147
142148 return ;
143149 }
144150
145- const latestScreenShareParticipantId = remoteScreenShares [ remoteScreenShares . length - 1 ] ;
151+ const latestScreenShareParticipantId = currentScreenShares [ currentScreenShares . length - 1 ] ;
146152
147153 if ( latestScreenShareParticipantId ) {
148- dispatch ( pinParticipant ( latestScreenShareParticipantId ) ) ;
154+ const alreadyPinned = pinned ?. id === latestScreenShareParticipantId ;
155+
156+ if ( ! alreadyPinned ) {
157+ logger . debug ( `Auto pinning latest screen share participant: ${ latestScreenShareParticipantId } ` ) ;
158+ dispatch ( pinParticipant ( latestScreenShareParticipantId ) ) ;
159+ }
149160 }
150161}
151162
0 commit comments