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.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) => {
|
ipcMain.on('play', (_event, type, id) => {
|
||||||
BrowserWindow.win.webContents.executeJavaScript(`
|
BrowserWindow.win.webContents.executeJavaScript(`
|
||||||
|
@ -1169,17 +1177,22 @@ export class BrowserWindow {
|
||||||
*/
|
*/
|
||||||
private static getIP(): string {
|
private static getIP(): string {
|
||||||
let ip: string = '';
|
let ip: string = '';
|
||||||
|
let ip2: any = [];
|
||||||
let alias = 0;
|
let alias = 0;
|
||||||
const ifaces: any = networkInterfaces();
|
const ifaces: any = networkInterfaces();
|
||||||
for (let dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
ifaces[dev].forEach((details: any) => {
|
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 (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
|
||||||
if (details.address.substring(0, 8) === '192.168.' ||
|
if (details.address.substring(0, 8) === '192.168.' ||
|
||||||
details.address.substring(0, 7) === '172.16.' ||
|
details.address.substring(0, 7) === '172.16.' ||
|
||||||
details.address.substring(0, 3) === '10.'
|
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;
|
++alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,12 @@ CiderCastController.prototype.sendIp = function(ip) {
|
||||||
this.request(data);
|
this.request(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CiderCastController.prototype.kill = function() {
|
||||||
|
// TODO: Implement Callback
|
||||||
|
let data = {
|
||||||
|
action : "stop"
|
||||||
|
}
|
||||||
|
this.request(data);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = CiderCastController;
|
module.exports = CiderCastController;
|
|
@ -74,4 +74,8 @@ CiderReceiver.prototype.sendIp = function(opts){
|
||||||
this.mediaReceiver.sendIp.apply(this.mediaReceiver, arguments);
|
this.mediaReceiver.sendIp.apply(this.mediaReceiver, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CiderReceiver.prototype.kill = function(opts){
|
||||||
|
this.mediaReceiver.kill.apply(this.mediaReceiver, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = CiderReceiver;
|
module.exports = CiderReceiver;
|
||||||
|
|
|
@ -27,6 +27,7 @@ export default class ChromecastPlugin {
|
||||||
// private requests = [];
|
// private requests = [];
|
||||||
// private GCstream = new Stream.PassThrough(),
|
// private GCstream = new Stream.PassThrough(),
|
||||||
private connectedHosts: any = {};
|
private connectedHosts: any = {};
|
||||||
|
private connectedPlayer: any;
|
||||||
// private port = false;
|
// private port = false;
|
||||||
// private server = false;
|
// private server = false;
|
||||||
// private bufcount = 0;
|
// private bufcount = 0;
|
||||||
|
@ -185,23 +186,35 @@ export default class ChromecastPlugin {
|
||||||
// send websocket ip
|
// send websocket ip
|
||||||
|
|
||||||
player.sendIp("ws://" + this.getIp() + ":26369");
|
player.sendIp("ws://" + this.getIp() + ":26369");
|
||||||
|
electron.ipcMain.on('stopGCast', (_event) => {
|
||||||
|
player.kill();
|
||||||
|
})
|
||||||
|
electron.app.on('before-quit', (_event) => {
|
||||||
|
player.kill();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getIp(){
|
private getIp(){
|
||||||
let ip = false;
|
let ip: string = '';
|
||||||
|
let ip2: any = [];
|
||||||
let alias = 0;
|
let alias = 0;
|
||||||
let ifaces: any = os.networkInterfaces();
|
const ifaces: any = os.networkInterfaces();
|
||||||
for (var dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
ifaces[dev].forEach((details: any) => {
|
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 (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
|
||||||
if (details.address.substring(0, 8) === '192.168.' ||
|
if (details.address.substring(0, 8) === '192.168.' ||
|
||||||
details.address.substring(0, 7) === '172.16.' ||
|
details.address.substring(0, 7) === '172.16.' ||
|
||||||
details.address.substring(0, 3) === '10.'
|
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;
|
++alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,6 +333,11 @@ export default class ChromecastPlugin {
|
||||||
|
|
||||||
electron.ipcMain.on('stopGCast', (_event) => {
|
electron.ipcMain.on('stopGCast', (_event) => {
|
||||||
this._win.webContents.setAudioMuted(false);
|
this._win.webContents.setAudioMuted(false);
|
||||||
|
this.activeConnections.forEach((client: any) => {
|
||||||
|
try{
|
||||||
|
client.stop();
|
||||||
|
} catch(e){}
|
||||||
|
})
|
||||||
this.activeConnections = [];
|
this.activeConnections = [];
|
||||||
this.connectedHosts = {};
|
this.connectedHosts = {};
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,8 @@ const CiderAudio = {
|
||||||
case "data":
|
case "data":
|
||||||
const audioData = data.audioBuffer;
|
const audioData = data.audioBuffer;
|
||||||
const bufferSize = data.bufferSize;
|
const bufferSize = data.bufferSize;
|
||||||
ipcRenderer.send('writeWAV', audioData[0], audioData[1], bufferSize);
|
if((audioData[0]).some(item => item !== 0) || (audioData[0]).some(item => item !== 0)){
|
||||||
|
ipcRenderer.send('writeWAV', audioData[0], audioData[1], bufferSize);}
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -643,11 +643,6 @@ const app = new Vue({
|
||||||
this.library.albums.displayListing = this.library.albums.listing
|
this.library.albums.displayListing = this.library.albums.listing
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = function (e) {
|
|
||||||
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))
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof MusicKit.PlaybackBitrate[app.cfg.audio.quality] !== "string") {
|
if (typeof MusicKit.PlaybackBitrate[app.cfg.audio.quality] !== "string") {
|
||||||
app.mk.bitrate = MusicKit.PlaybackBitrate[app.cfg.audio.quality]
|
app.mk.bitrate = MusicKit.PlaybackBitrate[app.cfg.audio.quality]
|
||||||
|
@ -2613,6 +2608,7 @@ const app = new Vue({
|
||||||
req.open('GET', url, true);
|
req.open('GET', url, true);
|
||||||
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||||
req.onload = function () {
|
req.onload = function () {
|
||||||
|
try{
|
||||||
let jsonResponse = JSON.parse(this.responseText);
|
let jsonResponse = JSON.parse(this.responseText);
|
||||||
let status2 = jsonResponse["message"]["header"]["status_code"];
|
let status2 = jsonResponse["message"]["header"]["status_code"];
|
||||||
if (status2 == 200) {
|
if (status2 == 200) {
|
||||||
|
@ -2635,7 +2631,10 @@ const app = new Vue({
|
||||||
// console.log('token 4xx');
|
// console.log('token 4xx');
|
||||||
getToken(mode, track, artist, songid, lang, time)
|
getToken(mode, track, artist, songid, lang, time)
|
||||||
}
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log('error');
|
||||||
|
app.loadAMLyrics();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
req.onerror = function () {
|
req.onerror = function () {
|
||||||
console.log('error');
|
console.log('error');
|
||||||
|
@ -2656,6 +2655,7 @@ const app = new Vue({
|
||||||
req.open('GET', url, true);
|
req.open('GET', url, true);
|
||||||
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||||
req.onload = function () {
|
req.onload = function () {
|
||||||
|
try{
|
||||||
let jsonResponse = JSON.parse(this.responseText);
|
let jsonResponse = JSON.parse(this.responseText);
|
||||||
console.log(jsonResponse);
|
console.log(jsonResponse);
|
||||||
let status1 = jsonResponse["message"]["header"]["status_code"];
|
let status1 = jsonResponse["message"]["header"]["status_code"];
|
||||||
|
@ -2733,6 +2733,9 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
} else { //4xx rejected
|
} else { //4xx rejected
|
||||||
getToken(1, track, artist, '', lang, time);
|
getToken(1, track, artist, '', lang, time);
|
||||||
|
}}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
app.loadAMLyrics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.onerror = function () {
|
req.onerror = function () {
|
||||||
|
@ -2751,6 +2754,7 @@ const app = new Vue({
|
||||||
req2.open('GET', url2, true);
|
req2.open('GET', url2, true);
|
||||||
req2.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
req2.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||||
req2.onload = function () {
|
req2.onload = function () {
|
||||||
|
try{
|
||||||
let jsonResponse2 = JSON.parse(this.responseText);
|
let jsonResponse2 = JSON.parse(this.responseText);
|
||||||
console.log(jsonResponse2);
|
console.log(jsonResponse2);
|
||||||
let status2 = jsonResponse2["message"]["header"]["status_code"];
|
let status2 = jsonResponse2["message"]["header"]["status_code"];
|
||||||
|
@ -2776,7 +2780,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
} else { //4xx rejected
|
} else { //4xx rejected
|
||||||
getToken(2, '', '', id, lang, '');
|
getToken(2, '', '', id, lang, '');
|
||||||
}
|
}}catch(e){}
|
||||||
}
|
}
|
||||||
req2.send();
|
req2.send();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue