@@ -36,6 +36,7 @@ export let currentUrl = '';
3636export const CustomWebView = forwardRef < CustomWebViewRef , CustomWebViewProps > (
3737 ( props , ref ) => {
3838 const webViewRef = useRef < WebView | null > ( null ) ;
39+ let socket = useRef < Socket > ( null ) ;
3940
4041 const [ webViewCanGoBack , setWebViewCanGoBack ] = useState ( false ) ;
4142
@@ -46,6 +47,10 @@ export const CustomWebView = forwardRef<CustomWebViewRef, CustomWebViewProps>(
4647 window.dispatchEvent(new Event('${ event } '));
4748 true;
4849 ` ) ;
50+
51+ if ( state === 'active' ) {
52+ socket . current ?. connect ( ) ;
53+ }
4954 } ) ;
5055
5156 return ( ) => {
@@ -171,7 +176,6 @@ export const CustomWebView = forwardRef<CustomWebViewRef, CustomWebViewProps>(
171176 }
172177 } ) ;
173178
174- let socket = useRef < Socket > ( null ) ;
175179 const onMessage = async ( evt : WebViewMessageEvent ) => {
176180 const { event, payload } = JSON . parse ( evt . nativeEvent . data ) ;
177181
@@ -190,6 +194,9 @@ export const CustomWebView = forwardRef<CustomWebViewRef, CustomWebViewProps>(
190194 } ) ;
191195 } ) ;
192196 socket . current . on ( 'disconnect' , ( reason , description ) => {
197+ if ( AppState . currentState !== 'active' ) {
198+ socket . current ?. disconnect ( ) ;
199+ }
193200 console . log ( 'disconnected' , reason , description ) ;
194201 localRefs ( ) . emit ( 'sio_event' , {
195202 event : 'disconnect' ,
0 commit comments