npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kef-wireless-js

v1.0.4

Published

control kef wireless speaker. tested with ls50w

Downloads

1

Readme

KEF wireless speaker JS module

Control and read state from your KEF wireless speakers (tested on ls50w)

This opens a socket and sends and parses the messages needed to communicate with the KEF socket protocol

It's event / callback based. Promise version coming later.

Example Use


//minimum info to connect to speakers. see OPTIONS for more
let kef = new KEF({
    ip: '192.168.1.60'
});


//when the state of the speakers change (volume , source, onoff )
kef.on('state', (data)=>{
    console.log(data);
});

//or get it manually
kef.toJSON();

//or force a query of the speaker
kef.checkState();

//at some point later turn the speakers on or change the source
kef.turnOnOrSwitchSource('AUX');

//or change the volume
kef.changeVolume(1);
kef.changeVolume(-1);

//or set volume manually
kef.setVolume(20);

//and turn them off
kef.turnOff();

Speaker / Module State

to get the current state of the speakers, as we know it, just call toJSON() the retured object looks like:

{
    "volume":40, //1-100, -1 if unknown. the speaker actually goes above 100 for muted states. this corrects for that.
    "muted":false, //true|false, null if unknown
    "source":"AUX", //AUX|OPT|BT|USB|WIFI, -1 if unknown
    "socketState":"socket:connect", //socket:disconnect, socket:connecting, socket:connect, socket:close
    "onoff":1 //1 if on, 0 if off, -1 if we don't know
}

Options

The constructor requiers an options object passed.

let kef = new KEF({
    ip: '192.168.1.60'
});

ip (required)

IP address of the speakers

port (optional, Default: 50001)

port of speakers

retryInterval (optional, milliseconds, Default: 1000)

if unable to connect or becomes disconnected, will retry every interval.

retry (optional, true|false, Default: true)

enable or disable retry socket connection on disconnect

maxVolume (optional, Default: 50)

limit the volume of the speakers. Note: this only limits what we send the speaker. If you use the remote control or on-speaker buttons you can do whatever you want.

checkStateInterval (optional, milliseconds, Default: 0 which is disabled)

this basically checks the speaker state once every x milliseconds. This is helpful if you want to catch changes made external to this module. For example, if you pick up the remote and turn the volume up, you won't know the new state unless you checkState(). This will just check for you.

emitUnchangedState (optional, true|false, Default: false)

if you want the module to always emit the state when we get it, even if it's unchanged. remember, you can always just access toJSON() to get current known state without requesting it from the speaker.

connectOnInstantiation (optional, true|false, Default: true)

connect to the speaker on instantiation. if false, you have to connect it by calling connect() on your kef instance.

Methods

Please note, for anything that takes a callback, it's a callback for the message on the underlying socket.write() not when the speakers have indeed done what we've asked them to do.

I will release a promise version later, but for now, if you want to know when the speaker has done the action you need to wait until the state event is thrown with the state you are waiting for.

The way it works under the hood is that after every request is made to the speakers, the speakers respond with an ack message. After the ack message, the library requests both source and volume info from the speakers and the appropriate state event is then thrown.

connect()

connect the socket. You don't need to call this unless you set connectOnInstantiation option to false.

muteToggle(cb)

equivilent to pressing the mute button.

turnOnOrSwitchSource(source, cb)

switch source. If off, speakers will turn on to the passed source. valid source values are ('AUX', 'WIFI', 'BT', 'USB', 'OPT').

cycleSource(cb)

if the speakers are on and we know what source we're on, this will move to the next source.

turnOff(cb)

equivilent to pressing the mute button.

changeVolume(amount, cb)

pass 1 for volume up and -1 for down

setVolume(val, cb)

absolute volume val

end

sets retry to false and calls a socket.end()

toJSON()

returns the current known state of the speakers. see speaker state above.

Events

socket events

socket:error

socket:disconnect

socket:connecting

socket:connect

socket:close

speaker events

state when we get a new state ( or any state if you set the option )

thanks

  • https://github.com/Gronis/pykef