11import { EventEmitter } from "node:events" ;
22import type { Channel } from "./channel" ;
33import { getFolder } from "#src/services/resources.ts" ;
4+ import type { Folder } from "#src/services/resources.ts" ;
45import { Logger } from "#src/utils/utils.ts" ;
56
67export enum RECORDER_STATE {
@@ -12,8 +13,8 @@ const logger = new Logger("RECORDER");
1213export class Recorder extends EventEmitter {
1314 channel : Channel ;
1415 state : RECORDER_STATE = RECORDER_STATE . STOPPED ;
16+ folder : Folder | undefined ;
1517 ffmpeg = null ;
16- destPath : string | undefined ;
1718 /** Path to which the final recording will be uploaded to */
1819 recordingAddress : string ;
1920
@@ -25,14 +26,10 @@ export class Recorder extends EventEmitter {
2526
2627 async start ( ) {
2728 if ( this . state === RECORDER_STATE . STOPPED ) {
28- const folder = getFolder ( ) ;
29- this . destPath = folder . path ;
30- this . once ( "stopped" , ( { name } ) => {
31- folder . seal ( name ) ;
32- } ) ;
29+ this . folder = getFolder ( ) ;
3330 this . state = RECORDER_STATE . STARTED ;
3431 logger . trace ( "TO IMPLEMENT" ) ;
35- // TODO ffmpeg instance creation for recording to destPath with proper name, start, build timestamps object
32+ // TODO ffmpeg instance creation for recording to folder.path with proper name, start, build timestamps object
3633 }
3734 this . _record ( ) ;
3835 return { state : this . state } ;
@@ -41,7 +38,8 @@ export class Recorder extends EventEmitter {
4138 async stop ( ) {
4239 if ( this . state === RECORDER_STATE . STARTED ) {
4340 logger . trace ( "TO IMPLEMENT" ) ;
44- this . emit ( "stopped" , { name : "test" } ) ;
41+ await this . folder ! . seal ( "test-name" ) ;
42+ this . folder = undefined ;
4543 // TODO ffmpeg instance stop, cleanup,
4644 // only resolve promise and switch state when completely ready to start a new recording.
4745 this . state = RECORDER_STATE . STOPPED ;
0 commit comments