Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-clubs-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/media": patch
---

media: Fixes rtcstats disconnecting and never reconnecting
13 changes: 12 additions & 1 deletion packages/media/src/webrtc/P2pRtcManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,18 @@ export default class P2pRtcManager implements RtcManager {
rtcStats.sendEvent(eventName, data);
}

rtcStatsConnect() {
if (!rtcStats.server.connected) {
rtcStats.server.connect();
}
}

rtcStatsDisconnect() {
rtcStats.server.close();
}

rtcStatsReconnect() {
if (!rtcStats.server.connected) {
if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
rtcStats.server.connect();
}
}
Expand Down Expand Up @@ -888,6 +894,11 @@ export default class P2pRtcManager implements RtcManager {
}

_connect(clientId: string) {
// bring rtcstats back up if disconnected
try {
this.rtcStatsReconnect();
} catch (_) {}

let session = this._getSession(clientId);
let initialBandwidth = (session && session.bandwidth) || 0;
if (session) {
Expand Down
2 changes: 1 addition & 1 deletion packages/media/src/webrtc/RtcManagerDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class RtcManagerDispatcher {
} else {
rtcManager = new P2pRtcManager(config);
}
rtcManager.rtcStatsReconnect();
rtcManager.rtcStatsConnect();
rtcManager.setupSocketListeners();
emitter.emit(CONNECTION_STATUS.EVENTS.RTC_MANAGER_CREATED, { rtcManager });
this.currentManager = rtcManager;
Expand Down
8 changes: 7 additions & 1 deletion packages/media/src/webrtc/VegaRtcManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1698,12 +1698,18 @@ export default class VegaRtcManager implements RtcManager {
rtcStats.sendEvent(eventName, data);
}

rtcStatsConnect() {
if (!rtcStats.server.connected) {
rtcStats.server.connect();
}
}

rtcStatsDisconnect() {
rtcStats.server.close();
}

rtcStatsReconnect() {
if (!rtcStats.server.connected) {
if (!rtcStats.server.connected && rtcStats.server.attemptedConnectedAtLeastOnce) {
rtcStats.server.connect();
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/media/src/webrtc/rtcStatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function rtcStatsConnection(wsURL: string, logger: any = console) {

const connection = {
connected: false,
attemptedConnectedAtLeastOnce: false,
trace: (...args: any) => {
args.push(Date.now());

Expand Down Expand Up @@ -114,6 +115,7 @@ function rtcStatsConnection(wsURL: string, logger: any = console) {
connectionAttempt += 1;
ws?.close();
connection.connected = true;
connection.attemptedConnectedAtLeastOnce = true;
ws = new WebSocket(wsURL + window.location.pathname, RTCSTATS_PROTOCOL_VERSION);

ws.onerror = (e: Event) => {
Expand Down