react-native-nodemediaclient
react-native-nodemediaclient copied to clipboard
RTMP connection doesn't terminate on unmount (NodePlayerView)
It seems like the "stop" method was left out of the native code of this library on unmount for livestream URLs. We can see the connections persist even if the component is unmounted. This can cause multiple connections to occur as well if the component remounts with an old connection around.
The native code should correctly manage the react native unmount lifecycle
I'm also experiencing this. @LeviWilliams have you figured out a solution.
I believe it is causing my app to crash.
Thanks
A few things - we were able to fix natively on Android but no luck on iOS. We ended up writing a wrapper component to handle every case, a hacky solution but it works. Our wrapper component looks something like this:
const NodePlayerViewWrapper = React.forwardRef((props, ref) => {
const onBackground = () => {
ref?.current!.stop();
};
const onForeground = () => {
ref?.current!.start();
};
return <NodePlayerView ref={ref} {...props} />;
});
We plug onBackground/onForeground into react natives AppState (not shown cause we use a custom hook for this) and we also pass down a ref from our higher level screen that uses the viewer. Whenever that screen is going to navigate, we manually call ref.current.stop() before it unmounts.