Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casting fixes #623

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 36 additions & 23 deletions app/api/players/ChromecastPlayerProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Client, DefaultMediaReceiver, Player } from "castv2-client";
import mdns, { Browser } from "mdns-js";
import network from "network-address";
import { PlayerProviderInterface, Device } from "./PlayerProviderInterface";
import { PlayerProviderInterface, Device, PlayerKind } from "./PlayerProviderInterface";
import { Subtitle } from "../metadata/Subtitle";
import { Item } from "../metadata/MetadataProviderInterface";

Expand All @@ -25,6 +25,7 @@ const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export default class ChromecastPlayerProvider
implements PlayerProviderInterface {
name = PlayerKind.Chromecast;
provider = "Chromecast";

providerId = "chromecast";
Expand All @@ -36,47 +37,59 @@ export default class ChromecastPlayerProvider
private browser: Browser;

constructor() {
// this.browser = mdns.createBrowser();
// this.browser = mdns.createBrowser(mdns.tcp("airplay"));
this.browser = mdns.createBrowser(mdns.tcp("googlecast"));
this.browser.on("ready", () => {
this.browser.discover();
});

this.browser.on("update", (data: RawDevice | RawDevice[]) => {
if (Array.isArray(data)) {
data?.forEach((device) => {
console.log(device)
this.devices.set(device.fullname, {
id: device.fullname,
address: device.addresses[0],
port: device.port,
name: device.fullname,
});
});
} else {
const device = data;
console.log(device)
this.devices.set(device.fullname, {
id: device.fullname,
address: device.addresses[0],
port: device.port,
name: device.fullname,
});
}
});
}

// @TODO
public async setup() {}
public async pause() {}
public async seek() {}
public async restart() {}

async cleanup() {
if (this.browser) {
this.browser.stop();
}
}

public async getDevices(timeout = 2_000): Promise<Device[]> {
const devices: DeviceMap = new Map<string, Device>();

this.browser.on("update", (data: RawDevice[]) => {
data.forEach((device) => {
devices.set(device.fullname, {
id: device.fullname,
address: device.addresses[0],
port: device.port,
name: "",
});
});
});

public async getDevices(timeout = 5_000): Promise<Device[]> {
await delay(timeout);
this.browser.stop();
this.browser.removeAllListeners();
this.devices = devices;

const deviceList = Array.from(devices.values());

const deviceList = Array.from(this.devices.values());
if (deviceList.length) {
this.selectDevice(deviceList[0].id);
}

return deviceList;
}

private async selectDevice(deviceId: string): Promise<void> {
async selectDevice(deviceId: string): Promise<void> {
const selectedDevice = Array.from(this.devices.values()).find(
(device) => device.id === deviceId
);
Expand Down
2 changes: 1 addition & 1 deletion app/features/item/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultProps = {
runtime: {},
onTrailerClick: () => {},
torrentHealth: "poor",
showTorrentInfo: false,
showTorrentInfo: true,
trailer: "",
seederCount: 0,
rating: 0,
Expand Down
11 changes: 7 additions & 4 deletions app/features/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class ItemComponent extends Component<Props, State> {
this.getAllData(itemId);

this.subtitleServer.startServer();
this.initCastingDevices()
}

// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -580,10 +581,12 @@ class ItemComponent extends Component<Props, State> {
}));
}

async initCastingDevices() {
this.setState({
castingDevices: await this.player.getDevices(),
});
initCastingDevices() {
setInterval(async () => {
this.setState({
castingDevices: await this.player.getDevices(),
});
}, 3_000)
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion app/features/item/SelectPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SelectPlayer = ({ castingDevices, onSelect }: SelectPlayerProps) => (
</DropdownItem>
{castingDevices.map(({ id, name }) => (
<DropdownItem key={id} id={id} name="chromecast" onClick={onSelect}>
{name}
{name || id}
</DropdownItem>
))}
</DropdownMenu>
Expand Down
5 changes: 1 addition & 4 deletions app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import { render } from "react-dom";
import { AppContainer } from "react-hot-loader";
import * as Sentry from "@sentry/electron/dist/renderer";
import Root from "./root";
import { history, configuredStore } from "./store";
Expand All @@ -21,8 +20,6 @@ if (process.env.NODE_ENV !== "production") {
}

render(
<AppContainer>
<Root store={store} history={history} />
</AppContainer>,
<Root store={store} history={history} />,
document.getElementById("root")
);
29 changes: 7 additions & 22 deletions app/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
/* eslint react/jsx-props-no-spreading: off */
import React from "react";
import React, {Suspense, lazy} from "react";
import { Switch, Route, Redirect } from "react-router-dom";
import { Container } from "reactstrap";
import SkeletonLoader from "./features/app/SkeletonLoader";
import App from "./features/app/App";

const LazyItemPage = React.lazy(
() => import(/* webpackChunkName: "ItemPage" */ "./features/item/ItemPage")
);
const LazyHomePage = React.lazy(
() => import(/* webpackChunkName: "HomePage" */ "./features/home/HomePage")
);

export const ItemPage = (props) => (
<React.Suspense fallback={<SkeletonLoader />}>
<LazyItemPage {...props} />
</React.Suspense>
);

export const HomePage = () => (
<React.Suspense fallback={<SkeletonLoader />}>
<LazyHomePage />
</React.Suspense>
);
import LazyItemPage from './features/item/ItemPage'
import LazyHomePage from './features/home/HomePage'

export default function Routes() {
return (
<App>
<Container fluid>
<Suspense fallback={<SkeletonLoader />}>
<Switch>
<Route path="/:view/:itemId" component={ItemPage} />
<Route path="/:view" component={HomePage} />
<Route path="/:view/:itemId" component={LazyItemPage} />
<Route path="/:view" component={LazyHomePage} />
<Redirect to="/home" />
</Switch>
</Suspense>
</Container>
</App>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"react": "^17.0.1",
"react-content-loader": "^5.0.4",
"react-dom": "^17.0.1",
"react-hot-loader": "4.12.21",
"react-hot-loader": "^4.13.0",
"react-notifications-component": "^2.4.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13262,10 +13262,10 @@ react-dom@^17.0.1:
object-assign "^4.1.1"
scheduler "^0.20.1"

react-hot-loader@4.12.21:
version "4.12.21"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.12.21.tgz#332e830801fb33024b5a147d6b13417f491eb975"
integrity sha512-Ynxa6ROfWUeKWsTHxsrL2KMzujxJVPjs385lmB2t5cHUxdoRPGind9F00tOkdc1l5WBleOF4XEAMILY1KPIIDA==
react-hot-loader@^4.13.0:
version "4.13.0"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.13.0.tgz#c27e9408581c2a678f5316e69c061b226dc6a202"
integrity sha512-JrLlvUPqh6wIkrK2hZDfOyq/Uh/WeVEr8nc7hkn2/3Ul0sx1Kr5y4kOGNacNRoj7RhwLNcQ3Udf1KJXrqc0ZtA==
dependencies:
fast-levenshtein "^2.0.6"
global "^4.3.0"
Expand Down