@@ -113,8 +113,11 @@ export class Recorder extends EventEmitter {
113
113
async _start_fragment ( ids ) {
114
114
const oldProcess = this . ffmpeg ;
115
115
this . state = RECORDER_STATE . UPDATING ;
116
+ /** @type {RtpData[] } */
116
117
const audioRtps = [ ] ;
118
+ /** @type {RtpData[] } */
117
119
const cameraRtps = [ ] ;
120
+ /** @type {RtpData[] } */
118
121
const screenRtps = [ ] ;
119
122
for ( const id of ids ) {
120
123
const session = this . channel . sessions . get ( id ) ;
@@ -123,22 +126,25 @@ export class Recorder extends EventEmitter {
123
126
continue ;
124
127
}
125
128
if ( audioRtps . length < recording . audioLimit ) {
126
- const audioRtpData = session . getRtp ( STREAM_TYPE . AUDIO ) ;
129
+ const audioRtpData = await session . getRtp ( STREAM_TYPE . AUDIO ) ;
127
130
audioRtpData && audioRtps . push ( audioRtpData ) ;
128
131
}
129
132
if ( cameraRtps . length < recording . cameraLimit ) {
130
- const cameraRtpData = session . getRtp ( STREAM_TYPE . CAMERA ) ;
133
+ const cameraRtpData = await session . getRtp ( STREAM_TYPE . CAMERA ) ;
131
134
cameraRtpData && cameraRtps . push ( cameraRtpData ) ;
132
135
}
133
136
if ( screenRtps . length < recording . screenLimit ) {
134
- const screenRtpData = session . getRtp ( STREAM_TYPE . SCREEN ) ;
137
+ const screenRtpData = await session . getRtp ( STREAM_TYPE . SCREEN ) ;
135
138
screenRtpData && screenRtps . push ( screenRtpData ) ;
136
139
}
137
140
}
138
- const tempPath = path . join ( recording . directory , `call_${ Date . now ( ) } .${ recording . fileType } ` ) ;
141
+ const tempPath = path . join (
142
+ recording . directory ,
143
+ `__FRAGMENT__-${ this . uuid } -${ Date . now ( ) } .${ recording . fileType } `
144
+ ) ;
139
145
this . ffmpeg = new FFMPEG ( tempPath ) ;
140
146
try {
141
- await this . ffmpeg . start ( audioRtps , screenRtps , cameraRtps ) ; // args should be base on the rtp transports
147
+ await this . ffmpeg . merge ( { audioRtps, screenRtps, cameraRtps } ) ; // args should be base on the rtp transports
142
148
this . state = RECORDER_STATE . RECORDING ;
143
149
} catch ( error ) {
144
150
logger . error ( `Failed to start recording: ${ error . message } ` ) ;
@@ -206,6 +212,11 @@ export class Recorder extends EventEmitter {
206
212
if ( filePaths . length === 1 ) {
207
213
return filePaths [ 0 ] ;
208
214
}
209
- return filePaths [ 1 ] ; // TODO merge logic with FFMPEG
215
+ const ffmpeg = new FFMPEG (
216
+ path . join ( recording . directory , `__MERGED__-${ this . uuid } .${ recording . fileType } ` )
217
+ ) ;
218
+ // should await for ffmpeg complete event.
219
+ await ffmpeg . concat ( filePaths ) ;
220
+ return "" ; // TODO merge logic with FFMPEG
210
221
}
211
222
}
0 commit comments