mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 11:42:05 +00:00
Merge pull request #572 from Stremio/feat/streaming-server-url-param
Streaming server url param
This commit is contained in:
commit
239832f2d0
2 changed files with 59 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ const { NotFound } = require('stremio/routes');
|
||||||
const { ToastProvider, TooltipProvider, CONSTANTS, withCoreSuspender } = require('stremio/common');
|
const { ToastProvider, TooltipProvider, CONSTANTS, withCoreSuspender } = require('stremio/common');
|
||||||
const ServicesToaster = require('./ServicesToaster');
|
const ServicesToaster = require('./ServicesToaster');
|
||||||
const DeepLinkHandler = require('./DeepLinkHandler');
|
const DeepLinkHandler = require('./DeepLinkHandler');
|
||||||
|
const SearchParamsHandler = require('./SearchParamsHandler');
|
||||||
const ErrorDialog = require('./ErrorDialog');
|
const ErrorDialog = require('./ErrorDialog');
|
||||||
const withProtectedRoutes = require('./withProtectedRoutes');
|
const withProtectedRoutes = require('./withProtectedRoutes');
|
||||||
const routerViewsConfig = require('./routerViewsConfig');
|
const routerViewsConfig = require('./routerViewsConfig');
|
||||||
|
|
@ -164,6 +165,7 @@ const App = () => {
|
||||||
<TooltipProvider className={styles['tooltip-container']}>
|
<TooltipProvider className={styles['tooltip-container']}>
|
||||||
<ServicesToaster />
|
<ServicesToaster />
|
||||||
<DeepLinkHandler />
|
<DeepLinkHandler />
|
||||||
|
<SearchParamsHandler />
|
||||||
<RouterWithProtectedRoutes
|
<RouterWithProtectedRoutes
|
||||||
className={styles['router']}
|
className={styles['router']}
|
||||||
viewsConfig={routerViewsConfig}
|
viewsConfig={routerViewsConfig}
|
||||||
|
|
|
||||||
57
src/App/SearchParamsHandler.js
Normal file
57
src/App/SearchParamsHandler.js
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
// Copyright (C) 2017-2023 Smart code 203358507
|
||||||
|
|
||||||
|
const React = require('react');
|
||||||
|
const isEqual = require('lodash.isequal');
|
||||||
|
const { withCoreSuspender, useProfile, useToast } = require('stremio/common');
|
||||||
|
const { useServices } = require('stremio/services');
|
||||||
|
|
||||||
|
const SearchParamsHandler = () => {
|
||||||
|
const { core } = useServices();
|
||||||
|
const profile = useProfile();
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
|
const [searchParams, setSearchParams] = React.useState({});
|
||||||
|
|
||||||
|
const onLocationChange = () => {
|
||||||
|
const { origin, hash, search } = window.location;
|
||||||
|
const { searchParams } = new URL(`${origin}${hash.replace('#', '')}${search}`);
|
||||||
|
|
||||||
|
setSearchParams((previousSearchParams) => {
|
||||||
|
const currentSearchParams = Object.fromEntries(searchParams.entries());
|
||||||
|
return isEqual(previousSearchParams, currentSearchParams) ? previousSearchParams : currentSearchParams;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const { streamingServerUrl } = searchParams;
|
||||||
|
|
||||||
|
if (streamingServerUrl) {
|
||||||
|
core.transport.dispatch({
|
||||||
|
action: 'Ctx',
|
||||||
|
args: {
|
||||||
|
action: 'UpdateSettings',
|
||||||
|
args: {
|
||||||
|
...profile.settings,
|
||||||
|
streamingServerUrl,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.show({
|
||||||
|
type: 'success',
|
||||||
|
title: `Using streaming server at ${streamingServerUrl}`,
|
||||||
|
timeout: 4000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [searchParams]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
onLocationChange();
|
||||||
|
window.addEventListener('hashchange', onLocationChange);
|
||||||
|
return () => window.removeEventListener('hashchange', onLocationChange);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = withCoreSuspender(SearchParamsHandler);
|
||||||
Loading…
Reference in a new issue