11'use strict' ;
22
33const { PassThrough } = require ( 'stream' )
4+ const fs = require ( 'fs' )
45
56const { RTCAudioSink, RTCVideoSink } = require ( 'wrtc' ) . nonstandard ;
67
78const ffmpeg = require ( 'fluent-ffmpeg' )
89const { StreamInput } = require ( 'fluent-ffmpeg-multistream' )
9- const fs = require ( 'fs' )
1010
1111const VIDEO_OUTPUT_SIZE = '320x240'
1212const VIDEO_OUTPUT_FILE = './recording.mp4'
@@ -22,9 +22,9 @@ function beforeOffer(peerConnection) {
2222
2323 const streams = [ ] ;
2424
25- videoSink . addEventListener ( 'frame' , function ( { frame : { width, height, data } } ) {
25+ videoSink . addEventListener ( 'frame' , ( { frame : { width, height, data } } ) => {
2626 const size = width + 'x' + height ;
27- if ( ! streams [ 0 ] || ( streams [ 0 ] && streams [ 0 ] . size !== size ) ) {
27+ if ( ! streams [ 0 ] || ( streams [ 0 ] && streams [ 0 ] . size !== size ) ) {
2828 UID ++ ;
2929
3030 const stream = {
@@ -34,24 +34,24 @@ function beforeOffer(peerConnection) {
3434 audio : new PassThrough ( )
3535 } ;
3636
37- const onAudioData = function ( { samples : { buffer } } ) {
38- if ( ! stream . end ) {
37+ const onAudioData = ( { samples : { buffer } } ) => {
38+ if ( ! stream . end ) {
3939 stream . audio . push ( Buffer . from ( buffer ) ) ;
4040 }
4141 } ;
4242
43- audioSink . addEventListener ( 'data' , onAudioData )
43+ audioSink . addEventListener ( 'data' , onAudioData ) ;
4444
45- stream . audio . on ( 'end' , ( ) => {
46- audioSink . removeEventListener ( 'data' , onAudioData )
47- } )
45+ stream . audio . on ( 'end' , ( ) => {
46+ audioSink . removeEventListener ( 'data' , onAudioData ) ;
47+ } ) ;
4848
49- streams . unshift ( stream )
49+ streams . unshift ( stream ) ;
5050
5151 streams . forEach ( item => {
52- if ( item !== stream && ! item . end ) {
52+ if ( item !== stream && ! item . end ) {
5353 item . end = true ;
54- if ( item . audio ) {
54+ if ( item . audio ) {
5555 item . audio . end ( ) ;
5656 }
5757 item . video . end ( ) ;
@@ -80,34 +80,34 @@ function beforeOffer(peerConnection) {
8080 console . log ( 'Stop recording >> ' , stream . recordPath )
8181 } )
8282 . size ( VIDEO_OUTPUT_SIZE )
83- . output ( stream . recordPath )
83+ . output ( stream . recordPath ) ;
8484
85- stream . proc . run ( )
85+ stream . proc . run ( ) ;
8686 }
8787
8888 streams [ 0 ] . video . push ( Buffer . from ( data ) ) ;
89- } )
89+ } ) ;
9090
9191 const { close } = peerConnection ;
9292 peerConnection . close = function ( ) {
9393 audioSink . stop ( ) ;
9494 videoSink . stop ( ) ;
9595
9696 streams . forEach ( ( { audio, video, end, proc, recordPath } ) => {
97- if ( ! end ) {
98- if ( audio ) {
97+ if ( ! end ) {
98+ if ( audio ) {
9999 audio . end ( ) ;
100100 }
101101 video . end ( ) ;
102102 }
103- } )
103+ } ) ;
104104
105105 let totalEnd = 0 ;
106106 const timer = setInterval ( ( ) => {
107107 streams . forEach ( stream => {
108- if ( stream . recordEnd ) {
108+ if ( stream . recordEnd ) {
109109 totalEnd ++ ;
110- if ( totalEnd === streams . length ) {
110+ if ( totalEnd === streams . length ) {
111111 clearTimeout ( timer ) ;
112112
113113 const mergeProc = ffmpeg ( )
@@ -123,15 +123,15 @@ function beforeOffer(peerConnection) {
123123
124124 streams . forEach ( ( { recordPath } ) => {
125125 mergeProc . addInput ( recordPath )
126- } )
126+ } ) ;
127127
128128 mergeProc
129129 . output ( VIDEO_OUTPUT_FILE )
130130 . run ( ) ;
131131 }
132132 }
133- } )
134- } , 1000 )
133+ } ) ;
134+ } , 1000 )
135135
136136 return close . apply ( this , arguments ) ;
137137 }
0 commit comments