1- import { EventEmitter } from "node:events" ;
1+ import { EventEmitter } from "node:events" ;
22import 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+ }
510const logger = new Logger ( "RECORDER" ) ;
611
712export 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}
0 commit comments