Merge branch 'upcoming' of https://github.com/ciderapp/Cider into upcoming

This commit is contained in:
child_duckling 2022-01-21 23:27:59 -08:00
commit 6570043ab0
2 changed files with 52 additions and 14 deletions

View file

@ -37,6 +37,7 @@
"express": "^4.17.2",
"get-port": "^5.1.1",
"lastfmapi": "^0.1.1",
"mdns-js": "github:bitfocus/node-mdns-js",
"mpris-service": "^2.1.2",
"music-metadata": "^7.11.4",
"qrcode": "^1.5.0",

View file

@ -103,6 +103,9 @@ export class Win {
// Register listeners on Window to track size and position of the Window.
windowState.manage(this.win);
// Start Remote Discovery
this.broadcastRemote()
return this.win;
}
@ -198,20 +201,23 @@ export class Win {
*/
const remote = express();
remote.use(express.static(path.join(this.paths.srcPath, "./web-remote/")))
remote.listen(this.remotePort, () => {
console.log(`Cider remote port: ${this.remotePort}`);
if (firstRequest) {
console.log("---- Ignore Me ;) ---");
qrcode.generate(`http://${os.hostname}:${this.remotePort}`);
console.log("---- Ignore Me ;) ---");
/*
*
* USING https://www.npmjs.com/package/qrcode-terminal for terminal
* WE SHOULD USE https://www.npmjs.com/package/qrcode for the remote (or others) for showing to user via an in-app dialog
* -@quacksire
*/
}
firstRequest = false;
getPort({port: 6942}).then((port) => {
this.remotePort = port;
remote.listen(this.remotePort, () => {
console.log(`Cider remote port: ${this.remotePort}`);
if (firstRequest) {
console.log("---- Ignore Me ;) ---");
qrcode.generate(`http://${os.hostname}:${this.remotePort}`);
console.log("---- Ignore Me ;) ---");
/*
*
* USING https://www.npmjs.com/package/qrcode-terminal for terminal
* WE SHOULD USE https://www.npmjs.com/package/qrcode for the remote (or others) for showing to user via an in-app dialog
* -@quacksire
*/
}
firstRequest = false;
})
})
}
@ -477,4 +483,35 @@ export class Win {
return { action: "deny" };
});
}
private async broadcastRemote() {
function getIp() {
let ip :any = false;
let alias = 0;
const ifaces: any = os.networkInterfaces() ;
for (var dev in ifaces) {
ifaces[dev].forEach( (details: any) => {
if (details.family === 'IPv4') {
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
if (details.address.substring(0, 8) === '192.168.' ||
details.address.substring(0, 7) === '172.16.' ||
details.address.substring(0, 3) === '10.'
) {
ip = details.address;
++alias;
}
}
}
}) ;
}
return ip;
}
const myString = `http://${getIp()}:${this.remotePort}`;
var mdns = require('mdns-js');
const encoded = new Buffer(myString).toString('base64');
var x = mdns.tcp('cider-remote');
let server2 = mdns.createAdvertisement(x, `${await getPort({port: 3839})}`, { name: encoded });
server2.start();
console.log('remote broadcasted')
}
}