@livekit/rtc-node 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +21 -0
- package/build.rs +5 -0
- package/dist/audio_frame.d.ts +14 -0
- package/dist/audio_frame.d.ts.map +1 -0
- package/dist/audio_frame.js +36 -0
- package/dist/audio_frame.js.map +1 -0
- package/dist/audio_source.d.ts +14 -0
- package/dist/audio_source.d.ts.map +1 -0
- package/dist/audio_source.js +42 -0
- package/dist/audio_source.js.map +1 -0
- package/dist/audio_stream.d.ts +24 -0
- package/dist/audio_stream.d.ts.map +1 -0
- package/dist/audio_stream.js +54 -0
- package/dist/audio_stream.js.map +1 -0
- package/dist/e2ee.d.ts +44 -0
- package/dist/e2ee.d.ts.map +1 -0
- package/dist/e2ee.js +232 -0
- package/dist/e2ee.js.map +1 -0
- package/dist/ffi_client.d.ts +23 -0
- package/dist/ffi_client.d.ts.map +1 -0
- package/dist/ffi_client.js +57 -0
- package/dist/ffi_client.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/native.d.ts +14 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +297 -0
- package/dist/native.js.map +1 -0
- package/dist/participant.d.ts +30 -0
- package/dist/participant.d.ts.map +1 -0
- package/dist/participant.js +120 -0
- package/dist/participant.js.map +1 -0
- package/dist/proto/audio_frame_pb.d.ts +556 -0
- package/dist/proto/audio_frame_pb.d.ts.map +1 -0
- package/dist/proto/audio_frame_pb.js +861 -0
- package/dist/proto/audio_frame_pb.js.map +1 -0
- package/dist/proto/e2ee_pb.d.ts +652 -0
- package/dist/proto/e2ee_pb.d.ts.map +1 -0
- package/dist/proto/e2ee_pb.js +906 -0
- package/dist/proto/e2ee_pb.js.map +1 -0
- package/dist/proto/ffi_pb.d.ts +672 -0
- package/dist/proto/ffi_pb.d.ts.map +1 -0
- package/dist/proto/ffi_pb.js +459 -0
- package/dist/proto/ffi_pb.js.map +1 -0
- package/dist/proto/handle_pb.d.ts +30 -0
- package/dist/proto/handle_pb.d.ts.map +1 -0
- package/dist/proto/handle_pb.js +59 -0
- package/dist/proto/handle_pb.js.map +1 -0
- package/dist/proto/participant_pb.d.ts +54 -0
- package/dist/proto/participant_pb.d.ts.map +1 -0
- package/dist/proto/participant_pb.js +93 -0
- package/dist/proto/participant_pb.js.map +1 -0
- package/dist/proto/room_pb.d.ts +1480 -0
- package/dist/proto/room_pb.d.ts.map +1 -0
- package/dist/proto/room_pb.js +2172 -0
- package/dist/proto/room_pb.js.map +1 -0
- package/dist/proto/stats_pb.d.ts +1713 -0
- package/dist/proto/stats_pb.d.ts.map +1 -0
- package/dist/proto/stats_pb.js +2238 -0
- package/dist/proto/stats_pb.js.map +1 -0
- package/dist/proto/track_pb.d.ts +353 -0
- package/dist/proto/track_pb.d.ts.map +1 -0
- package/dist/proto/track_pb.js +550 -0
- package/dist/proto/track_pb.js.map +1 -0
- package/dist/proto/video_frame_pb.d.ts +855 -0
- package/dist/proto/video_frame_pb.d.ts.map +1 -0
- package/dist/proto/video_frame_pb.js +1214 -0
- package/dist/proto/video_frame_pb.js.map +1 -0
- package/dist/room.d.ts +95 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +285 -0
- package/dist/room.js.map +1 -0
- package/dist/track.d.ts +35 -0
- package/dist/track.d.ts.map +1 -0
- package/dist/track.js +72 -0
- package/dist/track.js.map +1 -0
- package/dist/track_publication.d.ts +31 -0
- package/dist/track_publication.d.ts.map +1 -0
- package/dist/track_publication.js +66 -0
- package/dist/track_publication.js.map +1 -0
- package/dist/video_frame.d.ts +111 -0
- package/dist/video_frame.d.ts.map +1 -0
- package/dist/video_frame.js +364 -0
- package/dist/video_frame.js.map +1 -0
- package/dist/video_source.d.ts +14 -0
- package/dist/video_source.d.ts.map +1 -0
- package/dist/video_source.js +44 -0
- package/dist/video_source.js.map +1 -0
- package/dist/video_stream.d.ts +24 -0
- package/dist/video_stream.d.ts.map +1 -0
- package/dist/video_stream.js +56 -0
- package/dist/video_stream.js.map +1 -0
- package/package.json +19 -14
- package/src/audio_frame.ts +45 -0
- package/src/audio_source.ts +64 -0
- package/src/audio_stream.ts +74 -0
- package/src/e2ee.ts +311 -0
- package/src/ffi_client.ts +68 -0
- package/src/index.ts +52 -0
- package/src/lib.rs +5 -0
- package/src/native.d.ts +14 -0
- package/src/native.js +269 -0
- package/src/nodejs.rs +115 -0
- package/src/participant.ts +171 -0
- package/src/proto/audio_frame_pb.ts +1121 -0
- package/src/proto/e2ee_pb.ts +1231 -0
- package/src/proto/ffi_pb.ts +969 -0
- package/src/proto/handle_pb.ts +69 -0
- package/src/proto/participant_pb.ts +121 -0
- package/src/proto/room_pb.ts +2843 -0
- package/src/proto/stats_pb.ts +2955 -0
- package/src/proto/track_pb.ts +683 -0
- package/src/proto/video_frame_pb.ts +1568 -0
- package/src/room.ts +370 -0
- package/src/track.ts +101 -0
- package/src/track_publication.ts +90 -0
- package/src/video_frame.ts +620 -0
- package/src/video_source.ts +61 -0
- package/src/video_stream.ts +76 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FfiHandle } from './ffi_client';
|
|
2
|
+
import { Track } from './track';
|
|
3
|
+
import TypedEmitter from 'typed-emitter';
|
|
4
|
+
import { VideoFrame } from './video_frame';
|
|
5
|
+
import { VideoStreamInfo } from './proto/video_frame_pb';
|
|
6
|
+
export type VideoStreamCallbacks = {
|
|
7
|
+
frameReceived: (frame: VideoFrame) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare enum VideoStreamEvent {
|
|
10
|
+
FrameReceived = "frameReceived"
|
|
11
|
+
}
|
|
12
|
+
declare const VideoStream_base: new () => TypedEmitter<VideoStreamCallbacks>;
|
|
13
|
+
export declare class VideoStream extends VideoStream_base {
|
|
14
|
+
/** @internal */
|
|
15
|
+
info: VideoStreamInfo;
|
|
16
|
+
/** @internal */
|
|
17
|
+
ffiHandle: FfiHandle;
|
|
18
|
+
track: Track;
|
|
19
|
+
constructor(track: Track);
|
|
20
|
+
private onEvent;
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=video_stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video_stream.d.ts","sourceRoot":"","sources":["../src/video_stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,SAAS,EAAc,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAoB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAGL,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF,oBAAY,gBAAgB;IAC1B,aAAa,kBAAkB;CAChC;0CAE2D,aAAa,oBAAoB,CAAC;AAA9F,qBAAa,WAAY,SAAQ,gBAA8D;IAC7F,gBAAgB;IAChB,IAAI,EAAE,eAAe,CAAC;IACtB,gBAAgB;IAChB,SAAS,EAAE,SAAS,CAAC;IAErB,KAAK,EAAE,KAAK,CAAC;gBAED,KAAK,EAAE,KAAK;IAsBxB,OAAO,CAAC,OAAO;IAsBf,KAAK;CAGN"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VideoStream = exports.VideoStreamEvent = void 0;
|
|
7
|
+
const ffi_client_1 = require("./ffi_client");
|
|
8
|
+
const events_1 = __importDefault(require("events"));
|
|
9
|
+
const video_frame_1 = require("./video_frame");
|
|
10
|
+
const video_frame_pb_1 = require("./proto/video_frame_pb");
|
|
11
|
+
var VideoStreamEvent;
|
|
12
|
+
(function (VideoStreamEvent) {
|
|
13
|
+
VideoStreamEvent["FrameReceived"] = "frameReceived";
|
|
14
|
+
})(VideoStreamEvent || (exports.VideoStreamEvent = VideoStreamEvent = {}));
|
|
15
|
+
class VideoStream extends events_1.default {
|
|
16
|
+
constructor(track) {
|
|
17
|
+
super();
|
|
18
|
+
this.track = track;
|
|
19
|
+
let req = new video_frame_pb_1.NewVideoStreamRequest({
|
|
20
|
+
type: video_frame_pb_1.VideoStreamType.VIDEO_STREAM_NATIVE,
|
|
21
|
+
trackHandle: track.ffi_handle.handle,
|
|
22
|
+
});
|
|
23
|
+
let res = ffi_client_1.FfiClient.instance.request({
|
|
24
|
+
message: {
|
|
25
|
+
case: 'newVideoStream',
|
|
26
|
+
value: req,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
this.info = res.stream.info;
|
|
30
|
+
this.ffiHandle = new ffi_client_1.FfiHandle(res.stream.handle.id);
|
|
31
|
+
ffi_client_1.FfiClient.instance.on(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent);
|
|
32
|
+
}
|
|
33
|
+
onEvent(ev) {
|
|
34
|
+
if (ev.message.case != 'videoStreamEvent' ||
|
|
35
|
+
ev.message.value.streamHandle != this.ffiHandle.handle) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let streamEvent = ev.message.value.message;
|
|
39
|
+
switch (streamEvent.case) {
|
|
40
|
+
case 'frameReceived':
|
|
41
|
+
let frameInfo = streamEvent.value.frame;
|
|
42
|
+
let buffer = video_frame_1.VideoFrameBuffer.fromOwnedInfo(streamEvent.value.buffer);
|
|
43
|
+
let frame = new video_frame_1.VideoFrame(Number(frameInfo.timestampUs), frameInfo.rotation, buffer);
|
|
44
|
+
this.emit(VideoStreamEvent.FrameReceived, frame);
|
|
45
|
+
break;
|
|
46
|
+
case 'eos':
|
|
47
|
+
ffi_client_1.FfiClient.instance.off(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
close() {
|
|
52
|
+
this.ffiHandle.dispose();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.VideoStream = VideoStream;
|
|
56
|
+
//# sourceMappingURL=video_stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video_stream.js","sourceRoot":"","sources":["../src/video_stream.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA0F;AAE1F,oDAAkC;AAElC,+CAA6D;AAC7D,2DAKgC;AAMhC,IAAY,gBAEX;AAFD,WAAY,gBAAgB;IAC1B,mDAA+B,CAAA;AACjC,CAAC,EAFW,gBAAgB,gCAAhB,gBAAgB,QAE3B;AAED,MAAa,WAAY,SAAS,gBAA6D;IAQ7F,YAAY,KAAY;QACtB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,GAAG,GAAG,IAAI,sCAAqB,CAAC;YAClC,IAAI,EAAE,gCAAe,CAAC,mBAAmB;YACzC,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM;SACrC,CAAC,CAAC;QAEH,IAAI,GAAG,GAAG,sBAAS,CAAC,QAAQ,CAAC,OAAO,CAAyB;YAC3D,OAAO,EAAE;gBACP,IAAI,EAAE,gBAAgB;gBACtB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAErD,sBAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,2BAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;IAEO,OAAO,CAAC,EAAY;QAC1B,IACE,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,kBAAkB;YACrC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EACtD,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,WAAW,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;QAC3C,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,eAAe;gBAClB,IAAI,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;gBACxC,IAAI,MAAM,GAAG,8BAAgB,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtE,IAAI,KAAK,GAAG,IAAI,wBAAU,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;gBACtF,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,KAAK;gBACR,sBAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,2BAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC9D,MAAM;QACV,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAvDD,kCAuDC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/rtc-node",
|
|
3
3
|
"description": "LiveKit RTC Node",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"version": "0.0.4",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
|
-
"
|
|
9
|
+
"dist",
|
|
10
|
+
"src",
|
|
11
|
+
"build.rs",
|
|
12
|
+
"Cargo.toml",
|
|
13
|
+
"Cargo.lock"
|
|
9
14
|
],
|
|
10
15
|
"napi": {
|
|
11
16
|
"name": "rtc-node",
|
|
@@ -20,14 +25,13 @@
|
|
|
20
25
|
]
|
|
21
26
|
}
|
|
22
27
|
},
|
|
23
|
-
"license": "Apache-2.0",
|
|
24
28
|
"dependencies": {
|
|
25
|
-
"@bufbuild/protobuf": "^1.4.2"
|
|
29
|
+
"@bufbuild/protobuf": "^1.4.2",
|
|
30
|
+
"typed-emitter": "^2.1.0"
|
|
26
31
|
},
|
|
27
32
|
"devDependencies": {
|
|
28
33
|
"@napi-rs/cli": "^2.16.5",
|
|
29
34
|
"@types/node": "^20.9.2",
|
|
30
|
-
"typed-emitter": "^2.1.0",
|
|
31
35
|
"typescript": "^5.2.2",
|
|
32
36
|
"prettier": "^3.0.3"
|
|
33
37
|
},
|
|
@@ -35,18 +39,19 @@
|
|
|
35
39
|
"node": ">= 10"
|
|
36
40
|
},
|
|
37
41
|
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
"build": "tsc && napi build --platform --release --dts src/native.d.ts --js src/native.js --pipe \"prettier -w\"",
|
|
42
|
+
"build:tsc": "tsc && cp src/native.d.ts dist/native.d.ts",
|
|
43
|
+
"build": "yarn build:tsc && napi build --platform --release --dts src/native.d.ts --js src/native.js --pipe \"prettier -w\"",
|
|
44
|
+
"artifacts": "yarn build:tsc && napi artifacts",
|
|
40
45
|
"build:debug": "napi build --platform",
|
|
41
46
|
"prepublishOnly": "napi prepublish -t npm",
|
|
42
47
|
"universal": "napi universal",
|
|
43
48
|
"version": "napi version"
|
|
44
49
|
},
|
|
45
50
|
"optionalDependencies": {
|
|
46
|
-
"@livekit/rtc-node-darwin-arm64": "0.0.
|
|
47
|
-
"@livekit/rtc-node-darwin-x64": "0.0.
|
|
48
|
-
"@livekit/rtc-node-linux-arm64-gnu": "0.0.
|
|
49
|
-
"@livekit/rtc-node-linux-x64-gnu": "0.0.
|
|
50
|
-
"@livekit/rtc-node-win32-x64-msvc": "0.0.
|
|
51
|
+
"@livekit/rtc-node-darwin-arm64": "0.0.4",
|
|
52
|
+
"@livekit/rtc-node-darwin-x64": "0.0.4",
|
|
53
|
+
"@livekit/rtc-node-linux-arm64-gnu": "0.0.4",
|
|
54
|
+
"@livekit/rtc-node-linux-x64-gnu": "0.0.4",
|
|
55
|
+
"@livekit/rtc-node-win32-x64-msvc": "0.0.4"
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FfiClient, FfiHandle } from './ffi_client';
|
|
2
|
+
import { AudioFrameBufferInfo, OwnedAudioFrameBuffer } from './proto/audio_frame_pb';
|
|
3
|
+
|
|
4
|
+
export class AudioFrame {
|
|
5
|
+
data: Uint16Array;
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
channels: number;
|
|
8
|
+
samplesPerChannel: number;
|
|
9
|
+
|
|
10
|
+
constructor(data: Uint16Array, sampleRate: number, channels: number, samplesPerChannel: number) {
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.sampleRate = sampleRate;
|
|
13
|
+
this.channels = channels;
|
|
14
|
+
this.samplesPerChannel = samplesPerChannel;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static create(sampleRate: number, channels: number, samplesPerChannel: number): AudioFrame {
|
|
18
|
+
const data = new Uint16Array(channels * samplesPerChannel);
|
|
19
|
+
return new AudioFrame(data, sampleRate, channels, samplesPerChannel);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {
|
|
24
|
+
let info = owned.info;
|
|
25
|
+
let len = info.numChannels * info.samplesPerChannel * 2; // c_int16
|
|
26
|
+
let data = FfiClient.instance.copyBuffer(info.dataPtr, len);
|
|
27
|
+
new FfiHandle(owned.handle.id).dispose();
|
|
28
|
+
return new AudioFrame(
|
|
29
|
+
new Uint16Array(data.buffer),
|
|
30
|
+
info.sampleRate,
|
|
31
|
+
info.numChannels,
|
|
32
|
+
info.samplesPerChannel,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
protoInfo(): AudioFrameBufferInfo {
|
|
38
|
+
return new AudioFrameBufferInfo({
|
|
39
|
+
dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),
|
|
40
|
+
sampleRate: this.sampleRate,
|
|
41
|
+
numChannels: this.channels,
|
|
42
|
+
samplesPerChannel: this.samplesPerChannel,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import TypedEmitter from 'typed-emitter';
|
|
3
|
+
import { FfiHandle } from './native';
|
|
4
|
+
import { AudioFrame } from './audio_frame';
|
|
5
|
+
import {
|
|
6
|
+
AudioSourceInfo,
|
|
7
|
+
AudioSourceType,
|
|
8
|
+
CaptureAudioFrameCallback,
|
|
9
|
+
CaptureAudioFrameRequest,
|
|
10
|
+
CaptureAudioFrameResponse,
|
|
11
|
+
NewAudioSourceRequest,
|
|
12
|
+
NewAudioSourceResponse,
|
|
13
|
+
} from './proto/audio_frame_pb';
|
|
14
|
+
import { FfiClient, FfiRequest } from './ffi_client';
|
|
15
|
+
|
|
16
|
+
export class AudioSource {
|
|
17
|
+
/** @internal */
|
|
18
|
+
info: AudioSourceInfo;
|
|
19
|
+
/** @internal */
|
|
20
|
+
ffiHandle: FfiHandle;
|
|
21
|
+
|
|
22
|
+
sampleRate: number;
|
|
23
|
+
numChannels: number;
|
|
24
|
+
|
|
25
|
+
constructor(sampleRate: number, numChannels: number) {
|
|
26
|
+
this.sampleRate = sampleRate;
|
|
27
|
+
this.numChannels = numChannels;
|
|
28
|
+
|
|
29
|
+
let req = new NewAudioSourceRequest({
|
|
30
|
+
type: AudioSourceType.AUDIO_SOURCE_NATIVE,
|
|
31
|
+
sampleRate: sampleRate,
|
|
32
|
+
numChannels: numChannels,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
let res = FfiClient.instance.request<NewAudioSourceResponse>({
|
|
36
|
+
message: {
|
|
37
|
+
case: 'newAudioSource',
|
|
38
|
+
value: req,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this.info = res.source.info;
|
|
43
|
+
this.ffiHandle = new FfiHandle(res.source.handle.id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async captureFrame(frame: AudioFrame) {
|
|
47
|
+
let req = new CaptureAudioFrameRequest({
|
|
48
|
+
sourceHandle: this.ffiHandle.handle,
|
|
49
|
+
buffer: frame.protoInfo(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let res = FfiClient.instance.request<CaptureAudioFrameResponse>({
|
|
53
|
+
message: { case: 'captureAudioFrame', value: req },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
let cb = await FfiClient.instance.waitFor<CaptureAudioFrameCallback>((ev) => {
|
|
57
|
+
return ev.message.case == 'captureAudioFrame' && ev.message.value.asyncId == res.asyncId;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (cb.error) {
|
|
61
|
+
throw new Error(cb.error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AudioFrame } from './audio_frame';
|
|
2
|
+
import { FfiClient, FfiClientEvent, FfiEvent, FfiHandle, FfiRequest } from './ffi_client';
|
|
3
|
+
import {
|
|
4
|
+
AudioStreamInfo,
|
|
5
|
+
AudioStreamType,
|
|
6
|
+
NewAudioStreamRequest,
|
|
7
|
+
NewAudioStreamResponse,
|
|
8
|
+
} from './proto/audio_frame_pb';
|
|
9
|
+
import { Track } from './track';
|
|
10
|
+
import EventEmitter from 'events';
|
|
11
|
+
import TypedEmitter from 'typed-emitter';
|
|
12
|
+
|
|
13
|
+
export type AudioStreamCallbacks = {
|
|
14
|
+
frameReceived: (frame: AudioFrame) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export enum AudioStreamEvent {
|
|
18
|
+
FrameReceived = 'frameReceived',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class AudioStream extends (EventEmitter as new () => TypedEmitter<AudioStreamCallbacks>) {
|
|
22
|
+
/** @internal */
|
|
23
|
+
info: AudioStreamInfo;
|
|
24
|
+
/** @internal */
|
|
25
|
+
ffiHandle: FfiHandle;
|
|
26
|
+
|
|
27
|
+
track: Track;
|
|
28
|
+
|
|
29
|
+
constructor(track: Track) {
|
|
30
|
+
super();
|
|
31
|
+
this.track = track;
|
|
32
|
+
|
|
33
|
+
let req = new NewAudioStreamRequest({
|
|
34
|
+
type: AudioStreamType.AUDIO_STREAM_NATIVE,
|
|
35
|
+
trackHandle: track.ffi_handle.handle,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
let res = FfiClient.instance.request<NewAudioStreamResponse>({
|
|
39
|
+
message: {
|
|
40
|
+
case: 'newAudioStream',
|
|
41
|
+
value: req,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this.info = res.stream.info;
|
|
46
|
+
this.ffiHandle = new FfiHandle(res.stream.handle.id);
|
|
47
|
+
|
|
48
|
+
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private onEvent(ev: FfiEvent) {
|
|
52
|
+
if (
|
|
53
|
+
ev.message.case != 'audioStreamEvent' ||
|
|
54
|
+
ev.message.value.streamHandle != this.ffiHandle.handle
|
|
55
|
+
) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let streamEvent = ev.message.value.message;
|
|
60
|
+
switch (streamEvent.case) {
|
|
61
|
+
case 'frameReceived':
|
|
62
|
+
let frame = AudioFrame.fromOwnedInfo(streamEvent.value.frame);
|
|
63
|
+
this.emit(AudioStreamEvent.FrameReceived, frame);
|
|
64
|
+
break;
|
|
65
|
+
case 'eos':
|
|
66
|
+
FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
close() {
|
|
72
|
+
this.ffiHandle.dispose();
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/e2ee.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { FfiClient, FfiRequest } from './ffi_client';
|
|
2
|
+
import {
|
|
3
|
+
E2eeManagerGetFrameCryptorsResponse,
|
|
4
|
+
E2eeManagerSetEnabledRequest,
|
|
5
|
+
E2eeRequest,
|
|
6
|
+
E2eeResponse,
|
|
7
|
+
EncryptionType,
|
|
8
|
+
FrameCryptorSetEnabledRequest,
|
|
9
|
+
FrameCryptorSetKeyIndexRequest,
|
|
10
|
+
GetKeyRequest,
|
|
11
|
+
GetKeyResponse,
|
|
12
|
+
GetSharedKeyRequest,
|
|
13
|
+
GetSharedKeyResponse,
|
|
14
|
+
RatchetKeyRequest,
|
|
15
|
+
RatchetKeyResponse,
|
|
16
|
+
RatchetSharedKeyRequest,
|
|
17
|
+
RatchetSharedKeyResponse,
|
|
18
|
+
SetKeyRequest,
|
|
19
|
+
SetSharedKeyRequest,
|
|
20
|
+
} from './proto/e2ee_pb';
|
|
21
|
+
|
|
22
|
+
const DEFAULT_RATCHET_SALT = new TextEncoder().encode('LKFrameEncryptionKey');
|
|
23
|
+
const DEFAULT_RATCHET_WINDOW_SIZE = 16;
|
|
24
|
+
const DEFAULT_FAILURE_TOLERANCE = -1;
|
|
25
|
+
|
|
26
|
+
export interface KeyProviderOptions {
|
|
27
|
+
sharedKey?: Uint8Array;
|
|
28
|
+
ratchetSalt: Uint8Array;
|
|
29
|
+
ratchetWindowSize: number;
|
|
30
|
+
failureTolerance: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const defaultKeyProviderOptions: KeyProviderOptions = {
|
|
34
|
+
ratchetSalt: DEFAULT_RATCHET_SALT,
|
|
35
|
+
ratchetWindowSize: DEFAULT_RATCHET_WINDOW_SIZE,
|
|
36
|
+
failureTolerance: DEFAULT_FAILURE_TOLERANCE,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export interface E2EEOptions {
|
|
40
|
+
keyProviderOptions: KeyProviderOptions;
|
|
41
|
+
encryptionType: EncryptionType;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const defaultE2EEOptions: E2EEOptions = {
|
|
45
|
+
keyProviderOptions: defaultKeyProviderOptions,
|
|
46
|
+
encryptionType: EncryptionType.GCM,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class KeyProvider {
|
|
50
|
+
private roomHandle: bigint;
|
|
51
|
+
options: KeyProviderOptions;
|
|
52
|
+
|
|
53
|
+
/** internal */
|
|
54
|
+
constructor(roomHandle: bigint, opts: KeyProviderOptions) {
|
|
55
|
+
this.roomHandle = roomHandle;
|
|
56
|
+
this.options = opts;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setSharedKey(sharedKey: Uint8Array, keyIndex: number) {
|
|
60
|
+
let req = new E2eeRequest({
|
|
61
|
+
roomHandle: this.roomHandle,
|
|
62
|
+
message: {
|
|
63
|
+
case: 'setSharedKey',
|
|
64
|
+
value: new SetSharedKeyRequest({
|
|
65
|
+
keyIndex: keyIndex,
|
|
66
|
+
sharedKey: sharedKey,
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
FfiClient.instance.request({
|
|
72
|
+
message: {
|
|
73
|
+
case: 'e2ee',
|
|
74
|
+
value: req,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exportSharedKey(keyIndex: number): Uint8Array {
|
|
80
|
+
let req = new E2eeRequest({
|
|
81
|
+
roomHandle: this.roomHandle,
|
|
82
|
+
message: {
|
|
83
|
+
case: 'getSharedKey',
|
|
84
|
+
value: new GetSharedKeyRequest({
|
|
85
|
+
keyIndex: keyIndex,
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
let res = FfiClient.instance.request<E2eeResponse>({
|
|
91
|
+
message: {
|
|
92
|
+
case: 'e2ee',
|
|
93
|
+
value: req,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return (res.message.value as GetSharedKeyResponse).key;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
ratchetSharedKey(keyIndex: number): Uint8Array {
|
|
101
|
+
let req = new E2eeRequest({
|
|
102
|
+
roomHandle: this.roomHandle,
|
|
103
|
+
message: {
|
|
104
|
+
case: 'ratchetSharedKey',
|
|
105
|
+
value: new RatchetSharedKeyRequest({
|
|
106
|
+
keyIndex: keyIndex,
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
let res = FfiClient.instance.request<E2eeResponse>({
|
|
112
|
+
message: {
|
|
113
|
+
case: 'e2ee',
|
|
114
|
+
value: req,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return (res.message.value as RatchetSharedKeyResponse).newKey;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
setKey(participantIdentity: string, keyIndex: number) {
|
|
122
|
+
let req = new E2eeRequest({
|
|
123
|
+
roomHandle: this.roomHandle,
|
|
124
|
+
message: {
|
|
125
|
+
case: 'setKey',
|
|
126
|
+
value: new SetKeyRequest({
|
|
127
|
+
keyIndex: keyIndex,
|
|
128
|
+
participantIdentity: participantIdentity,
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
FfiClient.instance.request({
|
|
134
|
+
message: {
|
|
135
|
+
case: 'e2ee',
|
|
136
|
+
value: req,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
exportKey(participantIdentity: string, keyIndex: number): Uint8Array {
|
|
142
|
+
let req = new E2eeRequest({
|
|
143
|
+
roomHandle: this.roomHandle,
|
|
144
|
+
message: {
|
|
145
|
+
case: 'getKey',
|
|
146
|
+
value: new GetKeyRequest({
|
|
147
|
+
keyIndex: keyIndex,
|
|
148
|
+
participantIdentity: participantIdentity,
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
let res = FfiClient.instance.request<E2eeResponse>({
|
|
154
|
+
message: {
|
|
155
|
+
case: 'e2ee',
|
|
156
|
+
value: req,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return (res.message.value as GetKeyResponse).key;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
ratchetKey(participantIdentity: string, keyIndex: number): Uint8Array {
|
|
164
|
+
let req = new E2eeRequest({
|
|
165
|
+
roomHandle: this.roomHandle,
|
|
166
|
+
message: {
|
|
167
|
+
case: 'ratchetKey',
|
|
168
|
+
value: new RatchetKeyRequest({
|
|
169
|
+
keyIndex: keyIndex,
|
|
170
|
+
participantIdentity: participantIdentity,
|
|
171
|
+
}),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
let res = FfiClient.instance.request<E2eeResponse>({
|
|
176
|
+
message: {
|
|
177
|
+
case: 'e2ee',
|
|
178
|
+
value: req,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return (res.message.value as RatchetKeyResponse).newKey;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export class FrameCryptor {
|
|
187
|
+
private roomHandle = 0n;
|
|
188
|
+
participantIdentity: string;
|
|
189
|
+
keyIndex: number;
|
|
190
|
+
enabled: boolean;
|
|
191
|
+
|
|
192
|
+
constructor(roomHandle: bigint, participantIdentity: string, keyIndex: number, enabled: boolean) {
|
|
193
|
+
this.roomHandle = roomHandle;
|
|
194
|
+
this.participantIdentity = participantIdentity;
|
|
195
|
+
this.keyIndex = keyIndex;
|
|
196
|
+
this.enabled = enabled;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setEnabled(enabled: boolean) {
|
|
200
|
+
this.enabled = enabled;
|
|
201
|
+
let req = new E2eeRequest({
|
|
202
|
+
roomHandle: this.roomHandle,
|
|
203
|
+
message: {
|
|
204
|
+
case: 'cryptorSetEnabled',
|
|
205
|
+
value: new FrameCryptorSetEnabledRequest({
|
|
206
|
+
participantIdentity: this.participantIdentity,
|
|
207
|
+
enabled: this.enabled,
|
|
208
|
+
}),
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
FfiClient.instance.request({
|
|
213
|
+
message: {
|
|
214
|
+
case: 'e2ee',
|
|
215
|
+
value: req,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
setKeyIndex(keyIndex: number) {
|
|
221
|
+
this.keyIndex = keyIndex;
|
|
222
|
+
let req = new E2eeRequest({
|
|
223
|
+
roomHandle: this.roomHandle,
|
|
224
|
+
message: {
|
|
225
|
+
case: 'cryptorSetKeyIndex',
|
|
226
|
+
value: new FrameCryptorSetKeyIndexRequest({
|
|
227
|
+
participantIdentity: this.participantIdentity,
|
|
228
|
+
keyIndex: this.keyIndex,
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
FfiClient.instance.request({
|
|
234
|
+
message: {
|
|
235
|
+
case: 'e2ee',
|
|
236
|
+
value: req,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export class E2EEManager {
|
|
243
|
+
private roomHandle = 0n;
|
|
244
|
+
private options: E2EEOptions;
|
|
245
|
+
private keyProvider?: KeyProvider;
|
|
246
|
+
|
|
247
|
+
enabled: boolean;
|
|
248
|
+
|
|
249
|
+
constructor(roomHandle: bigint, opts?: E2EEOptions) {
|
|
250
|
+
this.roomHandle = roomHandle;
|
|
251
|
+
this.enabled = opts !== undefined;
|
|
252
|
+
|
|
253
|
+
if (opts !== undefined) {
|
|
254
|
+
const options = { ...defaultE2EEOptions, ...opts };
|
|
255
|
+
|
|
256
|
+
this.options = options;
|
|
257
|
+
this.keyProvider = new KeyProvider(roomHandle, options.keyProviderOptions);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
setEnabled(enabled: boolean) {
|
|
262
|
+
this.enabled = enabled;
|
|
263
|
+
let req = new E2eeRequest({
|
|
264
|
+
roomHandle: this.roomHandle,
|
|
265
|
+
message: {
|
|
266
|
+
case: 'managerSetEnabled',
|
|
267
|
+
value: new E2eeManagerSetEnabledRequest({
|
|
268
|
+
enabled: this.enabled,
|
|
269
|
+
}),
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
FfiClient.instance.request({
|
|
274
|
+
message: {
|
|
275
|
+
case: 'e2ee',
|
|
276
|
+
value: req,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
frameCryptors(): FrameCryptor[] {
|
|
282
|
+
let req = new E2eeRequest({
|
|
283
|
+
roomHandle: this.roomHandle,
|
|
284
|
+
message: {
|
|
285
|
+
case: 'managerGetFrameCryptors',
|
|
286
|
+
value: {},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
let res = FfiClient.instance.request<E2eeResponse>({
|
|
291
|
+
message: {
|
|
292
|
+
case: 'e2ee',
|
|
293
|
+
value: req,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
let frameCryptors = (
|
|
298
|
+
res.message.value as E2eeManagerGetFrameCryptorsResponse
|
|
299
|
+
).frameCryptors.map(
|
|
300
|
+
(cryptor) =>
|
|
301
|
+
new FrameCryptor(
|
|
302
|
+
this.roomHandle,
|
|
303
|
+
cryptor.participantIdentity,
|
|
304
|
+
cryptor.keyIndex,
|
|
305
|
+
cryptor.enabled,
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
return frameCryptors;
|
|
310
|
+
}
|
|
311
|
+
}
|