Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media: wait for sendtransport before producing #190

Merged
merged 1 commit into from
Apr 12, 2024
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/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
Loading