Skip to content
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
2 changes: 1 addition & 1 deletion demo/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function App() {
const [mode, setMode] = useState<ChatMode>(ChatMode.Functional);
const [sessionTimeout, setSessionTimeout] = useState<number | undefined>();
const [compatibilityMode, setCompatibilityMode] = useState<'on' | 'off' | 'auto'>();
const [fluent, setFluent] = useState(false);
const [fluent, setFluent] = useState(true);
const [enableMicrophone, setEnableMicrophone] = useState(true);
const [microphoneStream, setMicrophoneStream] = useState<MediaStream | undefined>(undefined);
const microphoneStreamRef = useRef<MediaStream | undefined>(undefined);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.32",
"version": "1.1.33",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down
21 changes: 13 additions & 8 deletions src/services/streaming-manager/advanced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { StreamApiFactory, StreamingAgentFactory, StreamingManagerOptionsFactory } from '../../test-utils/factories';
import { CreateStreamOptions, StreamType, StreamingManagerOptions } from '../../types/index';
import { pollStats } from './stats/poll';
import { createVideoStatsMonitor } from './stats/poll';
import {
createParseDataChannelMessage,
createWebRTCStreamingManager as createStreamingManager,
Expand All @@ -15,9 +15,14 @@ import {
const mockApi = StreamApiFactory.build();
jest.mock('../../api/streams', () => ({ createStreamApi: jest.fn(() => mockApi) }));

// Mock pollStats
// Mock createVideoStatsMonitor
const mockVideoStatsMonitor = {
start: jest.fn(),
stop: jest.fn(),
getReport: jest.fn(() => ({})),
};
jest.mock('./stats/poll', () => ({
pollStats: jest.fn(() => 123), // mock interval id
createVideoStatsMonitor: jest.fn(() => mockVideoStatsMonitor),
}));

// Mock other dependencies as needed
Expand Down Expand Up @@ -391,15 +396,15 @@ describe('Streaming Manager Advanced', () => {
it('should handle connectivity state changes via pollStats', async () => {
const manager = await createStreamingManager(agentId, agent, options);

expect(pollStats).toHaveBeenCalledWith(
expect(createVideoStatsMonitor).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.anything(),
expect.anything(),
expect.any(Function)
);

const connectivityCallback = (pollStats as jest.Mock).mock.calls[0][4];
const connectivityCallback = (createVideoStatsMonitor as jest.Mock).mock.calls[0][4];

connectivityCallback('test-connectivity-state');
expect(options.callbacks.onConnectivityStateChange).toHaveBeenCalledWith('test-connectivity-state');
Expand All @@ -408,15 +413,15 @@ describe('Streaming Manager Advanced', () => {
it('should handle pollStats return value', async () => {
const manager = await createStreamingManager(agentId, agent, options);

expect(pollStats).toHaveBeenCalled();
expect(createVideoStatsMonitor).toHaveBeenCalled();

expect(manager.streamId).toBe('streamId');
});

it('should handle video stats interval management', async () => {
const manager = await createStreamingManager(agentId, agent, options);

expect(pollStats).toHaveBeenCalledWith(
expect(createVideoStatsMonitor).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.anything(),
Expand All @@ -430,7 +435,7 @@ describe('Streaming Manager Advanced', () => {
it('should handle pollStats function execution and return', async () => {
const manager = await createStreamingManager(agentId, agent, options);

expect(pollStats).toHaveBeenCalled();
expect(createVideoStatsMonitor).toHaveBeenCalled();
expect(manager.streamId).toBe('streamId');
expect(manager.sessionId).toBe('sessionId');
});
Expand Down
9 changes: 7 additions & 2 deletions src/services/streaming-manager/business-flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { createWebRTCStreamingManager as createStreamingManager } from './webrtc
const mockApi = StreamApiFactory.build();
jest.mock('../../api/streams', () => ({ createStreamApi: jest.fn(() => mockApi) }));

// Mock pollStats
// Mock createVideoStatsMonitor
const mockVideoStatsMonitor = {
start: jest.fn(),
stop: jest.fn(),
getReport: jest.fn(() => ({})),
};
jest.mock('./stats/poll', () => ({
pollStats: jest.fn(() => 123), // mock interval id
createVideoStatsMonitor: jest.fn(() => mockVideoStatsMonitor),
}));

// Mock other dependencies as needed
Expand Down
49 changes: 16 additions & 33 deletions src/services/streaming-manager/disconnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { createWebRTCStreamingManager as createStreamingManager } from './webrtc
const mockApi = StreamApiFactory.build();
jest.mock('../../api/streams', () => ({ createStreamApi: jest.fn(() => mockApi) }));

// Mock pollStats
// Mock createVideoStatsMonitor
const mockVideoStatsMonitor = {
start: jest.fn(),
stop: jest.fn(),
getReport: jest.fn(() => ({})),
};
jest.mock('./stats/poll', () => ({
pollStats: jest.fn(() => 123), // mock interval id
createVideoStatsMonitor: jest.fn(() => mockVideoStatsMonitor),
}));

// Mock other dependencies as needed
Expand Down Expand Up @@ -93,18 +98,14 @@ describe('Streaming Manager Disconnect', () => {
expect(mockApi.close).toHaveBeenCalledWith('streamId', 'sessionId');
});

it('should handle clearInterval in disconnect', async () => {
it('should handle videoStatsMonitor.stop in disconnect', async () => {
const manager = await createStreamingManager(agentId, agentStreamOptions, options);
const mockPC = (window.RTCPeerConnection as any).mock.results[0].value;
mockPC.iceConnectionState = 'connected';

const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(clearIntervalSpy).toHaveBeenCalled();

clearIntervalSpy.mockRestore();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
});

it('should handle agent activity state changes on disconnect', async () => {
Expand All @@ -130,19 +131,15 @@ describe('Streaming Manager Disconnect', () => {
expect(mockPC.ontrack).toBeNull();
});

it('should handle disconnect cleanup and clearInterval', async () => {
it('should handle disconnect cleanup and videoStatsMonitor.stop', async () => {
const manager = await createStreamingManager(agentId, agentStreamOptions, options);
const mockPC = (window.RTCPeerConnection as any).mock.results[0].value;
mockPC.iceConnectionState = 'connected';

const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(clearIntervalSpy).toHaveBeenCalled();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
expect(options.callbacks.onAgentActivityStateChange).toHaveBeenCalledWith(AgentActivityState.Idle);

clearIntervalSpy.mockRestore();
});

it('should handle srcObject cleanup in disconnect', async () => {
Expand All @@ -162,20 +159,18 @@ describe('Streaming Manager Disconnect', () => {
mockPC.iceConnectionState = 'connected';

const closeSpy = jest.spyOn(mockPC, 'close');
const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(closeSpy).toHaveBeenCalled();
expect(clearIntervalSpy).toHaveBeenCalled();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
expect(mockPC.oniceconnectionstatechange).toBeNull();
expect(mockPC.onnegotiationneeded).toBeNull();
expect(mockPC.onicecandidate).toBeNull();
expect(mockPC.ontrack).toBeNull();
expect(options.callbacks.onAgentActivityStateChange).toHaveBeenCalledWith(AgentActivityState.Idle);

closeSpy.mockRestore();
clearIntervalSpy.mockRestore();
});
});

Expand Down Expand Up @@ -231,48 +226,36 @@ describe('Streaming Manager Disconnect', () => {
expect(manager.streamId).toBe('streamId');
});

it('should handle clearInterval on disconnect', async () => {
it('should handle videoStatsMonitor.stop on disconnect', async () => {
const manager = await createStreamingManager(agentId, agentStreamOptions, options);
const mockPC = (window.RTCPeerConnection as any).mock.results[0].value;
mockPC.iceConnectionState = 'connected';

const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(clearIntervalSpy).toHaveBeenCalled();

clearIntervalSpy.mockRestore();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
});

it('should handle complete disconnect cleanup sequence', async () => {
const manager = await createStreamingManager(agentId, agentStreamOptions, options);
const mockPC = (window.RTCPeerConnection as any).mock.results[0].value;
mockPC.iceConnectionState = 'connected';

const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(clearIntervalSpy).toHaveBeenCalled();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
expect(options.callbacks.onAgentActivityStateChange).toHaveBeenCalledWith(AgentActivityState.Idle);

clearIntervalSpy.mockRestore();
});

it('should execute all disconnect cleanup paths', async () => {
const manager = await createStreamingManager(agentId, agentStreamOptions, options);
const mockPC = (window.RTCPeerConnection as any).mock.results[0].value;
mockPC.iceConnectionState = 'connected';

const clearIntervalSpy = jest.spyOn(global, 'clearInterval');

await manager.disconnect();

expect(clearIntervalSpy).toHaveBeenCalled();
expect(mockVideoStatsMonitor.stop).toHaveBeenCalled();
expect(options.callbacks.onAgentActivityStateChange).toHaveBeenCalledWith(AgentActivityState.Idle);

clearIntervalSpy.mockRestore();
});
});

Expand Down
9 changes: 7 additions & 2 deletions src/services/streaming-manager/edge-cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import {
const mockApi = StreamApiFactory.build();
jest.mock('../../api/streams', () => ({ createStreamApi: jest.fn(() => mockApi) }));

// Mock pollStats
// Mock createVideoStatsMonitor
const mockVideoStatsMonitor = {
start: jest.fn(),
stop: jest.fn(),
getReport: jest.fn(() => ({})),
};
jest.mock('./stats/poll', () => ({
pollStats: jest.fn(() => 123), // mock interval id
createVideoStatsMonitor: jest.fn(() => mockVideoStatsMonitor),
}));

// Mock other dependencies as needed
Expand Down
2 changes: 1 addition & 1 deletion src/services/streaming-manager/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
StreamingManagerOptions,
TransportProvider,
} from '../../types';
import { createStreamingManager, StreamApiVersion } from './factory';
import { StreamApiVersion, createStreamingManager } from './factory';

const mockCreateWebRTCStreamingManager = jest.fn();
jest.mock('./webrtc-manager', () => ({
Expand Down
Loading