improve chromecast
This commit is contained in:
parent
f21a13f50a
commit
ab774d7eeb
6 changed files with 64 additions and 16 deletions
|
@ -893,6 +893,14 @@ export class BrowserWindow {
|
|||
app.exit()
|
||||
})
|
||||
|
||||
app.on('before-quit', () => {
|
||||
BrowserWindow.win.webContents.executeJavaScript(`
|
||||
window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem));
|
||||
window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime));
|
||||
window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue.items));
|
||||
ipcRenderer.send('stopGCast','');`)
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on('play', (_event, type, id) => {
|
||||
BrowserWindow.win.webContents.executeJavaScript(`
|
||||
|
@ -1169,17 +1177,22 @@ export class BrowserWindow {
|
|||
*/
|
||||
private static getIP(): string {
|
||||
let ip: string = '';
|
||||
let ip2: any = [];
|
||||
let alias = 0;
|
||||
const ifaces: any = networkInterfaces();
|
||||
for (let dev in ifaces) {
|
||||
ifaces[dev].forEach((details: any) => {
|
||||
if (details.family === 'IPv4') {
|
||||
if (details.family === 'IPv4' && !details.internal) {
|
||||
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;
|
||||
if (!ip.startsWith('192.168.') ||
|
||||
(ip2.startsWith('192.168.') && !ip.startsWith('192.168.')) &&
|
||||
(ip2.startsWith('172.16.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.')) ||
|
||||
(ip2.startsWith('10.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.') && !ip.startsWith('10.'))
|
||||
){ip = details.address;}
|
||||
++alias;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,12 @@ CiderCastController.prototype.sendIp = function(ip) {
|
|||
this.request(data);
|
||||
};
|
||||
|
||||
CiderCastController.prototype.kill = function() {
|
||||
// TODO: Implement Callback
|
||||
let data = {
|
||||
action : "stop"
|
||||
}
|
||||
this.request(data);
|
||||
};
|
||||
|
||||
module.exports = CiderCastController;
|
|
@ -74,4 +74,8 @@ CiderReceiver.prototype.sendIp = function(opts){
|
|||
this.mediaReceiver.sendIp.apply(this.mediaReceiver, arguments);
|
||||
};
|
||||
|
||||
CiderReceiver.prototype.kill = function(opts){
|
||||
this.mediaReceiver.kill.apply(this.mediaReceiver, arguments);
|
||||
};
|
||||
|
||||
module.exports = CiderReceiver;
|
||||
|
|
|
@ -27,6 +27,7 @@ export default class ChromecastPlugin {
|
|||
// private requests = [];
|
||||
// private GCstream = new Stream.PassThrough(),
|
||||
private connectedHosts: any = {};
|
||||
private connectedPlayer: any;
|
||||
// private port = false;
|
||||
// private server = false;
|
||||
// private bufcount = 0;
|
||||
|
@ -185,23 +186,35 @@ export default class ChromecastPlugin {
|
|||
// send websocket ip
|
||||
|
||||
player.sendIp("ws://" + this.getIp() + ":26369");
|
||||
electron.ipcMain.on('stopGCast', (_event) => {
|
||||
player.kill();
|
||||
})
|
||||
electron.app.on('before-quit', (_event) => {
|
||||
player.kill();
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private getIp() {
|
||||
let ip = false;
|
||||
private getIp(){
|
||||
let ip: string = '';
|
||||
let ip2: any = [];
|
||||
let alias = 0;
|
||||
let ifaces: any = os.networkInterfaces();
|
||||
for (var dev in ifaces) {
|
||||
const ifaces: any = os.networkInterfaces();
|
||||
for (let dev in ifaces) {
|
||||
ifaces[dev].forEach((details: any) => {
|
||||
if (details.family === 'IPv4') {
|
||||
if (details.family === 'IPv4' && !details.internal) {
|
||||
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;
|
||||
if (!ip.startsWith('192.168.') ||
|
||||
(ip2.startsWith('192.168.') && !ip.startsWith('192.168.')) &&
|
||||
(ip2.startsWith('172.16.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.')) ||
|
||||
(ip2.startsWith('10.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.') && !ip.startsWith('10.'))
|
||||
){ip = details.address;}
|
||||
++alias;
|
||||
}
|
||||
}
|
||||
|
@ -320,6 +333,11 @@ export default class ChromecastPlugin {
|
|||
|
||||
electron.ipcMain.on('stopGCast', (_event) => {
|
||||
this._win.webContents.setAudioMuted(false);
|
||||
this.activeConnections.forEach((client: any) => {
|
||||
try{
|
||||
client.stop();
|
||||
} catch(e){}
|
||||
})
|
||||
this.activeConnections = [];
|
||||
this.connectedHosts = {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue