Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom elements to be rendered for the switch camera button #137

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export default class VideoRecorder extends Component {
videoControlsList: PropTypes.string,
/** Use this to disable picture in picture mode on the replaying video element */
disablePictureInPicture: PropTypes.bool,
/** Use this to change what element is rendered for the switch camera view button */
switchCameraViewElement: PropTypes.element,

renderDisconnectedView: PropTypes.func,
renderLoadingView: PropTypes.func,
Expand Down Expand Up @@ -733,6 +735,7 @@ export default class VideoRecorder extends Component {
renderUnsupportedView,
renderErrorView,
renderLoadingView,
switchCameraViewElement,
useVideoInput,
videoClassName
} = this.props
Expand Down Expand Up @@ -803,7 +806,13 @@ export default class VideoRecorder extends Component {
// Enable switch camera button, only if not recording and multiple video sources available
const switchCameraControl =
availableDeviceIds && availableDeviceIds.length >= 2 && !isRecording ? (
<SwitchCameraView onClick={this.handleSwitchCamera} />
switchCameraViewElement ? (
<span onClick={this.handleSwitchCamera}>
{switchCameraViewElement}
</span>
) : (
<SwitchCameraView onClick={this.handleSwitchCamera} />
)
) : null

return (
Expand Down
33 changes: 33 additions & 0 deletions src/video-recorder.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const actionLoggers = {
onRecordingComplete: handleRecordingComplete,
onOpenVideoInput: action('onOpenVideoInput'),
onStopReplaying: action('onStopReplaying'),
onSwitchCamera: action('onSwitchCamera'),
onError: action('onError')
}

Expand Down Expand Up @@ -115,3 +116,35 @@ stories.add(
/>
)
)

stories.add('with custom element used for switch camera view button', () => (
<VideoRecorder
isOnInitially
showReplayControls
switchCameraViewElement={
<svg
width='80'
height='40'
style={{
position: 'absolute',
right: '4px',
bottom: '4px',
zIndex: '10',
cursor: 'pointer'
}}
>
<rect
x='10'
y='10'
width='60'
height='20'
style={{ fill: 'blue', fillOpacity: 0.5 }}
/>
<text x='16' y='24' fill='white'>
Switch
</text>
</svg>
}
{...actionLoggers}
/>
))