react-native-nodemediaclient icon indicating copy to clipboard operation
react-native-nodemediaclient copied to clipboard

RTMP connection doesn't terminate on unmount (NodePlayerView)

Open LeviWilliams opened this issue 3 years ago • 2 comments

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

LeviWilliams avatar Jul 26 '21 18:07 LeviWilliams

I'm also experiencing this. @LeviWilliams have you figured out a solution.

I believe it is causing my app to crash.

Thanks

scottschindler avatar Aug 04 '21 14:08 scottschindler

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.

LeviWilliams avatar Aug 04 '21 18:08 LeviWilliams