mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
When running bonob outside of sonos network ability to register with sonos using remote bonob
This commit is contained in:
14
src/app.ts
14
src/app.ts
@@ -67,6 +67,10 @@ const app = server(
|
||||
true,
|
||||
);
|
||||
|
||||
app.listen(config.port, () => {
|
||||
logger.info(`Listening on ${config.port} available @ ${config.bonobUrl}`);
|
||||
});
|
||||
|
||||
if (config.sonos.autoRegister) {
|
||||
sonosSystem.register(bonob).then((success) => {
|
||||
if (success) {
|
||||
@@ -75,10 +79,12 @@ if (config.sonos.autoRegister) {
|
||||
);
|
||||
}
|
||||
});
|
||||
} else if(config.sonos.deviceDiscovery) {
|
||||
sonosSystem.devices().then(devices => {
|
||||
devices.forEach(d => {
|
||||
logger.info(`Found device ${d.name}(${d.group}) @ ${d.ip}:${d.port}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
app.listen(config.port, () => {
|
||||
logger.info(`Listening on ${config.port} available @ ${config.bonobUrl}`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,26 +1,15 @@
|
||||
import readConfig from "./config";
|
||||
import logger from "./logger";
|
||||
import sonos, { bonobService } from "./sonos";
|
||||
import registrar from "./registrar";
|
||||
import { URLBuilder } from "./url_builder";
|
||||
|
||||
const config = readConfig();
|
||||
const params = process.argv.slice(2);
|
||||
|
||||
const bonob = bonobService(
|
||||
config.sonos.serviceName,
|
||||
config.sonos.sid,
|
||||
config.bonobUrl,
|
||||
"AppLink"
|
||||
);
|
||||
if (params.length != 1) {
|
||||
console.error("Usage: register [URL to bonob]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const sonosSystem = sonos(config.sonos.deviceDiscovery, config.sonos.seedHost);
|
||||
|
||||
sonosSystem.register(bonob).then((success) => {
|
||||
if (success) {
|
||||
logger.info(
|
||||
`Successfully registered ${bonob.name}(SID:${bonob.sid}) with sonos`
|
||||
);
|
||||
process.exit(0);
|
||||
} else {
|
||||
logger.error(`Failed to register ${bonob.name}(SID:${bonob.sid}) with sonos!!`)
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
const bonobUrl = new URLBuilder(params[0]!);
|
||||
registrar(bonobUrl)().then((success) => {
|
||||
if (success) console.log(`Successfully registered bonob @ ${bonobUrl} with sonos`);
|
||||
else console.error(`Failed registering bonob @ ${bonobUrl} with sonos`);
|
||||
});
|
||||
|
||||
19
src/registrar.ts
Normal file
19
src/registrar.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import axios from "axios";
|
||||
import logger from "./logger";
|
||||
import sonos, { bonobService } from "./sonos";
|
||||
import { URLBuilder } from "./url_builder";
|
||||
|
||||
export default (bonobUrl: URLBuilder) => async () => {
|
||||
const about = bonobUrl.append({ pathname: "/about" });
|
||||
logger.info(`Fetching bonob service about from ${about}`);
|
||||
return axios
|
||||
.get(about.href())
|
||||
.then((res) => {
|
||||
if (res.status == 200) return res.data;
|
||||
else throw `Unexpected response status ${res.status} from ${about}`;
|
||||
})
|
||||
.then((about) =>
|
||||
bonobService(about.service.name, about.service.sid, bonobUrl)
|
||||
)
|
||||
.then((bonobService) => sonos(true).register(bonobService));
|
||||
};
|
||||
@@ -101,6 +101,15 @@ function server(
|
||||
);
|
||||
});
|
||||
|
||||
app.get("/about", (_, res) => {
|
||||
return res.send({
|
||||
service: {
|
||||
name: service.name,
|
||||
sid: service.sid
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post(REGISTER_ROUTE, (_, res) => {
|
||||
sonos.register(service).then((success) => {
|
||||
if (success) {
|
||||
|
||||
@@ -132,7 +132,7 @@ const setupDiscovery = (
|
||||
sonosSeedHost?: string
|
||||
): Promise<boolean> => {
|
||||
if (sonosSeedHost == undefined || sonosSeedHost == "") {
|
||||
logger.info("Trying to auto discover sonos devices");
|
||||
logger.info("Trying to discover sonos devices");
|
||||
return manager.InitializeWithDiscovery(10);
|
||||
} else {
|
||||
logger.info(`Trying to discover sonos devices using seed ${sonosSeedHost}`);
|
||||
|
||||
Reference in New Issue
Block a user