Skip to content

Commit 25064a5

Browse files
authored
only display screen share button if not in mobile browser (#200)
* only display screen share button if not a mobile browser * Add changeset
1 parent ef273a2 commit 25064a5

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

.changeset/poor-fans-grow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@livekit/components-core': patch
3+
'@livekit/components-react': patch
4+
---
5+
6+
Hide screen share button on mobile.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function isWeb(): boolean {
2+
return typeof document !== 'undefined';
3+
}
4+
5+
/**
6+
* Mobile browser detection based on `navigator.userAgent` string.
7+
* Defaults to returning `false` if not in a browser.
8+
*
9+
* @remarks
10+
* This should only be used if feature detection or other methods do not work!
11+
*
12+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#mobile_device_detection
13+
*/
14+
export function isMobileBrowser(): boolean {
15+
return isWeb() ? /Mobi/i.test(window.navigator.userAgent) : false;
16+
}

packages/core/src/helper/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './detectMobileBrowser';

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './constants';
22
export * from './utils';
3+
export * from './helper';
34
export * from './types';
45

56
export * from './components/mediaToggle';

packages/core/src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { PinState, TrackParticipantPair } from './types';
1212
export function kebabize(str: string) {
1313
return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
1414
}
15+
16+
// TODO: If we have utils/helper, we should structure it better to prevent this thing from turning into a dumping ground for all sorts of things.
17+
1518
/**
1619
* Converts a non prefixed CSS class into a prefixed one.
1720
*/

packages/react/src/assets/icons/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ export { default as ScreenShareIcon } from './ScreenShareIcon';
1414
export { default as ScreenShareStopIcon } from './ScreenShareStopIcon';
1515
export { default as SpinnerIcon } from './SpinnerIcon';
1616
export { default as UnfocusToggleIcon } from './UnfocusToggleIcon';
17-
export { default as UserSilhouetteIcon } from './UserSilhouetteIcon';

packages/react/src/prefabs/ControlBar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TrackToggle } from '../components/controls/TrackToggle';
66
import { StartAudio } from '../components/controls/StartAudio';
77
import { ChatIcon, LeaveIcon } from '../assets/icons';
88
import { ChatToggle } from '../components/controls/ChatToggle';
9+
import { isMobileBrowser } from '@livekit/components-core';
910

1011
type ControlBarControls = {
1112
microphone?: boolean;
@@ -57,6 +58,8 @@ export function ControlBar(props: ControlBarProps) {
5758
[variation],
5859
);
5960

61+
const isMobile = React.useMemo(() => isMobileBrowser(), []);
62+
6063
const [isScreenShareEnabled, setIsScreenShareEnabled] = React.useState(false);
6164

6265
const onScreenShareChange = (enabled: boolean) => {
@@ -85,7 +88,7 @@ export function ControlBar(props: ControlBarProps) {
8588
</div>
8689
</div>
8790
)}
88-
{visibleControls.screenShare && (
91+
{visibleControls.screenShare && !isMobile && (
8992
<TrackToggle
9093
source={Track.Source.ScreenShare}
9194
showIcon={showIcon}

0 commit comments

Comments
 (0)