Esempio n. 1
0
    async def _one_read(self) -> bool:
        packs = await self._conn.read_bytes()

        if packs is None:
            return False

        for opt, body in Pack.unpack(packs):
            if not self.parse_body(body, opt):
                return False
        return True
Esempio n. 2
0
 async def _one_hello(self) -> bool:
     dict_enter = {
         'uid': 0,
         'roomid': self._room_id,
         'protover': 2,
         'platform': 'web',
         'clientver': '1.7.3'
     }
     str_enter = json.dumps(dict_enter)
     return await self._conn.send_bytes(Pack.pack(str_enter, opt=Opt.AUTH, ver=2, seq=1))
Esempio n. 3
0
    def __init__(self,
                 room_id: int,
                 area_id: int,
                 session: Optional[ClientSession] = None,
                 loop=None):
        heartbeat = 30.0
        conn = WsConn(url='wss://broadcastlv.chat.bilibili.com:443/sub',
                      receive_timeout=heartbeat + 10,
                      session=session)
        super().__init__(area_id=area_id,
                         conn=conn,
                         heartbeat=heartbeat,
                         loop=loop,
                         logger_info=print)
        self._room_id = room_id

        self._pack_heartbeat = Pack.pack('', opt=Opt.HEARTBEAT, ver=1, seq=1)
Esempio n. 4
0
    async def _one_read(self) -> bool:
        packs = await self._conn.read_bytes()

        if packs is None:
            return False

        len_pack, len_header, ver, opt, _ = Header.unpack(packs)
        body = packs[len_header:]

        if ver == 2 and opt == Opt.SEND_MSG_REPLY:  # v2 协议有混合,可能不成熟吧
            packs = zlib.decompress(body)
            for opt, body in Pack.unpack(packs):
                if not await self.parse_body(body, opt):
                    return False
            return True
        else:
            return await self.parse_body(body, opt)