react-native-webrtc: Added reconnection events

This commit is contained in:
csantosm 2021-10-14 13:35:12 +02:00
parent c62a8a51d3
commit d6f0e173e5

View File

@ -126,6 +126,26 @@ export default class App extends Component<Props> {
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.