forked from phoboslab/jsmpeg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
media-control.js
52 lines (38 loc) · 1.16 KB
/
media-control.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const argv = require('minimist')(process.argv.slice(2));
const {wsClient} = require('./module-wsClient.js');
const {PcmFromFile, JpegsPcmFromFile} = require('./module-transcode.js');
let host = argv.host? argv.host : 'localhost:8080';
let mode = argv.mode? argv.mode: 'audio';
let input = argv.input? argv.input : __dirname + '/public/media/mp3/clapping.mp3';
let interval = 300;
let pcmClient = wsClient( 'ws://'+host+'/stream/pcm', interval, (data)=> {
if ( data === null ) {
console.log( 'pcm client connected' );
return;
}
console.log( data );
});
let mjpegClient = wsClient( 'ws://'+host+'/stream/mjpeg', interval, (data)=> {
if ( data === null ) {
console.log( 'mjpeg client connected' );
return;
}
console.log( data );
});
let source;
source = new PcmFromFile( null, input, pcmClient.send.bind(pcmClient), (msg)=>{
console.log('finish ' + msg);
}).start((cmdline)=>{
console.log(cmdline);
});
return;
//-------------------------------------
source = new MjpegPcmFromFile( null,
input,
data=>mjpegClient.send(data),
data=>pcmClient.send(data)
).start(()=>{
console.log('pushing ' + input );
});
return;
//-------------------------------------