Add Support for Opening With Streaming Server

This commit is contained in:
Alexandru Branza 2023-05-29 17:29:31 +03:00
parent 8f80d74883
commit a26d000a98
2 changed files with 29 additions and 10 deletions

View file

@ -4,16 +4,20 @@ const React = require('react');
const PropTypes = require('prop-types');
const classnames = require('classnames');
const Icon = require('@stremio/stremio-icons/dom');
const { Button, Image, PlayIconCircleCentered, useProfile, isMobile } = require('stremio/common');
const { Button, Image, PlayIconCircleCentered, useProfile, isMobile, useStreamingServer } = require('stremio/common');
const StreamPlaceholder = require('./StreamPlaceholder');
const styles = require('./styles');
const Stream = ({ className, addonName, name, description, thumbnail, progress, deepLinks, ...props }) => {
const profile = useProfile();
const streamingServer = useStreamingServer();
const haveStreamingServer = streamingServer.settings !== null && streamingServer.settings.type === 'Ready';
const href = React.useMemo(() => {
return deepLinks ?
profile.settings.playerType === 'external' ?
deepLinks.externalPlayer.vlc[isMobile() || 'desktop'] || deepLinks.externalPlayer.href
isMobile() || !haveStreamingServer ?
deepLinks.externalPlayer.vlc[isMobile()] || deepLinks.externalPlayer.streaming
: 'javascript:void(0);' // handled in StreamsList.js onClick
:
typeof deepLinks.player === 'string' ?
deepLinks.player
@ -73,7 +77,7 @@ Stream.propTypes = {
android: PropTypes.string,
desktop: PropTypes.string
},
href: PropTypes.string
streaming: PropTypes.string
})
})
};

View file

@ -27,13 +27,28 @@ const StreamsList = ({ className, ...props }) => {
addon: streams.addon,
streams: streams.content.content.map((stream) => ({
...stream,
onClick: () => {
core.transport.analytics({
event: 'StreamClicked',
args: {
stream
}
});
onClick: (e) => {
if (e.target.getAttribute('href') === 'javascript:void(0);') {
// link does not lead to the player, it is expected to
// open with local video player through the streaming server
core.transport.dispatch({
action: 'StreamingServer',
args: {
action: 'PlayOnDevice',
args: {
device: 'vlc',
source: stream.deepLinks.externalPlayer.streaming
}
}
});
} else {
core.transport.analytics({
event: 'StreamClicked',
args: {
stream
}
});
}
},
addonName: streams.addon.manifest.name
}))