masto.js icon indicating copy to clipboard operation
masto.js copied to clipboard

Detecting stream disconnection?

Open mitchellurgero opened this issue 2 years ago • 2 comments

I don't see an event type that would help with stream detection, has anyone been able to figure out how to do this?

mitchellurgero avatar May 03 '22 23:05 mitchellurgero

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!');
});

neet avatar May 04 '22 05:05 neet

This detects the disconnection. for some reason my app crashes when trying the reconnect. Which I guess I'll have to figure out. Thanks!

mitchellurgero avatar May 04 '22 17:05 mitchellurgero

:tada: This issue has been resolved in version 6.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 27 '23 07:07 github-actions[bot]