Skip to content

Commit ac7a58e

Browse files
[IMP] fixup
1 parent acd9ceb commit ac7a58e

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

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/services/resources.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export async function start(): Promise<void> {
2+
// monitors server resources, generate workers to build the streams from the permanent folders
3+
}
4+
export async function stop(): Promise<void> {
5+
}
6+
7+
export function getFolder() {
8+
// create a temp folder at a path, returns the path and a function to seal the folder
9+
return {
10+
path: "",
11+
sealFolder: () => {
12+
// move the content into a permanent folder location so it can easily be retrieved for processing later
13+
// or directly forward for transcription
14+
},
15+
}
16+
}

0 commit comments

Comments
 (0)