def handle(request):
peername = request.transport.get_extra_info('peername')
host = port = "unknown"
if peername is not None:
host, port = peername[0:2]
log.debug("web journal socket request from {}[{}]".format(host, port))
ws = web.WebSocketResponse()
await ws.prepare(request)
jh = JournalHandler(ws)
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
if msg.data == 'close':
await ws.close()
await jh.shutdown()
return ws
if msg.data == 'info':
jh.sync_info()
elif msg.data == 'history':
jh.sync_history()
elif msg.data == 'journal-sync-start':
jh.sync_log()
elif msg.data == 'journal-sync-stop':
jh.journal_sync_stop()
else:
log.debug("unknown websocket command {}".format(str(msg.data)))
elif msg.type == aiohttp.WSMsgType.ERROR:
print('ws connection closed with exception %s' % ws.exception())
return ws
评论列表
文章目录