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_ID | 246 | service id for sonos
|
||||
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,
|
||||
"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(
|
||||
sonos(SONOS_DEVICE_DISCOVERY, SONOS_SEED_HOST),
|
||||
sonosSystem,
|
||||
bonob,
|
||||
WEB_ADDRESS,
|
||||
new Navidrome(
|
||||
|
||||
@@ -19,7 +19,7 @@ export const BONOB_ACCESS_TOKEN_HEADER = "bonob-access-token";
|
||||
|
||||
function server(
|
||||
sonos: Sonos,
|
||||
bonobService: Service,
|
||||
service: Service,
|
||||
webAddress: string | "http://localhost:4534",
|
||||
musicService: MusicService,
|
||||
linkCodes: LinkCodes = new InMemoryLinkCodes(),
|
||||
@@ -40,12 +40,12 @@ function server(
|
||||
Promise.all([sonos.devices(), sonos.services()]).then(
|
||||
([devices, services]) => {
|
||||
const registeredBonobService = services.find(
|
||||
(it) => it.sid == bonobService.sid
|
||||
(it) => it.sid == service.sid
|
||||
);
|
||||
res.render("index", {
|
||||
devices,
|
||||
services,
|
||||
bonobService,
|
||||
bonobService: service,
|
||||
registeredBonobService,
|
||||
});
|
||||
}
|
||||
@@ -53,7 +53,7 @@ function server(
|
||||
});
|
||||
|
||||
app.post("/register", (_, res) => {
|
||||
sonos.register(bonobService).then((success) => {
|
||||
sonos.register(service).then((success) => {
|
||||
if (success) {
|
||||
res.render("success", {
|
||||
message: `Successfully registered`,
|
||||
@@ -68,7 +68,7 @@ function server(
|
||||
|
||||
app.get(LOGIN_ROUTE, (req, res) => {
|
||||
res.render("login", {
|
||||
bonobService,
|
||||
bonobService: service,
|
||||
linkCode: req.query.linkCode,
|
||||
loginRoute: LOGIN_ROUTE,
|
||||
});
|
||||
@@ -102,10 +102,10 @@ function server(
|
||||
res.type("application/xml").send(`<?xml version="1.0" encoding="utf-8" ?>
|
||||
<stringtables xmlns="http://sonos.com/sonosapi">
|
||||
<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 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>
|
||||
</stringtables>
|
||||
`);
|
||||
|
||||
@@ -156,6 +156,8 @@ export function autoDiscoverySonos(sonosSeedHost?: string): Sonos {
|
||||
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 csrfToken = await axios.get(customd).then((response) =>
|
||||
|
||||
Reference in New Issue
Block a user