mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-18 21:12:13 +00:00
Merge branch 'development' of github.com:Stremio/stremio-web into media-patch
This commit is contained in:
commit
ea3d06311d
15 changed files with 111 additions and 59 deletions
46
package-lock.json
generated
46
package-lock.json
generated
|
|
@ -1833,9 +1833,9 @@
|
|||
"integrity": "sha512-yT3No1gIWKLV2BhQIeSgG94EzXxmEqXJLulO+pFpziqWNUbmmEKeE+nRvW5wtoIK4SLy+v0bLd0b6HBH3KFfWw=="
|
||||
},
|
||||
"@stremio/stremio-core-web": {
|
||||
"version": "0.38.0",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.38.0.tgz",
|
||||
"integrity": "sha512-VAutpvUPzoBJ7U0IigOB6aIPVWLKeTQoAnpccsOLBEDhYUEMAcVqGirRx8Vyz1kEA+lhAQgBsDbBWONPQMONRA==",
|
||||
"version": "0.42.0",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.42.0.tgz",
|
||||
"integrity": "sha512-+DcuMYrneTUHGX+68oSo1Qe+y0CRbzLuyknAM0LsLVuIWviQW/zY9ahecmfRcTfw7skHtJQaDJIznXDQDEKjIg==",
|
||||
"requires": {
|
||||
"@babel/runtime": "7.15.4"
|
||||
},
|
||||
|
|
@ -1856,9 +1856,9 @@
|
|||
"integrity": "sha512-knlcBibqJW2mbEgid6YEeQN9FPkIGAEtozYWqzKWeHd2DPY2nl8kYX2pMQpa2Db/RVSqbVstu/gdey5TtSgGYw=="
|
||||
},
|
||||
"@stremio/stremio-video": {
|
||||
"version": "0.0.19-rc.1",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-video/-/stremio-video-0.0.19-rc.1.tgz",
|
||||
"integrity": "sha512-UiML0reTHcBhb2cddTrw7BqwYnJ7FcjOANltszmcG9Rx6PiJbZdfwZ2CR3VQX91nXbQlpeq81SjPt4WwcdXmuQ==",
|
||||
"version": "0.0.20-rc.4",
|
||||
"resolved": "https://registry.npmjs.org/@stremio/stremio-video/-/stremio-video-0.0.20-rc.4.tgz",
|
||||
"integrity": "sha512-hRVXSH/3MsdQ2GNE56FqaUDT39PELoHV1BGRO9gLPIAJSX+nMlTs1eupGuGVcBdCnqPwEfZyRgpG0lRAmjLrRw==",
|
||||
"requires": {
|
||||
"color": "4.2.3",
|
||||
"deep-freeze": "0.0.1",
|
||||
|
|
@ -2623,9 +2623,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"async": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
|
||||
"integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==",
|
||||
"version": "2.6.4",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
|
||||
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lodash": "^4.17.14"
|
||||
|
|
@ -3725,7 +3725,7 @@
|
|||
"deep-freeze": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/deep-freeze/-/deep-freeze-0.0.1.tgz",
|
||||
"integrity": "sha1-OgsABd4YZygZ39OM0x+RF5yJPoQ="
|
||||
"integrity": "sha512-Z+z8HiAvsGwmjqlphnHW5oz6yWlOwu6EQfFTjmeTWlDeda3FS2yv3jhq35TX/ewmsnqB+RX2IdsIOyjJCQN5tg=="
|
||||
},
|
||||
"deep-is": {
|
||||
"version": "0.1.4",
|
||||
|
|
@ -4992,7 +4992,7 @@
|
|||
"hat": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/hat/-/hat-0.0.3.tgz",
|
||||
"integrity": "sha1-uwFKnmSzeIrtgAWRdBPU/z1QLYo="
|
||||
"integrity": "sha512-zpImx2GoKXy42fVDSEad2BPKuSQdLcqsCYa48K3zHSzM/ugWuYjLDr8IXxpVuL7uCLHw56eaiLxCRthhOzf5ug=="
|
||||
},
|
||||
"he": {
|
||||
"version": "1.2.0",
|
||||
|
|
@ -7375,9 +7375,9 @@
|
|||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
||||
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"mkdirp": {
|
||||
|
|
@ -7484,9 +7484,9 @@
|
|||
}
|
||||
},
|
||||
"node-forge": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz",
|
||||
"integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==",
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz",
|
||||
"integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==",
|
||||
"dev": true
|
||||
},
|
||||
"node-int64": {
|
||||
|
|
@ -8413,7 +8413,7 @@
|
|||
"punycode": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
|
||||
"integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
|
||||
"integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw=="
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.9.6",
|
||||
|
|
@ -8424,7 +8424,7 @@
|
|||
"querystring": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
|
||||
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
|
||||
"integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g=="
|
||||
},
|
||||
"queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
|
|
@ -8973,7 +8973,7 @@
|
|||
"simple-swizzle": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
|
||||
"integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
|
||||
"integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==",
|
||||
"requires": {
|
||||
"is-arrayish": "^0.3.1"
|
||||
},
|
||||
|
|
@ -9076,8 +9076,8 @@
|
|||
}
|
||||
},
|
||||
"spatial-navigation-polyfill": {
|
||||
"version": "git+https://git@github.com/Stremio/spatial-navigation.git#40204ad9942fe786794c62f99ea5ab2b52b24096",
|
||||
"from": "git+https://git@github.com/Stremio/spatial-navigation.git#40204ad9942fe786794c62f99ea5ab2b52b24096"
|
||||
"version": "git+https://git@github.com/Stremio/spatial-navigation.git#64871b1422466f5f45d24ebc8bbd315b2ebab6a6",
|
||||
"from": "git+https://git@github.com/Stremio/spatial-navigation.git#64871b1422466f5f45d24ebc8bbd315b2ebab6a6"
|
||||
},
|
||||
"spdy": {
|
||||
"version": "4.0.2",
|
||||
|
|
@ -9438,7 +9438,7 @@
|
|||
"thirty-two": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/thirty-two/-/thirty-two-1.0.2.tgz",
|
||||
"integrity": "sha1-TKL//AKlEpDSdEueP1V2k8prYno="
|
||||
"integrity": "sha512-OEI0IWCe+Dw46019YLl6V10Us5bi574EvlJEOcAkB29IzQ/mYD1A6RyNHLjZPiHCmuodxvgF6U+vZO1L15lxVA=="
|
||||
},
|
||||
"throat": {
|
||||
"version": "6.0.1",
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
"@babel/runtime": "7.16.0",
|
||||
"@sentry/browser": "6.13.3",
|
||||
"@stremio/stremio-colors": "4.0.1",
|
||||
"@stremio/stremio-core-web": "0.38.0",
|
||||
"@stremio/stremio-core-web": "0.42.0",
|
||||
"@stremio/stremio-icons": "3.0.5",
|
||||
"@stremio/stremio-video": "0.0.19-rc.1",
|
||||
"@stremio/stremio-video": "0.0.20-rc.4",
|
||||
"a-color-picker": "1.2.1",
|
||||
"buffer": "6.0.3",
|
||||
"classnames": "2.3.1",
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
"react": "16.12.0",
|
||||
"react-dom": "16.12.0",
|
||||
"react-focus-lock": "2.2.1",
|
||||
"spatial-navigation-polyfill": "git+https://git@github.com/Stremio/spatial-navigation.git#40204ad9942fe786794c62f99ea5ab2b52b24096"
|
||||
"spatial-navigation-polyfill": "git+https://git@github.com/Stremio/spatial-navigation.git#64871b1422466f5f45d24ebc8bbd315b2ebab6a6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.16.0",
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ const Image = ({ className, src, alt, fallbackSrc, renderFallback, ...props }) =
|
|||
typeof renderFallback === 'function' ?
|
||||
renderFallback()
|
||||
:
|
||||
<img {...props} className={className} src={fallbackSrc} alt={alt} loading={'lazy'} />
|
||||
<img {...props} className={className} src={fallbackSrc} alt={alt} />
|
||||
:
|
||||
<img {...props} className={className} src={src} alt={alt} loading={'lazy'} onError={onError} />;
|
||||
<img {...props} className={className} src={src} alt={alt} onError={onError} />;
|
||||
};
|
||||
|
||||
Image.propTypes = {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ const MetaRow = ({ className, title, message, items, itemComponent, deepLinks })
|
|||
}
|
||||
{
|
||||
deepLinks && (typeof deepLinks.discover === 'string' || typeof deepLinks.library === 'string') ?
|
||||
<Button className={styles['see-all-container']} title={'SEE ALL'} href={deepLinks.discover || deepLinks.library}>
|
||||
<Button className={styles['see-all-container']} title={'SEE ALL'} href={deepLinks.discover || deepLinks.library} tabIndex={-1}>
|
||||
<div className={styles['label']}>SEE ALL</div>
|
||||
<Icon className={styles['icon']} icon={'ic_arrow_thin_right'} />
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const MetaRowPlaceholder = ({ className, title, deepLinks }) => {
|
|||
</div>
|
||||
{
|
||||
deepLinks && typeof deepLinks.discover === 'string' ?
|
||||
<Button className={styles['see-all-container']} title={'SEE ALL'} href={deepLinks.discover}>
|
||||
<Button className={styles['see-all-container']} title={'SEE ALL'} href={deepLinks.discover} tabIndex={-1}>
|
||||
<div className={styles['label']}>SEE ALL</div>
|
||||
<Icon className={styles['icon']} icon={'ic_arrow_thin_right'} />
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ const StreamingServerWarning = ({ className }) => {
|
|||
return (
|
||||
<div className={classnames(className, styles['warning-container'])}>
|
||||
<div className={styles['warning-statement']}>Streaming server is not available.</div>
|
||||
<Button className={styles['warning-button']} title={'Later'} onClick={onLaterClick}>
|
||||
<Button className={styles['warning-button']} title={'Later'} onClick={onLaterClick} tabIndex={-1}>
|
||||
<div className={styles['warning-label']}>Later</div>
|
||||
</Button>
|
||||
<Button className={styles['warning-button']} title={'Dismiss'} onClick={onDismissClick}>
|
||||
<Button className={styles['warning-button']} title={'Dismiss'} onClick={onDismissClick} tabIndex={-1}>
|
||||
<div className={styles['warning-label']}>Dismiss</div>
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
// Copyright (C) 2017-2022 Smart code 203358507
|
||||
|
||||
const isChildVisible = (container, element, threshold) => {
|
||||
const isChildVisible = (container, element) => {
|
||||
const elementTop = element.offsetTop;
|
||||
const elementBottom = element.offsetTop + element.clientHeight;
|
||||
const containerTop = container.scrollTop - threshold;
|
||||
const containerBottom = container.scrollTop + container.clientHeight + threshold;
|
||||
const containerTop = container.scrollTop;
|
||||
const containerBottom = container.scrollTop + container.clientHeight;
|
||||
return (elementTop >= containerTop && elementBottom <= containerBottom) ||
|
||||
(elementTop < containerTop && containerTop < elementBottom) ||
|
||||
(elementTop < containerBottom && containerBottom < elementBottom);
|
||||
};
|
||||
|
||||
const getVisibleChildrenRange = (container, threshold) => {
|
||||
const getVisibleChildrenRange = (container) => {
|
||||
return Array.from(container.children).reduce((result, child, index) => {
|
||||
if (isChildVisible(container, child, threshold)) {
|
||||
if (isChildVisible(container, child)) {
|
||||
if (result === null) {
|
||||
result = {
|
||||
start: index,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const useBoard = require('./useBoard');
|
|||
const useContinueWatchingPreview = require('./useContinueWatchingPreview');
|
||||
const styles = require('./styles');
|
||||
|
||||
const THRESHOLD = 300;
|
||||
const THRESHOLD = 5;
|
||||
|
||||
const Board = () => {
|
||||
const profile = useProfile();
|
||||
|
|
@ -18,13 +18,13 @@ const Board = () => {
|
|||
const boardCatalogsOffset = continueWatchingPreview.libraryItems.length > 0 ? 1 : 0;
|
||||
const scrollContainerRef = React.useRef();
|
||||
const onVisibleRangeChange = React.useCallback(() => {
|
||||
const range = getVisibleChildrenRange(scrollContainerRef.current, THRESHOLD);
|
||||
const range = getVisibleChildrenRange(scrollContainerRef.current);
|
||||
if (range === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const start = Math.max(0, range.start - boardCatalogsOffset);
|
||||
const end = range.end - boardCatalogsOffset;
|
||||
const start = Math.max(0, range.start - boardCatalogsOffset - THRESHOLD);
|
||||
const end = range.end - boardCatalogsOffset + THRESHOLD;
|
||||
if (end < start) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
overflow-y: auto;
|
||||
|
||||
.board-row {
|
||||
padding: 2rem;
|
||||
margin: 4rem 2rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,27 @@ const Video = ({ className, id, title, thumbnail, episode, released, upcoming, w
|
|||
const { core } = useServices();
|
||||
const routeFocused = useRouteFocused();
|
||||
const [menuOpen, , closeMenu, toggleMenu] = useBinaryState(false);
|
||||
const popupLabelOnClick = React.useCallback((event) => {
|
||||
if (!event.nativeEvent.togglePopupPrevented && event.nativeEvent.ctrlKey) {
|
||||
event.preventDefault();
|
||||
toggleMenu();
|
||||
}
|
||||
}, []);
|
||||
const popupLabelOnKeyDown = React.useCallback((event) => {
|
||||
event.nativeEvent.buttonClickPrevented = true;
|
||||
}, []);
|
||||
const popupLabelOnContextMenu = React.useCallback((event) => {
|
||||
if (!event.nativeEvent.togglePopupPrevented && !event.nativeEvent.ctrlKey) {
|
||||
event.preventDefault();
|
||||
toggleMenu();
|
||||
event.nativeEvent.preventDefault();
|
||||
}
|
||||
}, [toggleMenu]);
|
||||
const popupMenuOnContextMenu = React.useCallback((event) => {
|
||||
event.nativeEvent.togglePopupPrevented = true;
|
||||
}, []);
|
||||
const popupMenuOnClick = React.useCallback((event) => {
|
||||
event.nativeEvent.togglePopupPrevented = true;
|
||||
}, []);
|
||||
const toggleWatchedOnClick = React.useCallback((event) => {
|
||||
event.preventDefault();
|
||||
closeMenu();
|
||||
|
|
@ -120,7 +132,7 @@ const Video = ({ className, id, title, thumbnail, episode, released, upcoming, w
|
|||
}, []);
|
||||
const renderMenu = React.useMemo(() => function renderMenu() {
|
||||
return (
|
||||
<div className={styles['context-menu-content']} onContextMenu={popupMenuOnContextMenu}>
|
||||
<div className={styles['context-menu-content']} onContextMenu={popupMenuOnContextMenu} onClick={popupMenuOnClick}>
|
||||
<Button className={styles['context-menu-option-container']} title={'Watch'}>
|
||||
<div className={styles['context-menu-option-label']}>Watch</div>
|
||||
</Button>
|
||||
|
|
@ -149,6 +161,8 @@ const Video = ({ className, id, title, thumbnail, episode, released, upcoming, w
|
|||
scheduled={scheduled}
|
||||
href={href}
|
||||
{...props}
|
||||
onClick={popupLabelOnClick}
|
||||
onKeyDown={popupLabelOnKeyDown}
|
||||
onContextMenu={popupLabelOnContextMenu}
|
||||
open={menuOpen}
|
||||
onCloseRequest={closeMenu}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
.released-container {
|
||||
flex: 1;
|
||||
margin-right: 0.5rem;
|
||||
padding: 0.2rem 0;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
|
|
@ -138,36 +139,37 @@
|
|||
|
||||
.context-menu-container {
|
||||
max-width: calc(90% - 1.5rem);
|
||||
|
||||
|
||||
&.menu-direction-top-left, &.menu-direction-bottom-left {
|
||||
right: 1.5rem;
|
||||
}
|
||||
|
||||
|
||||
&.menu-direction-top-right, &.menu-direction-bottom-right {
|
||||
left: 1.5rem;
|
||||
}
|
||||
|
||||
|
||||
&.menu-direction-top-left, &.menu-direction-top-right {
|
||||
bottom: 90%;
|
||||
}
|
||||
|
||||
|
||||
&.menu-direction-bottom-left, &.menu-direction-bottom-right {
|
||||
top: 90%;
|
||||
}
|
||||
|
||||
|
||||
.context-menu-content {
|
||||
--spatial-navigation-contain: contain;
|
||||
background-color: @color-background-dark1;
|
||||
|
||||
|
||||
.context-menu-option-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
|
||||
|
||||
&:hover, &:focus {
|
||||
background-color: @color-background;
|
||||
}
|
||||
|
||||
|
||||
.context-menu-option-label {
|
||||
font-size: 1rem;
|
||||
max-height: 2.4em;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ const Video = React.forwardRef(({ className, ...props }, ref) => {
|
|||
});
|
||||
}
|
||||
return () => {
|
||||
dispatch({ type: 'command', commandName: 'destroy' });
|
||||
videoRef.current.destroy();
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
overflow-y: auto;
|
||||
|
||||
.search-row {
|
||||
padding: 2rem;
|
||||
margin: 4rem 2rem;
|
||||
}
|
||||
|
||||
.search-hints-container {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function Chromecast() {
|
|||
starting = false;
|
||||
onStateChanged();
|
||||
}
|
||||
function onTransportError(args) {
|
||||
function onTransportInitError(args) {
|
||||
console.error(args);
|
||||
active = false;
|
||||
error = new Error('Google Cast API not available');
|
||||
|
|
@ -68,7 +68,7 @@ function Chromecast() {
|
|||
starting = true;
|
||||
transport = new ChromecastTransport();
|
||||
transport.on('init', onTransportInit);
|
||||
transport.on('error', onTransportError);
|
||||
transport.on('init-error', onTransportInitError);
|
||||
onStateChanged();
|
||||
};
|
||||
this.stop = function() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
const EventEmitter = require('eventemitter3');
|
||||
|
||||
const MESSAGE_NAMESPACE = 'urn:x-cast:com.stremio';
|
||||
const CHUNK_SIZE = 20000;
|
||||
|
||||
let castAPIAvailable = null;
|
||||
const castAPIEvents = new EventEmitter();
|
||||
|
|
@ -32,6 +33,7 @@ const initialize = () => {
|
|||
|
||||
function ChromecastTransport() {
|
||||
const events = new EventEmitter();
|
||||
const chunks = [];
|
||||
|
||||
initialize()
|
||||
.then(() => {
|
||||
|
|
@ -52,11 +54,31 @@ function ChromecastTransport() {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
events.emit('error', error);
|
||||
events.emit('init-error', error);
|
||||
});
|
||||
|
||||
function onMessage(_, message) {
|
||||
events.emit('message', JSON.parse(message));
|
||||
try {
|
||||
const { chunk, last } = JSON.parse(message);
|
||||
chunks.push(chunk);
|
||||
if (!last) {
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
chunks.splice(0, chunks.length);
|
||||
events.emit('message-error', error);
|
||||
return;
|
||||
}
|
||||
|
||||
let parsedMessage;
|
||||
try {
|
||||
parsedMessage = JSON.parse(chunks.splice(0, chunks.length).join(''));
|
||||
} catch (error) {
|
||||
events.emit('message-error', error);
|
||||
return;
|
||||
}
|
||||
|
||||
events.emit('message', parsedMessage);
|
||||
}
|
||||
function onApplicationStatusChanged(event) {
|
||||
events.emit(cast.framework.CastSession.APPLICATION_STATUS_CHANGED, event);
|
||||
|
|
@ -135,7 +157,21 @@ function ChromecastTransport() {
|
|||
this.sendMessage = function(message) {
|
||||
const castSession = cast.framework.CastContext.getInstance().getCurrentSession();
|
||||
if (castSession !== null) {
|
||||
return castSession.sendMessage(MESSAGE_NAMESPACE, message);
|
||||
const serializedMessage = JSON.stringify(message);
|
||||
const chunksCount = Math.ceil(serializedMessage.length / CHUNK_SIZE);
|
||||
const chunks = [];
|
||||
for (let i = 0; i < chunksCount; i++) {
|
||||
const start = i * CHUNK_SIZE;
|
||||
const chunk = serializedMessage.slice(start, start + CHUNK_SIZE);
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
return Promise.all(chunks.map((chunk, index) => {
|
||||
return castSession.sendMessage(MESSAGE_NAMESPACE, {
|
||||
chunk,
|
||||
last: index === chunks.length - 1,
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
return Promise.reject(new Error('Session not started'));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue