From d6f0e173e5666775933e23825a0d3149d84c1dc9 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Thu, 14 Oct 2021 13:35:12 +0200 Subject: [PATCH] react-native-webrtc: Added reconnection events --- openvidu-react-native/App.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/openvidu-react-native/App.js b/openvidu-react-native/App.js index 50766d79..5aa47eb6 100644 --- a/openvidu-react-native/App.js +++ b/openvidu-react-native/App.js @@ -126,6 +126,26 @@ export default class App extends Component { console.warn(exception); }); + // On reconnection events + mySession.on('reconnecting', () => console.warn('Oops! Trying to reconnect to the session')); + mySession.on('reconnected', () => { + console.log('Hurray! You successfully reconnected to the session'); + setTimeout(() => { + // Updated state and rendering the view avoiding frozen streams + const subs = this.state.subscribers; + this.setState({ subscribers: [] }); + this.setState({ subscribers: subs }); + }, 1000); + }); + mySession.on('sessionDisconnected', (event) => { + if (event.reason === 'networkDisconnect') { + console.warn('Dang-it... You lost your connection to the session'); + this.leaveSession(); + } else { + // Disconnected from the session for other reason than a network drop + } + }); + try { // --- 4) Connect to the session with a valid user token --- // 'getToken' method is simulating what your server-side should do.