Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const useBackgroundPublisher = (
backgroundPublisherRef.current.destroy();
backgroundPublisherRef.current = null;
} else {
console.warn('pub not destroyed');
console.error('pub not destroyed');
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const usePreviewPublisher = (
publisherRef.current.destroy();
publisherRef.current = null;
} else {
console.warn('pub not destroyed');
console.error('pub not destroyed');
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('usePublisher', () => {
const mockedSessionUnpublish = vi.fn();

beforeEach(() => {
vi.spyOn(console, 'warn').mockImplementation(vi.fn());
vi.spyOn(console, 'error').mockImplementation(vi.fn());

vi.mocked(useUserContext).mockImplementation(() => mockUserContextWithDefaultSettings);

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('usePublisher', () => {
});

await waitFor(() => {
expect(console.warn).toHaveBeenCalled();
expect(console.error).toHaveBeenCalled();
});
});
});
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('usePublisher', () => {
});

await waitFor(() => {
expect(console.warn).toHaveBeenCalled();
expect(console.error).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
}, []);

const handleDestroyed = useCallback(() => {
console.warn('[PUBLISHER] handleDestroyed - Publisher destroyed');
publisherRef.current = null;
}, []);

Expand All @@ -186,12 +185,6 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
}, []);

const handleStreamCreated = useCallback((e: PublisherStreamCreatedEvent) => {
console.warn('streamCreated', {
streamId: e.stream?.streamId,
streamHasAudio: e.stream?.hasAudio,
streamHasVideo: e.stream?.hasVideo,
});

setIsPublishing(true);
setStream(e.stream);
// Reset the flag now that the stream is actually established
Expand All @@ -203,12 +196,6 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
}, []);

const handleStreamDestroyed = useCallback(() => {
console.warn('[PUBLISHER] handleStreamDestroyed', {
reconnecting: reconnectingRef.current,
hasPublisher: !!publisherRef.current,
hasStream: !!publisherRef.current?.stream,
});

setStream(null);
setIsPublishing(false);

Expand All @@ -218,21 +205,13 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
isInitializingPublisherRef.current;

if (shouldPreservePublisher) {
console.warn('[PUBLISHER] handleStreamDestroyed - Preserving publisher', {
reconnecting: reconnectingRef.current,
isPublishingToSession: isPublishingToSessionRef.current,
isInitializingPublisher: isInitializingPublisherRef.current,
});
isPublishingToSessionRef.current = false;
return;
}

if (publisherRef?.current) {
console.warn('[PUBLISHER] handleStreamDestroyed - Destroying publisher');
publisherRef.current.destroy();
publisherRef.current = null;
} else {
console.warn('[PUBLISHER] handleStreamDestroyed - Publisher already destroyed');
}
}, []);

