soundtouch-api
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

soundtouch-api

npm version

soundtouch-api is a Node.js library that implements the Bose SoundTouch API.

Installation

npm install --save soundtouch-api

Usage

Press the power button for each device in your local network

async function powerAllDevices(): Promise<boolean> {
    const apis: API[] = await APIDiscovery.search(); // find all devices in the local network
    const res = await Promise.all(apis.map((api) => api.pressKey(KeyValue.power)));
    return res.indexOf(false) === -1;
}
// Execute the task
powerAllDevices()
    .then(console.log)
    .catch(console.error)

Get the selected source of the device name's My SoundTouch Speaker

async function getSelectedSource(): Promise<string | undefined> {
    const api: API | undefined = await APIDiscovery.find('My SoundTouch Speaker');
    if(!api) {
        return undefined;
    }
    const nowPlaying: NowPlaying | undefined = await api.getNowPlaying();
    if(!nowPlaying) {
        return undefined;
    }
    return nowPlaying.source;
}
// Execute the task
getSelectedSource()
    .then(console.log)
    .catch(console.error)

Change the volume of a specific device IP on your local network

async function updateVolume(): Promise<number | undefined> {
    const api = new API({
        ip: '192.168.0.20',
        port: 8090,
        name: 'My SoundTouch Speaker'
    });
    const success = await api.setVolume(28);
    if(!success) {
        return undefined;
    }
    const volume: Volume | undefined = await api.getVolume();
    if(!volume) {
        return undefined;
    }
    return volume.actual;
}
// Execute the task
updateVolume()
    .then(console.log)
    .catch(console.error)

More actions are available on the API object.

Readme

Keywords

Package Sidebar

Install

npm i soundtouch-api

Weekly Downloads

15

Version

2.0.0

License

BSD

Unpacked Size

138 kB

Total Files

108

Last publish

Collaborators

  • bbriatte