Skip to content

Commit

Permalink
media: wait for sendtransport before producing (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnts-se-whereby authored Apr 12, 2024
1 parent 8bf60c4 commit d5ec7f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-masks-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/media": patch
---

Wait for send transport before restarting video producer
23 changes: 10 additions & 13 deletions packages/media/src/webrtc/VegaRtcManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Device } from "mediasoup-client";
import { PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES } from "../model/protocol";
import * as CONNECTION_STATUS from "../model/connectionStatusConstants";
import { ServerSocket } from "../utils/ServerSocket";
import rtcManagerEvents from "./rtcManagerEvents";
import rtcStats from "./rtcStatsService";
import adapterRaw from "webrtc-adapter";
Expand Down Expand Up @@ -728,20 +727,18 @@ export default class VegaRtcManager implements RtcManager {

async _internalSendWebcam() {
logger.info("_internalSendWebcam()");
// after waiting, do we still want or need to produce the track?
if (
!this._webcamTrack ||
this._webcamTrack.readyState === "ended" ||
!this._sendTransport ||
this._webcamProducer
) {
return;
}

this._webcamProducerPromise = (async () => {
try {
// after waiting, do we still want or need to produce the track?
if (
!this._webcamTrack ||
this._webcamTrack.readyState === "ended" ||
!this._sendTransport ||
this._webcamProducer
) {
this._webcamProducerPromise = null;
return;
}

const currentPaused = this._webcamPaused;

const producer = await this._sendTransport.produce({
Expand Down Expand Up @@ -797,7 +794,7 @@ export default class VegaRtcManager implements RtcManager {

// if we attempted to produce an ended track earlier no producer would have been made
// so here, later, it will be replaced with a working track, and the producer needs to be created
if (!this._webcamProducer && this._webcamTrack.enabled) await this._internalSendWebcam();
if (this._sendTransport && !this._webcamProducer && this._webcamTrack.enabled) await this._internalSendWebcam();

if (!this._webcamTrack || !this._webcamProducer || this._webcamProducer.closed) return;

Expand Down

0 comments on commit d5ec7f5

Please sign in to comment.