Skip to content

Commit 9d66e6e

Browse files
[IMP] fixup
1 parent acd9ceb commit 9d66e6e

File tree

8 files changed

+67
-24
lines changed

8 files changed

+67
-24
lines changed

src/models/channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type SessionInfo
1414
} from "#src/models/session.ts";
1515
import { Recorder } from "#src/models/recorder.ts";
16-
import { getWorker, type RtcWorker } from "#src/services/rtc.ts";
16+
import { getWorker, type RtcWorker } from "#src/services/resources.ts";
1717

1818
const logger = new Logger("CHANNEL");
1919

src/models/ffmpeg.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { EventEmitter } from "node:events";
2+
3+
export class FFMPEG extends EventEmitter {
4+
5+
constructor() {
6+
super();
7+
}
8+
}

src/models/recorder.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import {EventEmitter} from "node:events";
1+
import { EventEmitter } from "node:events";
22
import type { Channel } from "./channel";
3-
import {Logger} from "#src/utils/utils.ts";
3+
import { getFolder } from "#src/services/resources";
4+
import { Logger } from "#src/utils/utils.ts";
45

6+
export enum RECORDER_STATE {
7+
STARTED = "started",
8+
STOPPED = "stopped",
9+
}
510
const logger = new Logger("RECORDER");
611

712
export class Recorder extends EventEmitter {
813
channel: Channel;
9-
state: "started" | "stopped" = "stopped";
14+
state: RECORDER_STATE = RECORDER_STATE.STOPPED;
1015
ffmpeg = null;
16+
destPath: string | undefined;
1117
/** Path to which the final recording will be uploaded to */
1218
recordingAddress: string;
1319

@@ -18,16 +24,28 @@ export class Recorder extends EventEmitter {
1824
}
1925

2026
async start() {
21-
this.state = "started";
22-
logger.trace("TO IMPLEMENT");
23-
// TODO ffmpeg instance creation, start
27+
if (this.state === RECORDER_STATE.STOPPED) {
28+
const { path, sealFolder } = getFolder();
29+
this.destPath = path;
30+
this.once("stopped", sealFolder);
31+
this.state = RECORDER_STATE.STARTED;
32+
logger.trace("TO IMPLEMENT");
33+
// TODO ffmpeg instance creation for recording to destPath with proper name, start, build timestamps object
34+
}
35+
2436
return { state: this.state };
2537
}
2638

2739
async stop() {
28-
this.state = "stopped";
29-
logger.trace("TO IMPLEMENT");
30-
// TODO ffmpeg instance stop, cleanup, save,...
40+
if (this.state === RECORDER_STATE.STARTED) {
41+
42+
logger.trace("TO IMPLEMENT");
43+
this.emit("stopped");
44+
// TODO ffmpeg instance stop, cleanup,
45+
// only resolve promise and switch state when completely ready to start a new recording.
46+
this.state = RECORDER_STATE.STOPPED;
47+
}
48+
3149
return { state: this.state };
3250
}
3351
}

src/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as rtc from "#src/services/rtc.ts";
1+
import * as resources from "#src/services/resources.ts";
22
import * as http from "#src/services/http.ts";
33
import * as auth from "#src/services/auth.ts";
44
import { Logger } from "#src/utils/utils.ts";
@@ -8,15 +8,15 @@ const logger = new Logger("SERVER", { logLevel: "all" });
88

99
async function run(): Promise<void> {
1010
auth.start();
11-
await rtc.start();
11+
await resources.start();
1212
await http.start();
1313
logger.info(`ready - PID: ${process.pid}`);
1414
}
1515

1616
function cleanup(): void {
1717
Channel.closeAll();
1818
http.close();
19-
rtc.close();
19+
resources.close();
2020
logger.info("cleanup complete");
2121
}
2222

src/services/rtc.ts renamed to src/services/resources.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface RtcWorker extends mediasoup.types.Worker {
1010
};
1111
}
1212

13-
const logger = new Logger("RTC");
13+
const logger = new Logger("RESOURCES");
1414
const workers = new Set<RtcWorker>();
1515

1616
export async function start(): Promise<void> {
@@ -76,3 +76,20 @@ export async function getWorker(): Promise<mediasoup.types.Worker> {
7676
logger.debug(`worker ${leastUsedWorker!.pid} with ${lowestUsage} ru_maxrss was selected`);
7777
return leastUsedWorker;
7878
}
79+
80+
export function getFolder() {
81+
// create a temp folder at a path, returns the path and a function to seal the folder
82+
return {
83+
path: "",
84+
sealFolder: () => {
85+
// move the content into a permanent folder location so it can easily be retrieved for processing later
86+
// or directly forward for transcription
87+
},
88+
}
89+
}
90+
91+
export function getPort() {
92+
}
93+
94+
export function releasePort(port: number) {
95+
}

tests/models.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { describe, beforeEach, afterEach, expect, jest } from "@jest/globals";
22

3-
import * as rtc from "#src/services/rtc";
3+
import * as resources from "#src/services/resources";
44
import { Channel } from "#src/models/channel";
55
import { timeouts, CHANNEL_SIZE } from "#src/config";
66
import { OvercrowdedError } from "#src/utils/errors";
77

88
describe("Models", () => {
99
beforeEach(async () => {
10-
await rtc.start();
10+
await resources.start();
1111
});
1212
afterEach(() => {
1313
Channel.closeAll();
14-
rtc.close();
14+
resources.close();
1515
});
1616
test("Create channel and session", async () => {
1717
const channel = await Channel.create("testRemote", "testIssuer");

tests/rtc.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { afterEach, beforeEach, describe, expect } from "@jest/globals";
22

3-
import * as rtc from "#src/services/rtc";
3+
import * as resources from "#src/services/resources";
44
import * as config from "#src/config";
55

66
describe("rtc service", () => {
77
beforeEach(async () => {
8-
await rtc.start();
8+
await resources.start();
99
});
1010
afterEach(() => {
11-
rtc.close();
11+
resources.close();
1212
});
1313
test("worker load should be evenly distributed", async () => {
1414
const usedWorkers = new Set();
1515
for (let i = 0; i < config.NUM_WORKERS; ++i) {
16-
const worker = await rtc.getWorker();
16+
const worker = await resources.getWorker();
1717
const router = await worker.createRouter({});
1818
const webRtcServer = await worker.createWebRtcServer(config.rtc.rtcServerOptions);
1919
const promises = [];

tests/utils/network.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fakeParameters from "mediasoup-client/lib/test/fakeParameters";
55

66
import * as auth from "#src/services/auth";
77
import * as http from "#src/services/http";
8-
import * as rtc from "#src/services/rtc";
8+
import * as resources from "#src/services/resources";
99
import { SfuClient, SfuClientState } from "#src/client";
1010
import { Channel } from "#src/models/channel";
1111
import type { Session } from "#src/models/session";
@@ -69,7 +69,7 @@ export class LocalNetwork {
6969
this.port = port;
7070

7171
// Start all services in correct order
72-
await rtc.start();
72+
await resources.start();
7373
await http.start({ httpInterface: hostname, port });
7474
await auth.start(HMAC_B64_KEY);
7575
}
@@ -217,7 +217,7 @@ export class LocalNetwork {
217217
// Stop all services
218218
auth.close();
219219
http.close();
220-
rtc.close();
220+
resources.close();
221221

222222
// Clear network info
223223
this.hostname = undefined;

0 commit comments

Comments
 (0)