async def listen(self):
while not self._shutdown:<EOL><INDENT>try:<EOL><INDENT>data = json.loads(await self._ws.recv())<EOL><DEDENT>except websockets.ConnectionClosed as error:<EOL><INDENT>log.warning('<STR_LIT>'.format(str(error)))<EOL>for g in self._lavalink.players._players.copy().keys():<EOL><INDENT>ws = self._lavalink.bot._connection._get_websocket(int(g))<EOL>await ws.voice_state(int(g), None)<EOL><DEDENT>self._lavalink.players.clear()<EOL>if self._shutdown:<EOL><INDENT>break<EOL><DEDENT>if await self._attempt_reconnect():<EOL><INDENT>return<EOL><DEDENT>log.warning('<STR_LIT>')<EOL>break<EOL><DEDENT>op = data.get('<STR_LIT>', None)<EOL>log.debug('<STR_LIT>'.format(str(data)))<EOL>if not op:<EOL><INDENT>return log.debug('<STR_LIT>'.format(str(data)))<EOL><DEDENT>if op == '<STR_LIT>':<EOL><INDENT>log.debug('<STR_LIT>'.format(data['<STR_LIT:type>']))<EOL>player = self._lavalink.players[int(data['<STR_LIT>'])]<EOL>event = None<EOL>if data['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>event = TrackEndEvent(player, data['<STR_LIT>'], data['<STR_LIT>'])<EOL><DEDENT>elif data['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>event = TrackExceptionEvent(player, data['<STR_LIT>'], data['<STR_LIT:error>'])<EOL><DEDENT>elif data['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>event = TrackStuckEvent(player, data['<STR_LIT>'], data['<STR_LIT>'])<EOL><DEDENT>if event:<EOL><INDENT>await self._lavalink.dispatch_event(event)<EOL><DEDENT><DEDENT>elif op == '<STR_LIT>':<EOL><INDENT>await self._lavalink.update_state(data)<EOL><DEDENT>elif op == '<STR_LIT>':<EOL><INDENT>self._lavalink.stats._update(data)<EOL>await self._lavalink.dispatch_event(StatsUpdateEvent(self._lavalink.stats))<EOL><DEDENT><DEDENT>log.debug('<STR_LIT>')<EOL>await self._ws.close()<EOL>
Waits to receive a payload from the Lavalink server and processes it.