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: add Go Live button in the Dev Menu #1112

Merged
merged 1 commit into from
Sep 27, 2023
Merged
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
43 changes: 39 additions & 4 deletions sample-apps/react/react-dogfood/components/DevMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ConstructionIcon from '@mui/icons-material/Construction';
import IconButton from '@mui/material/IconButton';
import DownloadingIcon from '@mui/icons-material/Downloading';
import QueryStatsIcon from '@mui/icons-material/QueryStats';
import LiveTvIcon from '@mui/icons-material/LiveTv';
import CancelPresentationIcon from '@mui/icons-material/CancelPresentation';
import Menu from '@mui/material/Menu';
import Divider from '@mui/material/Divider';
import MenuList from '@mui/material/MenuList';
Expand Down Expand Up @@ -54,6 +56,7 @@ export const DevMenu = () => {
<LogSubscriberStats />
<Divider />
<StartStopBroadcasting />
<GoOrStopLive />
</MenuList>
</Menu>
</div>
Expand Down Expand Up @@ -94,6 +97,38 @@ const StartStopBroadcasting = () => {
);
};

const GoOrStopLive = () => {
const call = useCall();
const { useIsCallLive } = useCallStateHooks();
const isLive = useIsCallLive();
return (
<MenuItem
onClick={() => {
if (!call) return;
if (isLive) {
call.stopLive().catch((err) => {
console.error(`Failed to stop live`, err);
});
} else {
call
.goLive()
.then((res) => {
console.log(`Live started: ${res}`);
})
.catch((err) => {
console.error(`Failed to start live`, err);
});
}
}}
>
<ListItemIcon>
{isLive ? <CancelPresentationIcon /> : <LiveTvIcon />}
</ListItemIcon>
<ListItemText>{isLive ? 'Stop Live' : 'Go Live'}</ListItemText>
</MenuItem>
);
};

// const MigrateToNewSfu = () => {
// const call = useCall();
// return (
Expand Down Expand Up @@ -174,7 +209,7 @@ const RestartPublisher = () => {
<MenuItem
onClick={() => {
if (!call) return;
call['publisher']?.restartIce();
call.publisher?.restartIce();
}}
>
<ListItemIcon>
Expand All @@ -196,7 +231,7 @@ const RestartSubscriber = () => {
<MenuItem
onClick={() => {
if (!call) return;
call['subscriber']?.restartIce();
call.subscriber?.restartIce();
}}
>
<ListItemIcon>
Expand All @@ -213,7 +248,7 @@ const LogPublisherStats = () => {
<MenuItem
onClick={() => {
if (!call) return;
call['publisher']?.getStats().then((stats: RTCStatsReport) => {
call.publisher?.getStats().then((stats: RTCStatsReport) => {
const arr: any = [];
stats.forEach((value) => {
arr.push(value);
Expand Down Expand Up @@ -270,7 +305,7 @@ const LogSubscriberStats = () => {
<MenuItem
onClick={() => {
if (!call) return;
call['subscriber']?.getStats().then((stats: RTCStatsReport) => {
call.subscriber?.getStats().then((stats: RTCStatsReport) => {
const arr: any = [];
stats.forEach((value) => {
arr.push(value);
Expand Down