Skip to content

Commit e4dadd7

Browse files
committed
browser-emulator: stop and remove ffmpeg container when removing participant
1 parent 681228d commit e4dadd7

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

browser-emulator/src/services/browser/emulated/emulated-browser.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface EmulatedContainerInfo {
1313
containerId: string;
1414
sessionName: string;
1515
userName: string;
16+
ffmpegContainerName?: string;
1617
createdAt: Date;
1718
}
1819

@@ -111,6 +112,11 @@ export class EmulatedBrowserService {
111112
containerId,
112113
sessionName,
113114
userName: userId,
115+
ffmpegContainerName:
116+
properties.role === Role.PUBLISHER &&
117+
(properties.video || properties.audio)
118+
? ffmpegContainerName
119+
: undefined,
114120
createdAt: new Date(),
115121
});
116122

@@ -258,6 +264,21 @@ export class EmulatedBrowserService {
258264
return;
259265
}
260266

267+
// Stop ffmpeg container if present
268+
if (containerInfo.ffmpegContainerName) {
269+
try {
270+
await this.dockerService.stopContainer(
271+
containerInfo.ffmpegContainerName,
272+
);
273+
} catch (error) {
274+
console.error(
275+
`Error stopping ffmpeg container ${containerInfo.ffmpegContainerName} for ${connectionId}:`,
276+
error,
277+
);
278+
}
279+
}
280+
281+
// Stop join container
261282
try {
262283
await this.dockerService.stopContainer(containerInfo.containerId);
263284
} catch (error) {

browser-emulator/tests/unit/emulated-browser.service.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ describe('EmulatedBrowserService', () => {
203203
await service.deleteStreamManagerWithConnectionId(connectionId);
204204

205205
expect(mockDockerService.stopContainer).toHaveBeenCalled();
206+
// Ensure ffmpeg container was also stopped
207+
expect(mockDockerService.stopContainer).toHaveBeenCalledWith(
208+
expect.stringContaining('ffmpeg-emulated-'),
209+
);
210+
// Ensure join container (startContainer return value) was stopped
211+
expect(mockDockerService.stopContainer).toHaveBeenCalledWith(
212+
'container-id-123',
213+
);
206214
expect(mockDockerService.removeContainer).toHaveBeenCalled();
207215
});
208216
});
@@ -231,6 +239,9 @@ describe('EmulatedBrowserService', () => {
231239
);
232240

233241
expect(mockDockerService.stopContainer).toHaveBeenCalled();
242+
expect(mockDockerService.stopContainer).toHaveBeenCalledWith(
243+
expect.stringContaining('ffmpeg-emulated-'),
244+
);
234245
// Verify container is no longer tracked
235246
expect(
236247
service.getParticipantContainerId(connectionId),
@@ -268,6 +279,9 @@ describe('EmulatedBrowserService', () => {
268279
await service.clean();
269280

270281
expect(mockDockerService.stopContainer).toHaveBeenCalled();
282+
expect(mockDockerService.stopContainer).toHaveBeenCalledWith(
283+
expect.stringContaining('ffmpeg-emulated-'),
284+
);
271285
// Verify container is no longer tracked
272286
expect(
273287
service.getParticipantContainerId(connectionId),

0 commit comments

Comments
 (0)