Expand Down Expand Up @@ -313,24 +292,18 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
try {
// Don't re-initialize if we're currently publishing
if (isPublishingToSessionRef.current) {
console.warn(
'[PUBLISHER] initializeLocalPublisher - BLOCKED: Already publishing to session'
);
return;
}
// Don't re-initialize if we're already initializing
if (isInitializingPublisherRef.current) {
console.warn('[PUBLISHER] initializeLocalPublisher - BLOCKED: Already initializing');
return;
}
// Don't re-initialize if we already have a publisher
if (publisherRef.current) {
console.warn('[PUBLISHER] initializeLocalPublisher - BLOCKED: Publisher already exists');
return;
}
isInitializingPublisherRef.current = true;

console.warn('[PUBLISHER] initializeLocalPublisher - Creating new publisher');
const publisher = initPublisher(undefined, options);
// Add listeners synchronously as some events could be fired before callback is invoked
addPublisherListeners(publisher);
Expand All @@ -339,10 +312,9 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
// NOTE: isInitializingPublisherRef.current will be reset in handleAccessAllowed or handleAccessDenied
// NOT here, because getUserMedia is async and we need to keep the lock until media access is granted/denied
} catch (error) {
console.warn('[PUBLISHER] initializeLocalPublisher - ERROR during initialization:', error);
isInitializingPublisherRef.current = false;
if (error instanceof Error) {
console.warn(error.stack);
console.error(error.stack);
}
}
},
Expand All @@ -366,49 +338,31 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
* @returns {Promise<void>}
*/
const publish = useCallback(async (): Promise<void> => {
console.warn('[PUBLISHER] publish - Attempting to publish', {
connected,
reconnecting,
hasPublisher: !!publisherRef.current,
isPublishingToSession: isPublishingToSessionRef.current,
isAudioEnabled,
isVideoEnabled,
});

try {
if (isPublishingToSessionRef.current) {
console.warn('[PUBLISHER] publish - BLOCKED: Already publishing to session');
return; // Avoid multiple simultaneous publish attempts
}
if (reconnecting) {
console.warn('[PUBLISHER] publish - BLOCKED: Session is reconnecting');
return;
}
if (!connected) {
console.warn('[PUBLISHER] publish - ERROR: Not connected to session');
throw new Error('You are not connected to session');
}
if (!publisherRef.current) {
console.warn('[PUBLISHER] publish - ERROR: Publisher not initialized');
throw new Error('Publisher is not initialized');
}
if (publisherRef.current?.stream) {
console.warn('[PUBLISHER] publish - already has stream');
return;
}

isPublishingToSessionRef.current = true;

console.warn('[PUBLISHER] publish - Starting publish with retry');
await idempotentCallbackWithRetry(() => sessionPublish(publisherRef.current!), {
retries: 2,
delayMs: 500,
});
console.warn('[PUBLISHER] publish - Publish successful, waiting for streamCreated event');
// Don't reset isPublishingToSessionRef here - wait for streamCreated event
} catch (err: unknown) {
console.warn('[PUBLISHER] publish - ERROR during publish:', err);

// Reset the flag on error since we won't get streamCreated
isPublishingToSessionRef.current = false;

Expand All @@ -417,16 +371,9 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
handlePublishingError();
}

console.warn(err);
console.error(err);
}
}, [
connected,
reconnecting,
sessionPublish,
handlePublishingError,
isAudioEnabled,
isVideoEnabled,
]);
}, [connected, reconnecting, sessionPublish, handlePublishingError]);

