reload streaming server if not initialized

This commit is contained in:
nklhrstv 2020-02-15 12:18:47 +02:00
parent 6ef88f0609
commit ac46d0ebdb

View file

@ -1,3 +1,5 @@
const React = require('react');
const { useServices } = require('stremio/services');
const { useModelState } = require('stremio/common');
const initStreamingServer = () => ({
@ -6,9 +8,24 @@ const initStreamingServer = () => ({
});
const useStreamingServer = () => {
const { core } = useServices();
const loadStreamingServerAction = React.useMemo(() => {
const streamingServer = core.getState('streaming_server');
if (streamingServer.selected === null) {
return {
action: 'StreamingServer',
args: {
action: 'Reload'
}
};
} else {
return null;
}
}, []);
const streamingServer = useModelState({
model: 'streaming_server',
init: initStreamingServer,
action: loadStreamingServerAction
});
return streamingServer;
};