masto.js
masto.js copied to clipboard
Detecting stream disconnection?
I don't see an event type that would help with stream detection, has anyone been able to figure out how to do this?
I'm intentionally making some of the WS features private to hide implementations, but the close
event sounds good to be accessible.
For now, I think you can use this workaround to directly access an internal WebSocket instance and subscribe to close
event
const stream = await masto.stream.streamPublicTimeline();
// `stream` has a private `ws` property which is a instance of https://www.npmjs.im/ws
const ws = (stream as any).ws;
ws.on('close', () => {
console.log('Disconnected!');
});
This detects the disconnection. for some reason my app crashes when trying the reconnect. Which I guess I'll have to figure out. Thanks!
:tada: This issue has been resolved in version 6.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: