mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Ability to auto-regiter with sonos on startup
This commit is contained in:
@@ -45,3 +45,4 @@ BONOB_SONOS_SEED_HOST | undefined | sonos device seed host for discovery, or omm
|
|||||||
BONOB_SONOS_SERVICE_NAME | bonob | service name for sonos
|
BONOB_SONOS_SERVICE_NAME | bonob | service name for sonos
|
||||||
BONOB_SONOS_SERVICE_ID | 246 | service id for sonos
|
BONOB_SONOS_SERVICE_ID | 246 | service id for sonos
|
||||||
BONOB_NAVIDROME_URL | http://localhost:4533 | URL for navidrome
|
BONOB_NAVIDROME_URL | http://localhost:4533 | URL for navidrome
|
||||||
|
BONOB_SONOS_AUTO_REGISTER | false | Whether or not to try and auto-register on startup
|
||||||
|
|||||||
12
src/app.ts
12
src/app.ts
@@ -18,8 +18,18 @@ const bonob = bonobService(
|
|||||||
WEB_ADDRESS,
|
WEB_ADDRESS,
|
||||||
"AppLink"
|
"AppLink"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sonosSystem = sonos(SONOS_DEVICE_DISCOVERY, SONOS_SEED_HOST);
|
||||||
|
if(process.env["BONOB_SONOS_AUTO_REGISTER"] == "true") {
|
||||||
|
sonosSystem.register(bonob).then(success => {
|
||||||
|
if(success) {
|
||||||
|
logger.info(`Successfully registered ${bonob.name}(SID:${bonob.sid}) with sonos`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const app = server(
|
const app = server(
|
||||||
sonos(SONOS_DEVICE_DISCOVERY, SONOS_SEED_HOST),
|
sonosSystem,
|
||||||
bonob,
|
bonob,
|
||||||
WEB_ADDRESS,
|
WEB_ADDRESS,
|
||||||
new Navidrome(
|
new Navidrome(
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const BONOB_ACCESS_TOKEN_HEADER = "bonob-access-token";
|
|||||||
|
|
||||||
function server(
|
function server(
|
||||||
sonos: Sonos,
|
sonos: Sonos,
|
||||||
bonobService: Service,
|
service: Service,
|
||||||
webAddress: string | "http://localhost:4534",
|
webAddress: string | "http://localhost:4534",
|
||||||
musicService: MusicService,
|
musicService: MusicService,
|
||||||
linkCodes: LinkCodes = new InMemoryLinkCodes(),
|
linkCodes: LinkCodes = new InMemoryLinkCodes(),
|
||||||
@@ -40,12 +40,12 @@ function server(
|
|||||||
Promise.all([sonos.devices(), sonos.services()]).then(
|
Promise.all([sonos.devices(), sonos.services()]).then(
|
||||||
([devices, services]) => {
|
([devices, services]) => {
|
||||||
const registeredBonobService = services.find(
|
const registeredBonobService = services.find(
|
||||||
(it) => it.sid == bonobService.sid
|
(it) => it.sid == service.sid
|
||||||
);
|
);
|
||||||
res.render("index", {
|
res.render("index", {
|
||||||
devices,
|
devices,
|
||||||
services,
|
services,
|
||||||
bonobService,
|
bonobService: service,
|
||||||
registeredBonobService,
|
registeredBonobService,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ function server(
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post("/register", (_, res) => {
|
app.post("/register", (_, res) => {
|
||||||
sonos.register(bonobService).then((success) => {
|
sonos.register(service).then((success) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
res.render("success", {
|
res.render("success", {
|
||||||
message: `Successfully registered`,
|
message: `Successfully registered`,
|
||||||
@@ -68,7 +68,7 @@ function server(
|
|||||||
|
|
||||||
app.get(LOGIN_ROUTE, (req, res) => {
|
app.get(LOGIN_ROUTE, (req, res) => {
|
||||||
res.render("login", {
|
res.render("login", {
|
||||||
bonobService,
|
bonobService: service,
|
||||||
linkCode: req.query.linkCode,
|
linkCode: req.query.linkCode,
|
||||||
loginRoute: LOGIN_ROUTE,
|
loginRoute: LOGIN_ROUTE,
|
||||||
});
|
});
|
||||||
@@ -102,10 +102,10 @@ function server(
|
|||||||
res.type("application/xml").send(`<?xml version="1.0" encoding="utf-8" ?>
|
res.type("application/xml").send(`<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<stringtables xmlns="http://sonos.com/sonosapi">
|
<stringtables xmlns="http://sonos.com/sonosapi">
|
||||||
<stringtable rev="1" xml:lang="en-US">
|
<stringtable rev="1" xml:lang="en-US">
|
||||||
<string stringId="AppLinkMessage">Linking sonos with ${bonobService.name}</string>
|
<string stringId="AppLinkMessage">Linking sonos with ${service.name}</string>
|
||||||
</stringtable>
|
</stringtable>
|
||||||
<stringtable rev="1" xml:lang="fr-FR">
|
<stringtable rev="1" xml:lang="fr-FR">
|
||||||
<string stringId="AppLinkMessage">Lier les sonos à la ${bonobService.name}</string>
|
<string stringId="AppLinkMessage">Lier les sonos à la ${service.name}</string>
|
||||||
</stringtable>
|
</stringtable>
|
||||||
</stringtables>
|
</stringtables>
|
||||||
`);
|
`);
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ export function autoDiscoverySonos(sonosSeedHost?: string): Sonos {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(`Registering ${service.name}(SID:${service.sid}) with sonos device ${anyDevice.Name} @ ${anyDevice.Host}`)
|
||||||
|
|
||||||
const customd = `http://${anyDevice.Host}:${anyDevice.Port}/customsd`;
|
const customd = `http://${anyDevice.Host}:${anyDevice.Port}/customsd`;
|
||||||
|
|
||||||
const csrfToken = await axios.get(customd).then((response) =>
|
const csrfToken = await axios.get(customd).then((response) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user