-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@livekit/components-core": patch | ||
"@livekit/components-react": patch | ||
|
||
--- | ||
|
||
Add useStartVideo hook + update livekit client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Room } from 'livekit-client'; | ||
import { log } from '../logger'; | ||
import { roomVideoPlaybackAllowedObservable } from '../observables/room'; | ||
import { prefixClass } from '../styles-interface'; | ||
|
||
export function setupStartVideo() { | ||
const handleStartVideoPlayback = async (room: Room) => { | ||
log.info('Start Video for room: ', room); | ||
await room.startAudio(); | ||
}; | ||
const className: string = prefixClass('start-audio-button'); | ||
return { className, roomVideoPlaybackAllowedObservable, handleStartVideoPlayback }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { setupStartVideo } from '@livekit/components-core'; | ||
import type { Room } from 'livekit-client'; | ||
import * as React from 'react'; | ||
import { useEnsureRoom } from '../context'; | ||
import { mergeProps } from '../mergeProps'; | ||
import { useObservableState } from './internal'; | ||
|
||
/** @alpha */ | ||
export interface UseStartVideoProps { | ||
room?: Room; | ||
props: React.ButtonHTMLAttributes<HTMLButtonElement>; | ||
} | ||
|
||
/** | ||
* In some browsers to start video playback in low power mode, the user must perform a user-initiated event such as clicking a button. | ||
* The `useStartVideo` hook returns an object with a boolean `canPlayVideo` flag | ||
* that indicates whether video playback is allowed in the current context, | ||
* as well as a `startVideo` function that can be called in a button `onClick` callback to start video playback in the current context. | ||
* | ||
* @alpha | ||
*/ | ||
export function useStartVideo({ room, props }: UseStartVideoProps) { | ||
const roomEnsured = useEnsureRoom(room); | ||
const { className, roomVideoPlaybackAllowedObservable, handleStartVideoPlayback } = React.useMemo( | ||
() => setupStartVideo(), | ||
[], | ||
); | ||
const observable = React.useMemo( | ||
() => roomVideoPlaybackAllowedObservable(roomEnsured), | ||
[roomEnsured, roomVideoPlaybackAllowedObservable], | ||
); | ||
const { canPlayVideo } = useObservableState(observable, { | ||
canPlayVideo: roomEnsured.canPlaybackVideo, | ||
}); | ||
|
||
const mergedProps = React.useMemo( | ||
() => | ||
mergeProps(props, { | ||
className, | ||
onClick: () => { | ||
handleStartVideoPlayback(roomEnsured); | ||
}, | ||
style: { display: canPlayVideo ? 'none' : 'block' }, | ||
}), | ||
[props, className, canPlayVideo, handleStartVideoPlayback, roomEnsured], | ||
); | ||
|
||
return { mergedProps, canPlayVideo }; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.