Added some extra formating
This commit is contained in:
parent
22b426a5ea
commit
68486f1e43
@ -1,4 +1,4 @@
|
|||||||
#coding:utf8
|
# coding:utf8
|
||||||
from twisted.protocols.basic import LineReceiver
|
from twisted.protocols.basic import LineReceiver
|
||||||
import json
|
import json
|
||||||
import syncplay
|
import syncplay
|
||||||
@ -6,6 +6,7 @@ from functools import wraps
|
|||||||
import time
|
import time
|
||||||
from syncplay.messages import getMessage
|
from syncplay.messages import getMessage
|
||||||
|
|
||||||
|
|
||||||
class JSONCommandProtocol(LineReceiver):
|
class JSONCommandProtocol(LineReceiver):
|
||||||
def handleMessages(self, messages):
|
def handleMessages(self, messages):
|
||||||
for message in messages.iteritems():
|
for message in messages.iteritems():
|
||||||
@ -21,7 +22,7 @@ class JSONCommandProtocol(LineReceiver):
|
|||||||
elif command == "Error":
|
elif command == "Error":
|
||||||
self.handleError(message[1])
|
self.handleError(message[1])
|
||||||
else:
|
else:
|
||||||
self.dropWithError(getMessage("en", "unknown-command-server-error").format(message[1])) #TODO: log, not drop
|
self.dropWithError(getMessage("en", "unknown-command-server-error").format(message[1])) # TODO: log, not drop
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -48,6 +49,7 @@ class JSONCommandProtocol(LineReceiver):
|
|||||||
def dropWithError(self, error):
|
def dropWithError(self, error):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class SyncClientProtocol(JSONCommandProtocol):
|
class SyncClientProtocol(JSONCommandProtocol):
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self._client = client
|
self._client = client
|
||||||
@ -187,7 +189,7 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
def handleHttpRequest(self, request):
|
def handleHttpRequest(self, request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def sendState(self, position, paused, doSeek, latencyCalculation, stateChange = False):
|
def sendState(self, position, paused, doSeek, latencyCalculation, stateChange=False):
|
||||||
state = {}
|
state = {}
|
||||||
positionAndPausedIsSet = position is not None and paused is not None
|
positionAndPausedIsSet = position is not None and paused is not None
|
||||||
clientIgnoreIsNotSet = self.clientIgnoringOnTheFly == 0 or self.serverIgnoringOnTheFly != 0
|
clientIgnoreIsNotSet = self.clientIgnoringOnTheFly == 0 or self.serverIgnoringOnTheFly != 0
|
||||||
@ -210,7 +212,7 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
self.sendMessage({"State": state})
|
self.sendMessage({"State": state})
|
||||||
|
|
||||||
def handleError(self, error):
|
def handleError(self, error):
|
||||||
self.dropWithError(error["message"]) #TODO: more processing and fallbacking
|
self.dropWithError(error["message"]) # TODO: more processing and fallbacking
|
||||||
|
|
||||||
def sendError(self, message):
|
def sendError(self, message):
|
||||||
self.sendMessage({"Error": {"message": message}})
|
self.sendMessage({"Error": {"message": message}})
|
||||||
@ -229,7 +231,7 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
str(id(self)),
|
str(id(self)),
|
||||||
)))
|
)))
|
||||||
|
|
||||||
def requireLogged(f): #@NoSelf
|
def requireLogged(f): # @NoSelf
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(self, *args, **kwds):
|
def wrapper(self, *args, **kwds):
|
||||||
if(not self._logged):
|
if(not self._logged):
|
||||||
@ -339,7 +341,7 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
def handleList(self, _):
|
def handleList(self, _):
|
||||||
self.sendList()
|
self.sendList()
|
||||||
|
|
||||||
def sendState(self, position, paused, doSeek, setBy, senderLatency, watcherLatency, forced = False):
|
def sendState(self, position, paused, doSeek, setBy, senderLatency, watcherLatency, forced=False):
|
||||||
playstate = {
|
playstate = {
|
||||||
"position": position,
|
"position": position,
|
||||||
"paused": paused,
|
"paused": paused,
|
||||||
@ -395,7 +397,7 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
self.sendLine(self._factory.gethttpRequestReply())
|
self.sendLine(self._factory.gethttpRequestReply())
|
||||||
|
|
||||||
def handleError(self, error):
|
def handleError(self, error):
|
||||||
self.dropWithError(error["message"]) #TODO: more processing and fallbacking
|
self.dropWithError(error["message"]) # TODO: more processing and fallbacking
|
||||||
|
|
||||||
def sendError(self, message):
|
def sendError(self, message):
|
||||||
self.sendMessage({"Error": {"message": message}})
|
self.sendMessage({"Error": {"message": message}})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user