Hi
I’m trying to migrate from pub-sub to event-sub for the automod functionality with WebSocket on browser side (chromium). (and in the future even the IRC chat that I’m using)
Compared to pub-sub event-sub don’t request a triggered timed PONG event.
But the problem is that after around 2 minutes the WebSocket close itself without reason
CloseEvent {isTrusted: true, wasClean: false, code: 1006, reason: '', type: 'close' .....
after looking to the list of subscribes that I open from the POST api it looks like that the browser don’t send the PONG message.
{id: '0851dd4d-b416', status: 'websocket_failed_ping_pong', .....
here is the code when i open the WebSocket (the commented part was the working pub-sub):
// const ws = new WebSocket('wss://pubsub-edge.twitch.tv')
const ws = new WebSocket('wss://eventsub.wss.twitch.tv/ws?keepalive_timeout_seconds=30')
try {
const listener = (event) => {
const { data = '{}' } = event;
const _data = JSON.parse(data);
console.log(_data);
}
// const onOpen = () => {
// const topicString = `automod-queue.${tokenUserId}.${broadcasterId}`;
// heartbeatHandle = setInterval(() => heartbeat(ws), 10000);
// ws.send(JSON.stringify({
// "type": "LISTEN",
// "data": {
// "topics": [topicString],
// "auth_token": twitchOAuthToken
// }
// }));
// };
ws.addEventListener('message', listener)
// ws.addEventListener('open', onOpen)
ws.addEventListener("close", (event) => {
console.log(event);
// clearInterval(heartbeatHandle);
});
ws.addEventListener("error", (event) => {
console.log(event);
// clearInterval(heartbeatHandle);
});
}
and subscription post in react are ok and subscribe correctly to the WebSocket
const body = {
"type": "automod.message.hold",
"version": "1",
"condition": {
"broadcaster_user_id": broadcasterId,
"moderator_user_id": tokenUserId,
},
"transport": {
"method": "websocket",
"session_id": id,
}
}
query: ({ body = {} }) => ({
url: 'eventsub/subscriptions',
method: 'POST',
body,
}),
there is some way to respond at the PING browser side? or I will need to reopen the WebSocket in case of close event?