def classWebSocket(clsName, name): """ Websocket for an instance of the classes Game, Player or Tournament -> used to get the a json with informations about this object """ # should be a websocket wsock = request.environ.get('wsgi.websocket') if not wsock: abort(400, 'Expected Websocket request.') # check if that instance exists if clsName not in wsCls: abort(400, 'Invalid class %s is not in %s' % (clsName, wsCls.keys())) cls = wsCls[clsName] obj = cls.getFromName(name) if obj is None: abort(400, 'Invalid name (%s) for class %s' % (name, clsName)) # register this websocket obj.registerWebSocket(wsock) # send to this websocket obj.sendUpdateToWebSocket(wsock) # loop until the end of this websocket while True: try: wsock.receive() except WebSocketError: BaseClass.removeLoIWebSocket(wsock) break
def classWebSocket(): """ Websocket for the list of instances of the classes Game, Player and Tournament -> used to get the a json with the list of instances of theses classes """ # should be a websocket wsock = request.environ.get('wsgi.websocket') if not wsock: abort(400, 'Expected Websocket request.') # register this websocket BaseClass.registerLoIWebSocket(wsock) # send to this websocket BaseClass.sendListofInstances(wsock) # loop until the end of this websocket while True: try: wsock.receive() except WebSocketError: BaseClass.removeLoIWebSocket(wsock) break