Skip to content

Commit

Permalink
chore: handle network disconnect connect events (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
farhat-ha authored Oct 14, 2024
1 parent d3a3d37 commit 83a5126
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/js/src/Modules/Verto/BaseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,11 @@ export default abstract class BaseSession {
}

/**
* @private
* Close and remove the current connection.
* @return void
*/
private _closeConnection() {
public _closeConnection() {
this._idle = true;
clearTimeout(this._keepAliveTimeout);
if (this.connection) {
Expand Down
13 changes: 11 additions & 2 deletions packages/js/src/Modules/Verto/webrtc/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,17 @@ export default class Peer {
}

if (connectionState === 'failed' || connectionState === 'disconnected') {
this.instance.restartIce();
return this._session.onNetworkClose();
const onConnectionOnline = () => {
this.instance.restartIce();
this._session._closeConnection();
this._session.connect();
window.removeEventListener('online', onConnectionOnline);
};

if (navigator.onLine) {
return onConnectionOnline();
}
window.addEventListener('online', onConnectionOnline);
}
};

Expand Down

0 comments on commit 83a5126

Please sign in to comment.