Exemple #1
0
    async def handler_ok(ws, _):
        notice_coro = []
        topic = {}

        try:
            while True:
                recv_msg = str_to_msg(await ws.recv())
                if recv_msg.event == PHOENIX_EVENT['JOIN']:
                    if recv_msg.topic not in topic:

                        async def notice(topic):
                            for i in range(num_notice):
                                await ws.send(
                                    msg_to_str(None, None, topic,
                                               'notification', {
                                                   "data": [{
                                                       "data": [],
                                                       "action": "init"
                                                   }]
                                               }))
                                await asyncio.sleep(0.01, loop=event_loop)

                        notice_coro.append(
                            asyncio.ensure_future(notice(recv_msg.topic),
                                                  loop=event_loop))
                send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                      recv_msg.topic, PHOENIX_EVENT['REPLY'], {
                                          'status': 'ok',
                                          'response': {}
                                      })
                await ws.send(send_msg)
        except websockets.exceptions.ConnectionClosed:
            for n in notice_coro:
                n.cancel()
Exemple #2
0
async def handle(ws, _, responses):
    for r in responses:
        event, payload = r
        recv_msg = str_to_msg(await ws.recv())
        send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref, recv_msg.topic,
                              event, payload)
        await ws.send(send_msg)
Exemple #3
0
    async def handler_ok(ws, _):
        recv_msg = str_to_msg(await ws.recv())
        send_msg = msg_to_str(100, recv_msg.join_ref, recv_msg.topic,
                              PHOENIX_EVENT['REPLY'], {
                                  'status': 'ok',
                                  'response': {}
                              })
        await ws.send(send_msg)

        while True:
            recv_msg = str_to_msg(await ws.recv())
            send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                  recv_msg.topic, PHOENIX_EVENT['REPLY'], {
                                      'status': 'ok',
                                      'response': {}
                                  })
            await ws.send(send_msg)
Exemple #4
0
 async def notice():
     for i in range(notice_cnt):
         await ws.send(
             msg_to_str(
                 None, None, '/channel', 'notification',
                 {"data": [{
                     "data": [],
                     "action": "init"
                 }]}))
         await asyncio.sleep(0.01, loop=event_loop)
Exemple #5
0
 async def notice(topic):
     for i in range(num_notice):
         await ws.send(
             msg_to_str(None, None, topic,
                        'notification', {
                            "data": [{
                                "data": [],
                                "action": "init"
                            }]
                        }))
         await asyncio.sleep(0.01, loop=event_loop)
Exemple #6
0
    async def handler_ignore_first_message(ws, _):
        for i in range(3):
            recv_msg = str_to_msg(await ws.recv())
            if i == 0:
                continue

            send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                  recv_msg.topic, PHOENIX_EVENT['REPLY'], {
                                      'status': 'ok',
                                      'response': {}
                                  })
            await ws.send(send_msg)
Exemple #7
0
 async def handler_ok(ws, _):
     try:
         while True:
             recv_msg = str_to_msg(await ws.recv())
             send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                   recv_msg.topic, PHOENIX_EVENT['REPLY'], {
                                       'status': 'ok',
                                       'response': {}
                                   })
             await ws.send(send_msg)
     except websockets.exceptions.ConnectionClosed:
         pass
Exemple #8
0
 async def handler_ok(ws, _):
     while True:
         try:
             async with atimeout(0.5, loop=ws.loop):
                 recv_msg = str_to_msg(await ws.recv())
                 send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                       recv_msg.topic,
                                       PHOENIX_EVENT['REPLY'], {
                                           'status': 'ok',
                                           'response': {}
                                       })
                 await ws.send(send_msg)
         except asyncio.TimeoutError:
             break
Exemple #9
0
    async def handler_ok(ws, _):
        await ws.recv()
        breaked_msg = '{"join_ref": "1", "ref": "2", "topic": "/channel", "event": "phx_reply",' \
                      '"payload": {"breaked" : "json", "timestamp": 1533884684264, "timeout": 10000}'
        await ws.send(breaked_msg)

        while True:
            recv_msg = str_to_msg(await ws.recv())
            send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                  recv_msg.topic, PHOENIX_EVENT['REPLY'], {
                                      'status': 'ok',
                                      'response': {}
                                  })
            await ws.send(send_msg)
Exemple #10
0
 async def handler_never_accept_to_join(ws, _):
     try:
         while True:
             try:
                 recv_msg = str_to_msg(await ws.recv())
                 send_msg = msg_to_str(recv_msg.ref, recv_msg.join_ref,
                                       recv_msg.topic,
                                       PHOENIX_EVENT['REPLY'], {
                                           'status': 'ok',
                                           'response': {}
                                       })
                 if recv_msg.event != PHOENIX_EVENT['JOIN']:
                     await ws.send(send_msg)
             except asyncio.TimeoutError:
                 break
     except websockets.ConnectionClosed:
         pass