mdns/.local address prep + qrcode for remote url?
This commit is contained in:
parent
6f95494587
commit
80a9d79098
2 changed files with 42 additions and 19 deletions
|
@ -33,8 +33,10 @@
|
||||||
"express": "^4.17.2",
|
"express": "^4.17.2",
|
||||||
"get-port": "^5.1.1",
|
"get-port": "^5.1.1",
|
||||||
"lastfmapi": "^0.1.1",
|
"lastfmapi": "^0.1.1",
|
||||||
|
"mdns": "^2.7.2",
|
||||||
"mpris-service": "^2.1.2",
|
"mpris-service": "^2.1.2",
|
||||||
"music-metadata": "^7.11.4",
|
"music-metadata": "^7.11.4",
|
||||||
|
"qrcode-terminal": "^0.12.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"source-map-support": "^0.5.21",
|
"source-map-support": "^0.5.21",
|
||||||
|
|
|
@ -12,6 +12,8 @@ const { writeFile, writeFileSync, existsSync, mkdirSync } = require('fs');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const mpris = require('./mpris');
|
const mpris = require('./mpris');
|
||||||
const mm = require('music-metadata');
|
const mm = require('music-metadata');
|
||||||
|
const mdns = require('mdns')
|
||||||
|
const qrcode = require('qrcode-terminal')
|
||||||
const fetch = require('electron-fetch').default;
|
const fetch = require('electron-fetch').default;
|
||||||
const { Stream } = require('stream');
|
const { Stream } = require('stream');
|
||||||
|
|
||||||
|
@ -84,8 +86,7 @@ const CiderBase = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead
|
// intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead
|
||||||
win.webContents.session.webRequest.onBeforeRequest(
|
win.webContents.session.webRequest.onBeforeRequest({
|
||||||
{
|
|
||||||
urls: ["https://*/*.js"]
|
urls: ["https://*/*.js"]
|
||||||
},
|
},
|
||||||
(details, callback) => {
|
(details, callback) => {
|
||||||
|
@ -259,8 +260,7 @@ const CiderBase = {
|
||||||
if (url.includes("apple") || url.includes("localhost")) {
|
if (url.includes("apple") || url.includes("localhost")) {
|
||||||
return { action: "allow" }
|
return { action: "allow" }
|
||||||
}
|
}
|
||||||
shell.openExternal(url).catch(() => {
|
shell.openExternal(url).catch(() => {})
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
action: 'deny'
|
action: 'deny'
|
||||||
}
|
}
|
||||||
|
@ -374,20 +374,41 @@ const CiderBase = {
|
||||||
const webRemotePath = path.join(__dirname, '../renderer/');
|
const webRemotePath = path.join(__dirname, '../renderer/');
|
||||||
webapp.set("views", path.join(webRemotePath, "views"));
|
webapp.set("views", path.join(webRemotePath, "views"));
|
||||||
webapp.set("view engine", "ejs");
|
webapp.set("view engine", "ejs");
|
||||||
|
let firstRequest = true
|
||||||
|
//const webRemoteMDNS = mdns.createAdvertisement(mdns.tcp('https'), 9000, { name: "cider", domain: 'local' })
|
||||||
|
//webRemoteMDNS.start()
|
||||||
|
//* Prep for remote -quack
|
||||||
webapp.use(function(req, res, next) {
|
webapp.use(function(req, res, next) {
|
||||||
// if not localhost
|
// if not localhost
|
||||||
if (req.url.includes("audio.webm") || (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider"))) {
|
if (req.url.includes("audio.webm") || (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider"))) {
|
||||||
next();
|
next();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log(req.get('host'))
|
||||||
|
res.redirect("https://discord.gg/applemusic")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
webapp.use(express.static(webRemotePath));
|
webapp.use(express.static(webRemotePath));
|
||||||
webapp.get('/', function(req, res) {
|
webapp.get('/', function(req, res) {
|
||||||
|
//if (!req.headers["user-agent"].includes("Cider"))
|
||||||
//res.sendFile(path.join(webRemotePath, 'index_old.html'));
|
//res.sendFile(path.join(webRemotePath, 'index_old.html'));
|
||||||
|
if (firstRequest) {
|
||||||
|
console.log("---- Ignore Me ;) ---")
|
||||||
|
qrcode.generate(`http://${os.hostname}:9000`) //Prep for remote
|
||||||
|
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)
|
||||||
|
* -quack
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
firstRequest = false
|
||||||
|
|
||||||
res.render("main", CiderBase.EnvironmentVariables)
|
res.render("main", CiderBase.EnvironmentVariables)
|
||||||
});
|
});
|
||||||
webapp.get('/audio.webm', function(req, res) {
|
webapp.get('/audio.webm', function(req, res) {
|
||||||
|
console.log('hi')
|
||||||
try {
|
try {
|
||||||
req.connection.setTimeout(Number.MAX_SAFE_INTEGER);
|
req.connection.setTimeout(Number.MAX_SAFE_INTEGER);
|
||||||
// CiderBase.requests.push({req: req, res: res});
|
// CiderBase.requests.push({req: req, res: res});
|
||||||
|
@ -407,7 +428,7 @@ const CiderBase = {
|
||||||
} catch (ex) { console.log(ex) }
|
} catch (ex) { console.log(ex) }
|
||||||
});
|
});
|
||||||
webapp.listen(CiderBase.clientPort, function() {
|
webapp.listen(CiderBase.clientPort, function() {
|
||||||
console.log(`Cider client port: ${CiderBase.clientPort}`);
|
console.log(`Cider hosted on: ${CiderBase.clientPort}`);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue