It’s ok!
If you need the working code :
url = "wss://pubsub-edge.twitch.tv"
loop = asyncio.get_event_loop()
connection = websockets.connect(url, ping_interval=100)
client_id = 'myclientid'
channel_id = 'myuserid'
access_token = 'mytokent '
async def stay():
async with connection as socket:
while ():
ping = json.dumps({
"type": "PING"})
await socket.send(ping)
res = await socket.recv()
print(res)
await asyncio.sleep(100 + random.randrange(1, 50))
async def listen():
async with connection as socket:
data = json.dumps({
"type": "LISTEN",
"data": {
"topics": ["channel.channel_points_custom_reward_redemption.add" + channel_id],
"auth_token": access_token,
}
})
await socket.send(data)
resp = await socket.recv()
dec_resp = json.loads(resp)
print(dec_resp)
# while(loop.is_running):
async for msg in socket:
print(msg)
pass
loop.create_task(stay())
loop.run_until_complete(listen())