|
|
|
|
@ -32,9 +32,9 @@ class SocketPoller(threading.Thread):
|
|
|
|
|
self.buf=""
|
|
|
|
|
|
|
|
|
|
def sendData(self, data):
|
|
|
|
|
print "sending data '%s'"%data
|
|
|
|
|
if not '\n' in data:
|
|
|
|
|
data+='\n'
|
|
|
|
|
print "sending data '%s'"%data
|
|
|
|
|
self.sock.sendall(data)
|
|
|
|
|
|
|
|
|
|
class MpvSockParser(object):
|
|
|
|
|
@ -66,7 +66,7 @@ class MpvSockParser(object):
|
|
|
|
|
self.poller.sendData('{"command":["observe_property",3,"filename"]}')
|
|
|
|
|
self.poller.sendData('{"command":["observe_property",4,"duration"]}')
|
|
|
|
|
|
|
|
|
|
self.poller.run()
|
|
|
|
|
self.poller.start()
|
|
|
|
|
|
|
|
|
|
def newData(self, data):
|
|
|
|
|
data = json.loads(data)
|
|
|
|
|
@ -102,13 +102,23 @@ class MpvSockParser(object):
|
|
|
|
|
def processCommand(self, data):
|
|
|
|
|
pass
|
|
|
|
|
def sendCommand(self, command):
|
|
|
|
|
if command[command] == "seek":
|
|
|
|
|
pass
|
|
|
|
|
print "sending command %s"%command
|
|
|
|
|
if command["command"] == "play":
|
|
|
|
|
self.poller.sendData(
|
|
|
|
|
'{ "command": ["set_property", "pause", true] }'
|
|
|
|
|
)
|
|
|
|
|
if command["command"] == "pause":
|
|
|
|
|
self.poller.sendData(
|
|
|
|
|
'{ "command": ["set_property", "pause", false] }'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class WSHandler(WebSocket):
|
|
|
|
|
def handleMessage(self):
|
|
|
|
|
#self.sendMessage(self.data)
|
|
|
|
|
print "got message '%s'"%(self.data)
|
|
|
|
|
global mpvParser
|
|
|
|
|
command = json.loads(self.data)
|
|
|
|
|
print "got command %s"%(command)
|
|
|
|
|
mpvParser.sendCommand(command)
|
|
|
|
|
self.sendMessage('{"null":""}')
|
|
|
|
|
def handleConnected(self):
|
|
|
|
|
global mpvParser
|
|
|
|
|
mpvParser.registerListener(self)
|
|
|
|
|
@ -119,7 +129,7 @@ class WSHandler(WebSocket):
|
|
|
|
|
mpvParser.unregisterListener(self)
|
|
|
|
|
def dataNotify(self, data):
|
|
|
|
|
data['type'] = 'status'
|
|
|
|
|
self.sendMessage(data)
|
|
|
|
|
self.sendMessage(unicode( json.dumps(data) ))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
|
@ -127,5 +137,5 @@ if __name__=='__main__':
|
|
|
|
|
mpvParser = MpvSockParser()
|
|
|
|
|
mpvParser.startPoll()
|
|
|
|
|
|
|
|
|
|
server = SimpleWebSocketServer('', 8000, SimpleEcho)
|
|
|
|
|
server = SimpleWebSocketServer('', 8000, WSHandler)
|
|
|
|
|
server.serveforever()
|
|
|
|
|
|