Skip to content

Commit 1ea81d6

Browse files
committed
fix: stream not produced by meet creator
1 parent bebdb07 commit 1ea81d6

4 files changed

Lines changed: 147 additions & 223 deletions

File tree

frontend/src/mediasoup-client.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ export async function getRouterCapabilities(meetingId) {
4444
await sfuClient.connect(meetingId);
4545
}
4646

47-
// Get capabilities directly from SFU
4847
const capabilities = await sfuClient.getRouterRtpCapabilities();
49-
50-
// Initialize mediasoup device with the capabilities
5148
await initializeMediasoupDevice(capabilities);
5249

5350
return {
@@ -553,7 +550,7 @@ export async function subscribeToProducer(meetingId, producerId) {
553550

554551
consumers.set(consumer.id, consumer);
555552

556-
// CRITICAL: Ensure consumer is resumed (MediaSoup consumers are created paused by default)
553+
// Ensure consumer is resumed if paused
557554
if (consumer.paused) {
558555
try {
559556
await consumer.resume();
@@ -562,49 +559,6 @@ export async function subscribeToProducer(meetingId, producerId) {
562559
`❌ Failed to resume consumer ${consumer.id}:`,
563560
resumeError,
564561
);
565-
// Don't throw here, continue and see if video works anyway
566-
}
567-
}
568-
569-
// Wait a moment for video track to initialize after resume
570-
if (consumer.kind === "video") {
571-
await new Promise((resolve) => setTimeout(resolve, 1000));
572-
}
573-
574-
// CRITICAL: Verify video track has dimensions (with multiple attempts)
575-
if (consumer.kind === "video" && consumer.track) {
576-
let dimensionCheckAttempts = 0;
577-
const maxDimensionChecks = 5;
578-
let hasValidDimensions = false;
579-
580-
while (
581-
dimensionCheckAttempts < maxDimensionChecks &&
582-
!hasValidDimensions
583-
) {
584-
const settings = consumer.track.getSettings();
585-
dimensionCheckAttempts++;
586-
587-
if (
588-
settings.width &&
589-
settings.height &&
590-
settings.width > 0 &&
591-
settings.height > 0
592-
) {
593-
hasValidDimensions = true;
594-
break;
595-
}
596-
597-
// If no dimensions yet, wait and try again
598-
if (dimensionCheckAttempts < maxDimensionChecks) {
599-
await new Promise((resolve) => setTimeout(resolve, 1500));
600-
}
601-
}
602-
603-
// If we exhausted all attempts without getting dimensions
604-
if (!hasValidDimensions) {
605-
console.warn(
606-
`⚠️ Video consumer created but track has no dimensions after ${maxDimensionChecks} attempts - continuing anyway`,
607-
);
608562
}
609563
}
610564

@@ -807,12 +761,8 @@ export async function runNetworkDiagnostics() {
807761
}
808762
}
809763

810-
/**
811-
* Helper function to ensure device is ready
812-
*/
813764
async function ensureDeviceReady(meetingId) {
814765
if (!mediasoupDevice || !mediasoupDevice.loaded) {
815-
console.log("Device not ready, requesting router capabilities...");
816766
await getRouterCapabilities(meetingId);
817767
}
818768

@@ -821,9 +771,6 @@ async function ensureDeviceReady(meetingId) {
821771
}
822772
}
823773

824-
/**
825-
* Clean up all mediasoup resources
826-
*/
827774
export function cleanupMediasoup() {
828775
// Close all producers
829776
for (const producer of producers.values()) {

frontend/src/pages/Meeting.vue

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,28 +437,51 @@ const joinMeetingRoom = async () => {
437437
},
438438
},
439439
});
440-
441440
await sfuManager.connect();
442441
443442
// Hide loading indicator once we've joined
444443
isConnecting.value = false;
445444
446445
// Step 3: Initialize mediasoup device with router capabilities from SFU
447-
await sfuManager.initializeDevice();
446+
try {
447+
const initPromise = sfuManager.initializeDevice();
448+
const timeoutPromise = new Promise((resolve) =>
449+
setTimeout(resolve, 3000),
450+
);
451+
const result = await Promise.race([initPromise, timeoutPromise]);
452+
if (result === undefined) {
453+
console.warn(
454+
"⏳ Device initialization took too long, continuing; will lazy-load on publish",
455+
);
456+
}
457+
} catch (devErr) {
458+
console.warn(
459+
"⚠️ Device initialization error (will continue):",
460+
devErr?.message || devErr,
461+
);
462+
}
448463
449464
// Step 4: Start publishing media if we have local stream
450465
if (localStream && sfuManager) {
451466
const publishOptions = {
452467
publishVideo: isCameraOn.value,
453468
publishAudio: isMicOn.value,
454469
};
455-
456-
const mediaResults = await sfuManager.publishMedia(
457-
localStream,
458-
publishOptions,
459-
);
460-
videoProducer = mediaResults.videoProducer;
461-
audioProducer = mediaResults.audioProducer;
470+
try {
471+
const mediaResults = await sfuManager.publishMedia(
472+
localStream,
473+
publishOptions,
474+
);
475+
videoProducer = mediaResults.videoProducer;
476+
audioProducer = mediaResults.audioProducer;
477+
} catch (pubErr) {
478+
console.error("❌ publishMedia failed", pubErr);
479+
}
480+
} else {
481+
console.warn("⚠️ Skipping publish: localStream or sfuManager missing", {
482+
hasStream: !!localStream,
483+
hasManager: !!sfuManager,
484+
});
462485
}
463486
464487
// Step 5: Request existing participants and their media streams

0 commit comments

Comments
 (0)