When running bonob outside of sonos network ability to register with sonos using remote bonob

This commit is contained in:
simojenki
2021-08-06 18:12:55 +10:00
parent 22b8bf76d2
commit 27dc933ee0
8 changed files with 95 additions and 40 deletions

19
src/registrar.ts Normal file
View 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));
};