mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 10:39:57 +00:00
Fix mdns/castv2 uncaught errors
This commit is contained in:
@@ -33,8 +33,17 @@ export default class Session {
|
|||||||
, private sessionId: string
|
, private sessionId: string
|
||||||
, private referenceId: string) {
|
, private referenceId: string) {
|
||||||
|
|
||||||
this.client = new Client();
|
const client = new Client();
|
||||||
this.client.connect({ host, port }, this.onConnect.bind(this));
|
|
||||||
|
client.on("error", err => {
|
||||||
|
console.error(`castv2 error: ${err}`);
|
||||||
|
});
|
||||||
|
client.on("close", () => {
|
||||||
|
// TODO: Don't send new data
|
||||||
|
});
|
||||||
|
|
||||||
|
client.connect({ host, port }, this.onConnect.bind(this));
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
private onConnect () {
|
private onConnect () {
|
||||||
|
|||||||
@@ -76,4 +76,8 @@ export function stopReceiverApp (host: string, port: number) {
|
|||||||
clientConnection.send({ type: "CONNECT" });
|
clientConnection.send({ type: "CONNECT" });
|
||||||
clientReceiver.send({ type: "STOP", requestId: 1 });
|
clientReceiver.send({ type: "STOP", requestId: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on("error", err => {
|
||||||
|
console.error(`castv2 error (stopReceiverApp): ${err}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ import { ReceiverStatus } from "../types";
|
|||||||
import { sendMessage } from "../lib/messaging";
|
import { sendMessage } from "../lib/messaging";
|
||||||
|
|
||||||
|
|
||||||
|
interface CastTxtRecord {
|
||||||
|
id: string; cd: string; rm: string;
|
||||||
|
ve: string; md: string; ic: string;
|
||||||
|
fn: string; ca: string; st: string;
|
||||||
|
bs: string; nf: string; rs: string;
|
||||||
|
}
|
||||||
|
|
||||||
const browser = mdns.createBrowser(mdns.tcp("googlecast"), {
|
const browser = mdns.createBrowser(mdns.tcp("googlecast"), {
|
||||||
resolverSequence: [
|
resolverSequence: [
|
||||||
mdns.rst.DNSServiceResolve()
|
mdns.rst.DNSServiceResolve()
|
||||||
@@ -19,24 +26,26 @@ const browser = mdns.createBrowser(mdns.tcp("googlecast"), {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function onBrowserServiceUp (service: mdns.Service) {
|
function onBrowserServiceUp (service: mdns.Service) {
|
||||||
|
// Ignore without txt record
|
||||||
|
if (!service.txtRecord) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const txtRecord = service.txtRecord as CastTxtRecord;
|
||||||
|
|
||||||
sendMessage({
|
sendMessage({
|
||||||
subject: "main:serviceUp"
|
subject: "main:serviceUp"
|
||||||
, data: {
|
, data: {
|
||||||
host: service.addresses[0]
|
host: service.addresses[0]
|
||||||
, port: service.port
|
, port: service.port
|
||||||
, id: service.txtRecord.id
|
, id: txtRecord.id
|
||||||
, friendlyName: service.txtRecord.fn
|
, friendlyName: txtRecord.fn
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBrowserServiceDown (service: mdns.Service) {
|
function onBrowserServiceDown (service: mdns.Service) {
|
||||||
sendMessage({
|
// TODO: Fix service down detection
|
||||||
subject: "main:serviceDown"
|
|
||||||
, data: {
|
|
||||||
id: service.txtRecord.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.on("serviceUp", onBrowserServiceUp);
|
browser.on("serviceUp", onBrowserServiceUp);
|
||||||
@@ -59,6 +68,10 @@ export function startDiscovery (options: InitializeOptions) {
|
|||||||
const statusListeners = new Map<string, StatusListener>();
|
const statusListeners = new Map<string, StatusListener>();
|
||||||
|
|
||||||
function onStatusBrowserServiceUp (service: mdns.Service) {
|
function onStatusBrowserServiceUp (service: mdns.Service) {
|
||||||
|
if (!service.txtRecord) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { id } = service.txtRecord;
|
const { id } = service.txtRecord;
|
||||||
|
|
||||||
const listener = new StatusListener(
|
const listener = new StatusListener(
|
||||||
@@ -97,12 +110,7 @@ export function startDiscovery (options: InitializeOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onStatusBrowserServiceDown (service: mdns.Service) {
|
function onStatusBrowserServiceDown (service: mdns.Service) {
|
||||||
const { id } = service.txtRecord;
|
// TODO: Fix service down detection
|
||||||
|
|
||||||
if (statusListeners.has(id)) {
|
|
||||||
statusListeners.get(id)!.deregister();
|
|
||||||
statusListeners.delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user