Skip to content

Commit

Permalink
media: handle failed sfu connection in bwtester (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnts-se-whereby authored Dec 11, 2024
1 parent 33337b1 commit 9304948
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-socks-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/media": patch
---

Handle failed SFU connection in bwtester
13 changes: 8 additions & 5 deletions packages/media/src/webrtc/BandwidthTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default class BandwidthTester extends EventEmitter {
_timeout: any;
_canvas: any;
_drawInterval: any;
_resultTimeout: any;
_reportTimeout: any;
_resultTimeout: NodeJS.Timeout | null;

constructor({ features }: { features?: any } = {}) {
super();
Expand Down Expand Up @@ -97,6 +96,12 @@ export default class BandwidthTester extends EventEmitter {

this.closed = true;

// If this happens, the websocket connection to SFU probably failed right away.
if (!!this._timeout || Date.now() - this._startTime < 750) {
this.emit("result", {
error: true,
});
}
this._clearTimeouts();

clearInterval(this._drawInterval);
Expand Down Expand Up @@ -184,7 +189,7 @@ export default class BandwidthTester extends EventEmitter {
() => {
this._reportResults();
},
this._runTime * 1000 - this._mediaEstablishedTime
this._runTime * 1000 - this._mediaEstablishedTime,
);
} catch (error) {
logger.error("_start() [error:%o]", error);
Expand Down Expand Up @@ -477,7 +482,5 @@ export default class BandwidthTester extends EventEmitter {
_clearTimeouts() {
clearTimeout(this._timeout);
this._timeout = null;
clearTimeout(this._reportTimeout);
this._reportTimeout = null;
}
}

0 comments on commit 9304948

Please sign in to comment.