svrooij / node-sonos-ts

:speaker: Sonos control library, use this library in your own appliction.
https://sonos-ts.svrooij.io/
MIT License
81 stars 18 forks source link

Check event property name #78

Closed hklages closed 3 years ago

hklages commented 3 years ago
playerKueche.Events.on('x', value => {
      node.send({ payload: value, topic: 'x' })
    })
 playerKueche.Events.on(SonosEvents.y, value => {
      node.send({ payload: value, topic: 'y' })
    })

does not provide any error message. Do I have to check the right "name"? Or is there something wrong in the code?

svrooij commented 3 years ago

I've used a library to specify which events are available, this is how it looks like in VSCode.

image

So while I'm editing a .js file, that references the complied library, I'm still getting this extra information. I think it doesn't enforce which events you subscribe to.

Can you tell your environment that you're dealing with an object that is an instance of SonosDevice that might give you the same features?

hklages commented 3 years ago

I also use VSCode and the screen is visible - but not so easy to understand for instance ... 6 more ...

Is the following correct:

SonosEvents, from RenderingControl: Mute, Volume but NOT Bass, Treble, Loudness, DialogLevel, SubGain, NightMode

SonosEvents from AVTransportState: CurrentTrackMetaData, CurrentTrackUri, EnqueuedTransportUriMetadata, EnqueuedTransportUri, NextTrackMetadata, NextTrackUri - but not TransportStatus, CurrentPlayMode, CurrentCrossfadeMode, CurrentTransportActions, ...

and you renamed TransportState to CurrentTransportState.

svrooij commented 3 years ago

The events part could use some extra explanation, open to PR :wink:. I started somewhere and then I decided that they should be named differently. But renaming the Enums would break existing functionality, and that isn't something I would like to do.

svrooij commented 3 years ago

@hklages what do you think about https://github.com/KeesCBakker/Strongly-Typed-Events-for-TypeScript/blob/master/documentation/HowToAddAnEventToAClass.md

That looks like a no more mistakes eventemitter

hklages commented 3 years ago

For me this is not any more an issue: I only use const { SonosDevice, SonosEventListener } = require('@svrooij/sonos/lib') and as service serviceEvent. Thats realy easy - thanks to your package :-)

serviceArray.forEach(async function (serviceName) {
    await player[serviceName].Events.on('serviceEvent',
      sendServiceMsgs.bind(this, serviceName, eventsByServices[serviceName], outputs))
    debug('subscribed to >>%s', serviceName)
  })

Then I pick the properties I need, combine them and emit them to Node-RED output lines. Thats all done in sendServiceMsgs

I hope to get more information about interesting use cases and the required properties / what combination during the next months. Then I can give more suggestions about bundling properties to "events".

It is difficult for me to comment the above link - my TypeScript knowledge is not sufficient to understand the impact on stability, reliability.

svrooij commented 3 years ago

No idea on how to check. re-open with ideas on how to check