def __init__(self, on_message, on_open=None, on_error=None, on_close=None, on_data=None): mixin_api = MIXIN_API(mixin_config) encoded = mixin_api.genGETJwtToken('/', "", str(uuid.uuid4())) if on_open is None: on_open = MIXIN_WS_API.__on_open if on_close is None: on_close = MIXIN_WS_API.__on_close if on_error is None: on_error = MIXIN_WS_API.__on_error if on_data is None: on_data = MIXIN_WS_API.__on_data self.ws = websocket.WebSocketApp( "wss://blaze.mixin.one/", on_message=on_message, on_error=on_error, on_close=on_close, header=["Authorization:Bearer " + encoded.decode()], subprotocols=["Mixin-Blaze-1"], on_data=on_data) self.ws.on_open = on_open
def getAuthToken(self): mixin_api = MIXIN_API(robot_config) authToken = mixin_api.genGETJwtToken('/', "", str(uuid.uuid4())) return authToken
def on_open(ws): def run(*args): print("ws open") Message = {"id": str(uuid.uuid1()), "action": "LIST_PENDING_MESSAGES"} Message_instring = json.dumps(Message) fgz = StringIO() gzip_obj = gzip.GzipFile(mode='wb', fileobj=fgz) gzip_obj.write(Message_instring) gzip_obj.close() ws.send(fgz.getvalue(), opcode=websocket.ABNF.OPCODE_BINARY) while True: time.sleep(1) thread.start_new_thread(run, ()) if __name__ == "__main__": while True: encoded = mixin_api_robot.genGETJwtToken('/', "", str(uuid.uuid4())) #websocket.enableTrace(True) ws = websocket.WebSocketApp("wss://blaze.mixin.one/", on_message=on_message, on_error=on_error, on_close=on_close, header=["Authorization:Bearer " + encoded], subprotocols=["Mixin-Blaze-1"], on_data=on_data) ws.on_open = on_open ws.run_forever()