115 lines
3.1 KiB
TypeScript
115 lines
3.1 KiB
TypeScript
import {
|
|
incrementRecordingTrackPackets,
|
|
registerRecordingPeerCandidate,
|
|
registerRecordingPeerOffer,
|
|
registerRecordingPeerTrack,
|
|
resetRecordingAgents,
|
|
startRecordingAgent,
|
|
stopRecordingAgent
|
|
} from '../src/recording/agent';
|
|
import { RecordingSession } from '../src/recording/session-manager';
|
|
|
|
const session: RecordingSession = {
|
|
id: 'recording-1',
|
|
connectionId: 'room-1',
|
|
status: 'recording',
|
|
layout: 'grid',
|
|
format: 'webm',
|
|
createdAt: '2026-06-01T00:00:00.000Z',
|
|
startedAt: '2026-06-01T00:00:00.000Z',
|
|
updatedAt: '2026-06-01T00:00:00.000Z'
|
|
};
|
|
|
|
describe('recording agent', () => {
|
|
beforeEach(() => {
|
|
resetRecordingAgents();
|
|
});
|
|
|
|
test('starts an awaiting media adapter agent', () => {
|
|
const agent = startRecordingAgent(session);
|
|
|
|
expect(agent).toEqual(expect.objectContaining({
|
|
id: 'recorder_recording-1',
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
status: 'awaiting-media-adapter',
|
|
mediaMode: 'webrtc-sendonly'
|
|
}));
|
|
});
|
|
|
|
test('stores peer offers for an active agent', () => {
|
|
startRecordingAgent(session);
|
|
const offer = registerRecordingPeerOffer({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
sdp: 'test-sdp'
|
|
});
|
|
|
|
expect(offer).toEqual(expect.objectContaining({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
sdp: 'test-sdp'
|
|
}));
|
|
});
|
|
|
|
test('stores peer candidates for an active agent', () => {
|
|
const agent = startRecordingAgent(session);
|
|
const candidate = registerRecordingPeerCandidate({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
candidate: 'candidate:1',
|
|
sdpMid: '0',
|
|
sdpMLineIndex: 0
|
|
});
|
|
|
|
expect(candidate).toEqual(expect.objectContaining({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
candidate: 'candidate:1'
|
|
}));
|
|
expect(agent.peerCandidates.get('participant-1')).toEqual([candidate]);
|
|
});
|
|
|
|
test('tracks received media and packet counts', () => {
|
|
const agent = startRecordingAgent(session);
|
|
const track = registerRecordingPeerTrack({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
kind: 'video',
|
|
trackId: 'track-1'
|
|
});
|
|
|
|
incrementRecordingTrackPackets({
|
|
recordingId: 'recording-1',
|
|
participantId: 'participant-1',
|
|
trackId: 'track-1'
|
|
});
|
|
|
|
expect(agent.status).toBe('receiving-media');
|
|
expect(track).toEqual(expect.objectContaining({
|
|
recordingId: 'recording-1',
|
|
participantId: 'participant-1',
|
|
kind: 'video',
|
|
trackId: 'track-1',
|
|
rtpPackets: 1
|
|
}));
|
|
});
|
|
|
|
test('rejects offers when the agent is stopped', () => {
|
|
startRecordingAgent(session);
|
|
stopRecordingAgent('recording-1');
|
|
|
|
expect(registerRecordingPeerOffer({
|
|
recordingId: 'recording-1',
|
|
connectionId: 'room-1',
|
|
participantId: 'participant-1',
|
|
sdp: 'test-sdp'
|
|
})).toBeNull();
|
|
});
|
|
});
|