2.0.0 • Published 1 year ago

soundtouch-api v2.0.0

Weekly downloads
28
License
BSD
Repository
github
Last release
1 year ago

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.

2.0.0

1 year ago

1.1.0

2 years ago

1.0.15

4 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago