Skip to content

Commit e3b3937

Browse files
first test
1 parent 017bc68 commit e3b3937

20 files changed

+230
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
package-lock.json
3+
dist

.gitignore copy

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.idea/
3+
js/node_modules

.npmignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
.idea/
3+
js/node_modules
4+
docs/
5+
examples/
6+
janus-gateway/
7+
build_janus.sh
8+

bin/linux/janus

1.07 MB
Binary file not shown.

bin/linux/janus-cfgconv

125 KB
Binary file not shown.

bin/linux/janus-pp-rec

315 KB
Binary file not shown.

bin/linux/mjr2pcap

99.1 KB
Binary file not shown.

dev/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

dev/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { JanusPPRecJs } from 'janus-pp-rec-js'
2+
import { dirname } from 'path'
3+
import { fileURLToPath } from 'url'
4+
import { join } from 'path'
5+
const __dirname = dirname(fileURLToPath(import.meta.url))
6+
const mjrFilePath = join(
7+
__dirname,
8+
'recordings/0a2c4fae3b5e38d6b0fdad6ea014b293-peer-audio.mjr'
9+
)
10+
const wavFilePath = join(
11+
__dirname,
12+
'recordings/0a2c4fae3b5e38d6b0fdad6ea014b293-peer-audio.wav'
13+
)
14+
JanusPPRecJs.createWavFromMjr(mjrFilePath, wavFilePath)

dev/package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "dev",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index.js"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"janus-pp-rec-js": "file:../janus-pp-rec-js-1.0.0.tgz"
13+
}
14+
}
Binary file not shown.
Binary file not shown.

janus-pp-rec-js-1.0.0.tgz

490 KB
Binary file not shown.

package.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "janus-pp-rec-js",
3+
"version": "1.0.0",
4+
"description": "a simple js wrapper around janus-pp-rec which is used to convert mjr files to one of playable media format",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/flutterjanus/janus-pp-rec-js.git"
8+
},
9+
"bugs": {
10+
"url": "https://github.com/flutterjanus/janus-pp-rec-js/issues"
11+
},
12+
"homepage": "https://github.com/flutterjanus/janus-pp-rec-js#readme",
13+
"typings": "dist",
14+
"main": "dist/index.js",
15+
"scripts": {
16+
"build": "tsc",
17+
"doc": "npx typedoc src/index.ts"
18+
},
19+
"keywords": [
20+
"janusjs",
21+
"webrtc",
22+
"janus-gateway",
23+
"videoroom",
24+
"sip"
25+
],
26+
"files": [
27+
"dist/*",
28+
"bin"
29+
],
30+
"author": "[email protected]",
31+
"license": "ISC",
32+
"dependencies": {
33+
"@ffmpeg-installer/ffmpeg": "^1.1.0",
34+
"aigle": "1.14.1",
35+
"child_process": "^1.0.2",
36+
"fluent-ffmpeg": "^2.1.3",
37+
"lodash": "4.17.21",
38+
"rxjs": "^7.5.5",
39+
"typedoc": "0.22.15",
40+
"webrtc-adapter": "8.1.1"
41+
},
42+
"devDependencies": {
43+
"@types/es6-promise": "3.3.0",
44+
"@types/lodash": "4.14.182",
45+
"@types/node": "^20.14.7",
46+
"typescript": "^5.5.2"
47+
},
48+
"prettier": {
49+
"trailingComma": "es5",
50+
"tabWidth": 4,
51+
"proseWrap": "preserve",
52+
"printWidth": 80,
53+
"semi": false,
54+
"singleQuote": true
55+
}
56+
}

