Don't assume WebSocket clients are dashboards by default; announce user agents

This commit is contained in:
Ivan Kozik 2015-07-18 13:29:19 +00:00
parent 55e3507122
commit 6a866ad530
2 changed files with 9 additions and 3 deletions

View File

@ -1567,6 +1567,11 @@ Dashboard.prototype.connectWebSocket = function() {
this.ws.onopen = function(ev) {
console.log("WebSocket opened:", ev);
this.ws.send(JSON.stringify({
"type": "hello",
"mode": "dashboard",
"user_agent": navigator.userAgent
}));
this.decayer.reset();
}.bind(this);

View File

@ -12,7 +12,7 @@ from autobahn.asyncio.websocket import WebSocketServerFactory, WebSocketServerPr
class GrabberServerProtocol(WebSocketServerProtocol):
def __init__(self):
super().__init__()
self.mode = "dashboard"
self.mode = None
def onConnect(self, request):
self.peer = request.peer
@ -36,10 +36,11 @@ class GrabberServerProtocol(WebSocketServerProtocol):
if type == "hello" and obj.get("mode"):
mode = obj['mode']
if mode in ('dashboard', 'grabber'):
print("{} set mode {}".format(self.peer, mode))
self.mode = mode
if mode == "grabber":
print("{} is grabbing {}".format(self.peer, obj['url']))
self.mode = mode
elif mode == "dashboard":
print("{} is dashboarding with {}".format(self.peer, obj['user_agent']))
elif type == "download":
self.broadcastToDashboards({
"type": type,