/**
* Turns the camera on and off
Expand Down Expand Up @@ -456,25 +403,15 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe

const nextAudioEnabled = !isAudioEnabled;

console.warn('toggleAudio (before publishAudio)', {
nextAudioEnabled,
});

publisherRef.current.publishAudio(nextAudioEnabled);
setIsAudioEnabled(nextAudioEnabled);
setStorageItem(STORAGE_KEYS.AUDIO_SOURCE_ENABLED, nextAudioEnabled.toString());
setIsForceMuted(false);

console.warn('toggleAudio (after publishAudio)', {
nextAudioEnabled,
});
};

useEffect(() => {
const exceptionHandler = (exceptionEvent: ExceptionEvent) => {
if (exceptionEvent.code === 1500) {
console.warn('Unable to publish to session. Error code:', exceptionEvent.code);

consecutivePublishingFailureCountRef.current += 1;

const isBrowserOnline = (() => {
Expand All @@ -486,21 +423,13 @@ const usePublisher = (initialValue: PublisherContextInitialValue = {}): Publishe
// Try to recover by recreating the publisher; only surface a blocking error after repeated failures.
const shouldTreatAsTransient = reconnectingRef.current || !connected || !isBrowserOnline;

console.warn('[PUBLISHER] exception 1500', {
reconnecting: reconnectingRef.current,
connected,
isBrowserOnline,
consecutivePublishingFailureCount: consecutivePublishingFailureCountRef.current,
shouldTreatAsTransient,
});

const publisherToCleanup = publisherRef.current;
publisherRef.current = null;

try {
publisherToCleanup?.destroy();
} catch {
console.warn('[PUBLISHER] exception 1500 - Warning: Failed to destroy publisher');
console.error('[PUBLISHER] exception 1500 - Warning: Failed to destroy publisher');
}

isPublishingToSessionRef.current = false;
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/Context/SessionProvider/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ const SessionProvider = ({ children, initialValue = {} }: SessionProviderProps):
})();

if (reconnecting || isBrowserOnline === false) {
console.warn('[SUBSCRIBER] Ignoring subscription error during reconnection/offline', {
reconnecting,
isBrowserOnline,
error,
});
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const FilePicker = ({
onFileSelect(screenshotData);
} catch (error: unknown) {
if (error instanceof Error) {
console.warn(error.message);
console.error(error.message);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/hooks/tests/useDevices.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('useDevices', () => {
vi.spyOn(mediaDevicesMock, 'removeEventListener').mockImplementation(() => {});
});

it('warns if enumerateDevices is not supported', () => {
const consoleWarnSpy = vi.spyOn(console, 'warn');
it('error if enumerateDevices is not supported', () => {
const consoleErrorSpy = vi.spyOn(console, 'error');

Object.defineProperty(global.navigator.mediaDevices, 'enumerateDevices', {
writable: true,
Expand All @@ -46,7 +46,7 @@ describe('useDevices', () => {

renderHook(() => useDevices());

expect(consoleWarnSpy).toBeCalledWith('enumerateDevices() not supported.');
expect(consoleErrorSpy).toBeCalledWith('enumerateDevices() not supported.');
});

it('returns an empty object of media devices if none are connected', async () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const useDevices = () => {
*/
const getAllMediaDevices = useCallback(() => {
if (!mediaDevices.enumerateDevices) {
console.warn('enumerateDevices() not supported.');
console.error('enumerateDevices() not supported.');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useNetworkTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const useNetworkTest = (): NetworkTestHookType => {
try {
networkTestRef.current.stop();
} catch (error) {
console.warn('Error stopping network test:', error);
console.error('Error stopping network test:', error);
}
}
setState((prev) => ({
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/utils/VonageVideoClient/vonageVideoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ class VonageVideoClient extends EventEmitter<VonageVideoClientEvents> {
});
});

console.warn('[SUBSCRIBER] Subscribing attempt for stream:', streamId);

await idempotentCallbackWithRetry(() => subscribe());

console.warn('[SUBSCRIBER] Subscribing succeeded for stream:', streamId);
if (isScreenshare) {
this.emit('screenshareStreamCreated');
}
Expand All @@ -153,10 +150,6 @@ class VonageVideoClient extends EventEmitter<VonageVideoClientEvents> {
const isRecoverableError = this.isRecoverableSubscriptionError(syncError);

if (isRecoverableError) {
console.warn(
'[SUBSCRIBER] Recoverable subscription error - stream likely destroyed:',
syncError
);
// Don't emit subscriptionError for recoverable errors
// The stream was likely destroyed before subscription completed (e.g., user refreshed)
return;
Expand Down Expand Up @@ -403,7 +396,6 @@ class VonageVideoClient extends EventEmitter<VonageVideoClientEvents> {
// the following is needed for the local subscriber to be able to receive captions
// More information: https://developer.vonage.com/en/video/guides/live-caption#receiving-your-own-live-captions
if (publisher.stream) {
console.warn('[PUBLISHER] autosubscribe user to own captions stream');
this.hiddenSubscriber =
this.clientSession?.subscribe(publisher.stream, document.createElement('div'), {
audioVolume: 0,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/stores/devices/DevicesContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const devices$ = createGlobalState(initialValue, {
onInit: ({ actions }) => {
const { mediaDevices } = globalThis.navigator;
if (!mediaDevices || !mediaDevices.addEventListener) {
console.warn('enumerateDevices() not supported.');
console.error('enumerateDevices() not supported.');
return;
}

Expand Down
Loading