src/core/converter.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import _ from "lodash";
2+
import ffmpegPath from "@ffmpeg-installer/ffmpeg";
3+
import ffmpeg from "fluent-ffmpeg";
4+
import { spawnObservable } from "./spawn.js";
5+
6+
ffmpeg.setFfmpegPath(ffmpegPath.path);
7+
8+
export function addBufferOutput(bufferOutputs, bufferString, maxBufferSize = 50) {
9+
const newBufferOutputs = [...bufferOutputs, bufferString];
10+
if (newBufferOutputs.length > maxBufferSize) {
11+
newBufferOutputs.shift(); // Remove the oldest element (from the beginning of the array)
12+
}
13+
return newBufferOutputs;
14+
}
15+
16+
export const downMixAudioFiles = (outputFilePath, ...inputFilePaths) => {
17+
return new Promise((resolve, reject) => {
18+
const command = ffmpeg();
19+
_.each(inputFilePaths, (path) => {
20+
command.addInput(path);
21+
});
22+
command
23+
.complexFilter([`amix=inputs=${_.size(inputFilePaths)}:duration=longest`])
24+
.output(outputFilePath)
25+
.on("error", (err) => {
26+
reject(err);
27+
})
28+
.on("end", function (err, stdout, stderr) {
29+
resolve(true);
30+
})
31+
.run();
32+
});
33+
};

src/core/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './spawn'
2+
export * from './converter'

src/core/spawn.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Subject } from "rxjs";
2+
import { spawn, SpawnOptionsWithoutStdio } from "child_process";
3+
4+
export const spawnObservable = (cmd, args, spawnOptions: SpawnOptionsWithoutStdio = { shell: true }) => {
5+
const observable = new Subject();
6+
const errorObservable = new Subject();
7+
const writeObservable = new Subject();
8+
9+
const runCommand = spawn(cmd, args, spawnOptions);
10+
writeObservable.subscribe({
11+
next: (data) => {
12+
runCommand.stdin.write(data);
13+
},
14+
});
15+
runCommand.stdout.on("close", (code) => {
16+
observable.complete();
17+
});
18+
19+
runCommand.stdout.on("data", (data) => {
20+
if (data) {
21+
observable.next(data.toString());
22+
}
23+
});
24+
runCommand.stderr.on("close", (code) => {
25+
errorObservable.complete();
26+
});
27+
28+
runCommand.stderr.on("data", (data) => {
29+
if (data) {
30+
errorObservable.next(data.toString());
31+
}
32+
});
33+
return { errorObservable, events: observable.asObservable(), sender: writeObservable };
34+
};

src/index.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import _ from 'lodash'
2+
import { addBufferOutput, spawnObservable } from './core'
3+
import { dirname } from 'path';
4+
import { fileURLToPath } from 'url';
5+
import { join } from 'path'
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
8+
export class JanusPPRecJs {
9+
static async createWavFromMjr(mjrPath: string, wavPath: string) {
10+
const { events: converter, errorObservable } = spawnObservable(`janus-pp-rec`, [mjrPath, wavPath], {
11+
shell: true,
12+
cwd: join(__dirname, "../bin/linux")
13+
});
14+
return new Promise((resolve, reject) => {
15+
let outputBuffer = [];
16+
let errorBuffer = [];
17+
errorObservable.subscribe({
18+
next(data) {
19+
errorBuffer = addBufferOutput(errorBuffer, data, 100);
20+
},
21+
complete() {
22+
console.log(errorBuffer);
23+
reject({ error: _.join(errorBuffer, " ") });
24+
},
25+
});
26+
converter.subscribe({
27+
next(data) {
28+
outputBuffer = addBufferOutput(outputBuffer, data, 100);
29+
},
30+
complete() {
31+
const outputs = _.join(outputBuffer, " ");
32+
console.log(outputs);
33+
if (outputs.includes("No destination file") || outputs.includes("ERR")) {
34+
reject({ error: "bad mjr file" });
35+
}
36+
resolve(true);
37+
},
38+
});
39+
});
40+
};
41+
42+
}

src/interfaces/index.ts

Whitespace-only changes.

tsconfig.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist/",
4+
"experimentalDecorators": true,
5+
"noImplicitAny": false,
6+
"module": "ESNext",
7+
"allowSyntheticDefaultImports": true,
8+
"target": "es5",
9+
"types": ["node"],
10+
"declarationMap": true,
11+
"declaration": true,
12+
"allowJs": true,
13+
"moduleResolution": "node",
14+
"lib": ["ES5", "ES2015", "DOM", "ScriptHost"]
15+
},
16+
"typeRoots": ["node_modules/@types"],
17+
"include": ["src/**/*"],
18+
"exclude": ["node_modules", "janus-gateway"]
19+
}

0 commit comments

Comments
 (0)