File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
packages/react/src/prefabs Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @livekit/components-react " : patch
3+ ---
4+
5+ Refine visible controls based on canPublishSources permissions
Original file line number Diff line number Diff line change @@ -23,6 +23,20 @@ export type ControlBarControls = {
2323 settings ?: boolean ;
2424} ;
2525
26+ const trackSourceToProtocol = ( source : Track . Source ) => {
27+ // NOTE: this mapping avoids importing the protocol package as that leads to a significant bundle size increase
28+ switch ( source ) {
29+ case Track . Source . Camera :
30+ return 1 ;
31+ case Track . Source . Microphone :
32+ return 2 ;
33+ case Track . Source . ScreenShare :
34+ return 3 ;
35+ default :
36+ return 0 ;
37+ }
38+ } ;
39+
2640/** @public */
2741export interface ControlBarProps extends React . HTMLAttributes < HTMLDivElement > {
2842 onDeviceError ?: ( error : { source : Track . Source ; error : Error } ) => void ;
@@ -82,9 +96,16 @@ export function ControlBar({
8296 visibleControls . microphone = false ;
8397 visibleControls . screenShare = false ;
8498 } else {
85- visibleControls . camera ??= localPermissions . canPublish ;
86- visibleControls . microphone ??= localPermissions . canPublish ;
87- visibleControls . screenShare ??= localPermissions . canPublish ;
99+ const canPublishSource = ( source : Track . Source ) => {
100+ return (
101+ localPermissions . canPublish &&
102+ ( localPermissions . canPublishSources . length === 0 ||
103+ localPermissions . canPublishSources . includes ( trackSourceToProtocol ( source ) ) )
104+ ) ;
105+ } ;
106+ visibleControls . camera ??= canPublishSource ( Track . Source . Camera ) ;
107+ visibleControls . microphone ??= canPublishSource ( Track . Source . Microphone ) ;
108+ visibleControls . screenShare ??= canPublishSource ( Track . Source . ScreenShare ) ;
88109 visibleControls . chat ??= localPermissions . canPublishData && controls ?. chat ;
89110 }
90111
You can’t perform that action at this time.
0 commit comments