API and WebUI conflict?

So I am trying to listen for a state change via a small hacked together python program. When I run, the initial state comes back alright, but then as soon as I attempt to do anything other than pause via the WebUI I get multiple outputs.

1 from socketIO_client import SocketIO 2 3 socketIO = SocketIO('localhost', 3000) 4 5 def statusInfo(*args): 6 print(args[0]['status'].encode('ascii', 'ignore')) 7 def on_connect(*args): 8 print('Connected') 9 # Listen for connect 10 socketIO.on('connect', on_connect) 11 # Listen for pushState 12 socketIO.on('pushState', statusInfo) 13 # Get initial state 14 socketIO.emit('getState', '', statusInfo) 15 socketIO.wait()


Connected #Initial connection, expected pause #Initial state, expected play #Play via WebUI, expected play #Duplicate play, unexpected pause #Pause via WebUI, expected stop #Next via WebUI, (stop?) unexpected. stop #Duplicate (and multiple) stop, unexpected stop stop stop stop stop play #Play after Next, semi-expected play #Duplicate (multiple) play, unexpected play pause #Pause, expected

Does anyone know what is going on?

It’s normal to get multiple pushState, is it a problem for you?

Ahh… Ok, I was unsure if I was doing something wrong. It is potentially an issue, but I’m sure there is a work-around. All I really want to do is capture the current artist/track and have this information updated when the song changes (via end of song length or skip). Maybe I can figure out a way to capture only the last pushState, or compare the artist/track of any given pushState to the previous pushState and pull only the data from the instance that has changed. I’ll keep hacking away, unless anyone has any insights that could make my life easier.
As always, thanks for the quick response michelangelo.


Yes that’s quite easy, just listen on pushState, if state.artist != currentartist then update and so on…