diff --git a/src/views/Edit/Wizard/index.js b/src/views/Edit/Wizard/index.js
index 71fab1b..1f5ebdc 100644
--- a/src/views/Edit/Wizard/index.js
+++ b/src/views/Edit/Wizard/index.js
@@ -54,6 +54,7 @@ export default function Wizard(props) {
step: 'TYPE',
});
const [$ready, setReady] = React.useState(false);
+ const [$invalid, setInvalid] = React.useState(false);
React.useEffect(() => {
(async () => {
@@ -62,10 +63,16 @@ export default function Wizard(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid === true) {
+ navigate('/', { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const load = async () => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid(true);
return;
}
diff --git a/src/views/Edit/index.js b/src/views/Edit/index.js
index a9a80b4..820a710 100644
--- a/src/views/Edit/index.js
+++ b/src/views/Edit/index.js
@@ -78,6 +78,7 @@ export default function Edit(props) {
target: '',
what: '',
});
+ const [$invalid, setInvalid] = React.useState(false);
React.useEffect(() => {
(async () => {
@@ -86,10 +87,16 @@ export default function Edit(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid === true) {
+ navigate('/', { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const load = async () => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid(true);
return;
}
@@ -383,12 +390,6 @@ export default function Edit(props) {
return null;
}
- const channelid = props.restreamer.SelectChannel(_channelid);
- if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
- return null;
- }
-
let title = Main Source;
if ($data.meta.name.length !== '') {
title = $data.meta.name;
diff --git a/src/views/Main/index.js b/src/views/Main/index.js
index e65219d..ed269b2 100644
--- a/src/views/Main/index.js
+++ b/src/views/Main/index.js
@@ -58,6 +58,7 @@ const useStyles = makeStyles((theme) => ({
export default function Main(props) {
const classes = useStyles();
+ const navigate = useNavigate();
const { channelid: _channelid } = useParams();
const [$state, setState] = React.useState({
ready: false,
@@ -80,8 +81,7 @@ export default function Main(props) {
data: '',
});
const [$config, setConfig] = React.useState(null);
-
- const navigate = useNavigate();
+ const [$invalid, setInvalid] = React.useState(false);
useInterval(async () => {
await update();
@@ -95,6 +95,12 @@ export default function Main(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid === true) {
+ navigate('/', { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const load = async () => {
const config = props.restreamer.ConfigActive();
setConfig(config);
@@ -111,7 +117,7 @@ export default function Main(props) {
const update = async () => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid(true);
return;
}
@@ -275,12 +281,6 @@ export default function Main(props) {
return ;
}
- const channelid = props.restreamer.SelectChannel(_channelid);
- if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
- return null;
- }
-
const storage = $metadata.control.hls.storage;
const channel = props.restreamer.GetChannel(_channelid);
const manifest = props.restreamer.GetChannelAddress('hls+' + storage, _channelid);
diff --git a/src/views/Publication/Add.js b/src/views/Publication/Add.js
index b6ebab6..b8c77c0 100644
--- a/src/views/Publication/Add.js
+++ b/src/views/Publication/Add.js
@@ -53,6 +53,7 @@ export default function Add(props) {
const classes = useStyles();
const { i18n } = useLingui();
const navigate = useNavigate();
+ const [$ready, setReady] = React.useState(false);
const { channelid: _channelid } = useParams();
const notify = React.useContext(NotifyContext);
const [$service, setService] = React.useState('');
@@ -68,6 +69,7 @@ export default function Add(props) {
license: '',
});
const [$saving, setSaving] = React.useState(false);
+ const [$invalid, setInvalid] = React.useState(false);
React.useEffect(() => {
(async () => {
@@ -76,10 +78,16 @@ export default function Add(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid === true) {
+ navigate('/', { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const load = async () => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid(true);
return;
}
@@ -109,6 +117,8 @@ export default function Add(props) {
setLocalSources(localSources);
setSources(helper.createSourcesFromStreams(ingest.streams));
+
+ setReady(true);
};
const handleFilterChange = (event, value) => {
@@ -239,9 +249,7 @@ export default function Add(props) {
H(topic);
};
- const channelid = props.restreamer.SelectChannel(_channelid);
- if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ if ($ready === false) {
return null;
}
diff --git a/src/views/Publication/Edit.js b/src/views/Publication/Edit.js
index 7481b54..37f2d0e 100644
--- a/src/views/Publication/Edit.js
+++ b/src/views/Publication/Edit.js
@@ -83,6 +83,7 @@ export default function Edit(props) {
const [$saving, setSaving] = React.useState(false);
const [$service, setService] = React.useState(null);
const [$serviceSkills, setServiceSkills] = React.useState(null);
+ const [$invalid, setInvalid] = React.useState('');
useInterval(async () => {
await update(false);
@@ -95,17 +96,23 @@ export default function Edit(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid.length !== 0) {
+ navigate($invalid, { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const update = async (isFirst) => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid('/');
return;
}
const proc = await props.restreamer.GetEgress(_channelid, id, ['state']);
if (proc === null) {
notify.Dispatch('warning', 'notfound:egress:' + _service, i18n._(t`Publication service not found`));
- navigate(`/${_channelid}`);
+ setInvalid(`/${_channelid}`);
return;
}
@@ -115,7 +122,7 @@ export default function Edit(props) {
const s = Services.Get(_service);
if (s === null) {
notify.Dispatch('warning', 'notfound:egress:' + _service, i18n._(t`Publication service not found`));
- navigate(`/${_channelid}/`);
+ setInvalid(`/${_channelid}/`);
return null;
}
@@ -365,12 +372,6 @@ export default function Edit(props) {
return null;
}
- const channelid = props.restreamer.SelectChannel(_channelid);
- if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
- return null;
- }
-
const ServiceControl = $service.component;
const title = $settings.name.length === 0 ? $service.name : $settings.name;
diff --git a/src/views/Publication/Player.js b/src/views/Publication/Player.js
index 9f299e1..2e56595 100644
--- a/src/views/Publication/Player.js
+++ b/src/views/Publication/Player.js
@@ -79,6 +79,7 @@ export default function Edit(props) {
title: '',
message: '',
});
+ const [$invalid, setInvalid] = React.useState('');
React.useEffect(() => {
(async () => {
@@ -87,17 +88,23 @@ export default function Edit(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ React.useEffect(() => {
+ if ($invalid.length !== 0) {
+ navigate($invalid, { replace: true });
+ }
+ }, [navigate, $invalid]);
+
const mount = async () => {
const channelid = props.restreamer.SelectChannel(_channelid);
if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
+ setInvalid('/');
return;
}
const proc = await props.restreamer.GetIngest(channelid, ['state', 'metadata']);
if (proc === null) {
notify.Dispatch('warning', 'notfound:ingest', i18n._(t`Main channel not found`));
- navigate(`/${_channelid}/`);
+ setInvalid(`/${_channelid}/`);
return;
}
@@ -306,12 +313,6 @@ export default function Edit(props) {
return null;
}
- const channelid = props.restreamer.SelectChannel(_channelid);
- if (channelid === '' || channelid !== _channelid) {
- navigate('/', { replace: true });
- return null;
- }
-
const storage = $metadata.control.hls.storage;
const manifest = props.restreamer.GetChannelAddress('hls+' + storage, _channelid);
const poster = props.restreamer.GetChannelAddress('snapshot+' + storage, _channelid);