コード例 #1
0
ファイル: app.py プロジェクト: amanwriter/joyce-web
def wso(request):
    global wsk
    global wst
    wsk0 = WebSocketResponse()
    wsk0.start(request)
    unauth = True
    while True:
        msg = yield from wsk0.receive()
        if msg.tp == MsgType.text:
            print("Screen")
            print(msg.data)
            if unauth:
                wsk0.auth = msg.data
                wsk[wsk0.auth] = wsk0
                unauth = False
                continue
            if msg.data == 'close':
                yield from wsk0.close()
                wsk.pop(wsk0.auth, None)
                break
            else:
                wst[wsk0.auth].send_str(msg.data)
        elif msg.tp == MsgType.close:
            break
        elif msg.tp == MsgType.error:
            break
    wsk.pop(wsk0.auth, None)
    return wsk0