Ф1
This commit is contained in:
@@ -263,41 +263,44 @@ export default function CallModal({ isOpen, onClose, targetUser, callType: initi
|
|||||||
|
|
||||||
// Force binding to the SINGLE stable video element
|
// Force binding to the SINGLE stable video element
|
||||||
|
|
||||||
// Use a custom property on the video element to track the play promise
|
// Manage playback via startPlayback helper
|
||||||
if (remoteVideoRef.current) {
|
if (remoteVideoRef.current) {
|
||||||
const video = remoteVideoRef.current as any;
|
const video = remoteVideoRef.current as any;
|
||||||
|
|
||||||
const startPlayback = async () => {
|
const startPlayback = async () => {
|
||||||
// If a play promise is already pending, don't start a new one
|
// If a play request is already in progress, don't start a new one (as per Chrome docs)
|
||||||
if (video._playPromise) {
|
if (video._playPromise) {
|
||||||
console.log('[WebRTC] Play promise already pending, skipping...');
|
console.log('[WebRTC] Play is already in progress, waiting...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Small stabilization delay (100ms)
|
||||||
|
await new Promise(r => setTimeout(r, 100));
|
||||||
|
|
||||||
if (video.srcObject !== stream) {
|
if (video.srcObject !== stream) {
|
||||||
console.log('[WebRTC] Binding stream to video element');
|
console.log('[WebRTC] Binding stream to video element');
|
||||||
video.srcObject = stream;
|
video.srcObject = stream;
|
||||||
}
|
}
|
||||||
video.muted = false;
|
video.muted = false;
|
||||||
|
|
||||||
console.log('[WebRTC] Initiating play()...');
|
console.log('[WebRTC] Calling video.play()...');
|
||||||
video._playPromise = video.play();
|
video._playPromise = video.play();
|
||||||
|
|
||||||
await video._playPromise;
|
await video._playPromise;
|
||||||
|
|
||||||
console.log('[WebRTC] Playback started successfully');
|
console.log('[WebRTC] Playback confirmed');
|
||||||
video._playPromise = null;
|
video._playPromise = null;
|
||||||
setNeedsInteraction(false);
|
setNeedsInteraction(false);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
video._playPromise = null;
|
video._playPromise = null;
|
||||||
if (e.name === 'NotAllowedError' || e.name === 'NotSupportedError') {
|
if (e.name === 'NotAllowedError') {
|
||||||
console.warn('[WebRTC] Autoplay blocked, waiting for interaction');
|
console.warn('[WebRTC] Autoplay blocked, showing UI');
|
||||||
setNeedsInteraction(true);
|
setNeedsInteraction(true);
|
||||||
} else if (e.name === 'AbortError') {
|
} else if (e.name === 'AbortError') {
|
||||||
console.warn('[WebRTC] Playback interrupted (AbortError), safe to ignore');
|
console.log('[WebRTC] Play aborted (likely concurrent track), will be retried automatically');
|
||||||
} else {
|
} else {
|
||||||
console.error('[WebRTC] Playback failed:', e);
|
console.error('[WebRTC] Fatal playback error:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user