tests with socketIO / volumio websocket API

This commit is contained in:
2018-11-23 21:53:36 +00:00
parent 414f696065
commit 967968fcd0
+64
View File
@@ -0,0 +1,64 @@
#https://gist.github.com/ivesdebruycker/4b08bdd5415609ce95e597c1d28e9b9e
from socketIO_client import SocketIO, LoggingNamespace
# for REST
#import urllib.request
# clear the queue via REST (there is no websocket endpoint for this)
#contents = urllib.request.urlopen("http://192.168.1.124/api/v1/commands/?cmd=clearQueue").read()
socketIO = SocketIO('192.168.1.124', 3000)
def on_push_state(*args):
#print('state', args)
global status
status = args[0]['status'].encode('ascii', 'ignore')
print(status)
def showResponse(*args):
print('response', args[0])
#socketIO.on('pushState', on_push_state)
#socketIO.emit('getState', '', on_push_state)
#socketIO.emit('play')
#socketIO.on('pushBrowseSources', showResponse)
#socketIO.emit('getBrowseSources')
# doesn't work
#socketIO.on('pushQueue', showResponse)
#socketIO.emit('getQueue')
# removes from queue, but doesn't show response (unicode/version problem? https://github.com/miguelgrinberg/Flask-SocketIO/issues/674#issuecomment-376636659)
#socketIO.on('pushQueue', showResponse)
#socketIO.emit('removeFromQueue', 0)
#curl http://volumio.local/api/v1/getstate
socketIO.emit('clearQueue')
uri = "mnt/NAS/Audio/Singles/Blazin_Squad_-_Flip_Reverse.mp3"
#uri = "spotify:track:4aebBr4JAihzJQR0CiIZJv"
uri = "mnt/NAS/hidrive/Singles/04 - The Funeral.mp3"
socketIO.emit('addToQueue', {'uri':uri})
#socketIO.emit('addToQueue', {'service':'spop','uri':uri})
socketIO.emit('addToQueue', {'service':'webradio','uri':'http://mp3channels.webradio.antenne.de/rockantenne.aac'})
# mit socket-io-tester: Object {uri: "mnt/NAS/hidrive/Singles/04 - The Funeral.mp3"}
socketIO.emit('play')
try:
socketIO.wait()
except KeyboardInterrupt:
pass