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

Feature: Stream video from video devices like webcams or catpure cards #66

Closed
wants to merge 2 commits into from
Closed
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: 11 additions & 0 deletions ui/src/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@material-ui/core';
import CancelPresentationIcon from '@material-ui/icons/CancelPresentation';
import PresentToAllIcon from '@material-ui/icons/PresentToAll';
import VideocamIcon from '@material-ui/icons/Videocam';
import FullScreenIcon from '@material-ui/icons/Fullscreen';
import PeopleIcon from '@material-ui/icons/People';
import ShowMoreIcon from '@material-ui/icons/MoreVert';
Expand Down Expand Up @@ -51,11 +52,13 @@ const flags = (user: RoomUser) => {
export const Room = ({
state,
share,
shareVideoDevice,
stopShare,
setName,
}: {
state: ConnectedRoom;
share: () => void;
shareVideoDevice: () => void;
stopShare: () => void;
setName: (name: string) => void;
}) => {
Expand Down Expand Up @@ -171,6 +174,14 @@ export const Room = ({
</Tooltip>
)}

{!state.hostStream ? (
<Tooltip title="Start Video" arrow>
<IconButton onClick={shareVideoDevice}>
<VideocamIcon fontSize="large" />
</IconButton>
</Tooltip>
) : null}

<Tooltip
classes={{tooltip: classes.noMaxWidth}}
title={
Expand Down
22 changes: 21 additions & 1 deletion ui/src/useRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface UseRoom {
state: RoomState;
room: FCreateRoom;
share: () => void;
shareVideoDevice: () => void;
setName: (name: string) => void;
stopShare: () => void;
}
Expand Down Expand Up @@ -304,6 +305,25 @@ export const useRoom = (): UseRoom => {
conn.current?.send(JSON.stringify({type: 'share', payload: {}}));
};

const shareVideoDevice = async () => {
if (!navigator.mediaDevices) {
enqueueSnackbar(
'Could not start presentation. (mediaDevices undefined) Are you using https?',
{
variant: 'error',
persist: true,
}
);
return;
}
stream.current = await navigator.mediaDevices
// @ts-ignore
.getUserMedia({video: true});
setState((current) => (current ? {...current, hostStream: stream.current} : current));

conn.current?.send(JSON.stringify({type: 'share', payload: {}}));
};

const stopShare = async () => {
Object.values(host.current).forEach((peer) => {
peer.close();
Expand All @@ -326,5 +346,5 @@ export const useRoom = (): UseRoom => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return {state, room, share, stopShare, setName};
return {state, room, share, shareVideoDevice, stopShare, setName};
};