fix some ap devices not showing up

This commit is contained in:
vapormusic 2022-08-18 23:05:36 +07:00
parent 3d35cb3a54
commit fcc8d20f80

View file

@ -91,38 +91,40 @@ export default class RAOP {
try {
let model = text.filter((u: any) => String(u).startsWith('model='))
let manufacturer = text.filter((u: any) => String(u).startsWith('manufacturer='))
let name = text.filter((u: any) => String(u).startsWith('name='))
if (name.length > 0) {
shown_name = name[0].split("=")[1]
let name1 = text.filter((u: any) => String(u).startsWith('name='))
if (name1.length > 0) {
shown_name = name1[0].split("=")[1]
}
else if (manufacturer.length > 0) {
shown_name = (manufacturer.length > 0 ? manufacturer[0].substring(13) : "") + " " + (model.length > 0 ? model[0].substring(6) : "")
shown_name = (shown_name.trim()).length > 1 ? shown_name : (host ?? "Unknown").replace(".local", "")
}
} catch(e){}
let host_name = (addresses != null && typeof addresses == "object" && addresses.length > 0 ) ? addresses[0] : (typeof addresses == "string" ? addresses : "");
if (
this.castDevices.findIndex((item: any) => {
return item != null && item.name == shown_name && item.port == port && item.host == (addresses ? addresses[0] : "");
return item != null && item.name == shown_name && item.port == port && item.host == host_name;
}) == -1
) {
this.castDevices.push({
name: shown_name,
host: addresses ? addresses[0] : "",
host: host_name,
port: port,
addresses: addresses,
txt: text,
airplay2: airplay2,
});
if (this.devices.indexOf(host) === -1) {
this.devices.push(host);
if (this.devices.indexOf(host_name) === -1) {
this.devices.push(host_name);
}
if (name) {
this._win.webContents.executeJavaScript(`console.log('deviceFound','ip: ${host} name:${name}')`).catch((err: any) => console.error(err));
console.log("deviceFound", host, name);
if (shown_name) {
this._win.webContents.executeJavaScript(`console.log('deviceFound','ip: ${host_name} name:${shown_name}')`).catch((err: any) => console.error(err));
console.log("deviceFound", host_name, shown_name);
}
} else {
this._win.webContents.executeJavaScript(`console.log('deviceFound (added)','ip: ${host} name:${name}')`).catch((err: any) => console.error(err));
console.log("deviceFound (added)", host, name);
this._win.webContents.executeJavaScript(`console.log('deviceFound (added)','ip: ${host_name} name:${shown_name}')`).catch((err: any) => console.error(err));
console.log("deviceFound (added)", host_name, shown_name);
}
}