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 = {
23
23
settings ?: boolean ;
24
24
} ;
25
25
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
+
26
40
/** @public */
27
41
export interface ControlBarProps extends React . HTMLAttributes < HTMLDivElement > {
28
42
onDeviceError ?: ( error : { source : Track . Source ; error : Error } ) => void ;
@@ -82,9 +96,16 @@ export function ControlBar({
82
96
visibleControls . microphone = false ;
83
97
visibleControls . screenShare = false ;
84
98
} 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 ) ;
88
109
visibleControls . chat ??= localPermissions . canPublishData && controls ?. chat ;
89
110
}
90
111
You can’t perform that action at this time.
0 commit comments