@simplito/privmx-webendpoint 2.6.5 → 2.7.1
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/CONTRIBUTING.md +86 -0
- package/README.md +97 -7
- package/assets/driver-web-context.js +1 -1
- package/assets/e2ee-worker.js +1 -1
- package/assets/endpoint-wasm-module.js +2 -2
- package/assets/endpoint-wasm-module.wasm +0 -0
- package/assets/rms-processor.js +1 -0
- package/build-manifest.sh +6 -0
- package/{FinalizationHelper.js → dist/FinalizationHelper.js} +1 -1
- package/dist/ServerTypes.d.ts +7 -0
- package/{Types.d.ts → dist/Types.d.ts} +97 -10
- package/{Types.js → dist/Types.js} +17 -32
- package/{api → dist/api}/Api.d.ts +2 -0
- package/{api → dist/api}/Api.js +18 -1
- package/{api → dist/api}/ConnectionNative.js +1 -1
- package/{api → dist/api}/CryptoApiNative.js +1 -2
- package/{api → dist/api}/InboxApiNative.d.ts +21 -2
- package/{api → dist/api}/KvdbApiNative.d.ts +19 -2
- package/dist/api/NativeError.d.ts +13 -0
- package/dist/api/NativeError.js +20 -0
- package/{api → dist/api}/StoreApiNative.d.ts +19 -2
- package/dist/api/StreamApiNative.d.ts +72 -0
- package/dist/api/StreamApiNative.js +142 -0
- package/{api → dist/api}/ThreadApiNative.d.ts +19 -2
- package/dist/assets/e2ee-worker.js +1 -0
- package/dist/bundle/privmx-endpoint-web.js +2 -0
- package/dist/bundle/privmx-endpoint-web.js.LICENSE.txt +30 -0
- package/dist/bundle/rms-processor.js +1 -0
- package/{extra → dist/extra}/PrivmxClient.d.ts +9 -9
- package/{extra → dist/extra}/PrivmxClient.js +12 -12
- package/{extra → dist/extra}/PublicConnection.d.ts +2 -2
- package/{extra → dist/extra}/PublicConnection.js +2 -2
- package/{extra → dist/extra}/__tests__/connectionEventManager.test.js +1 -3
- package/{extra → dist/extra}/__tests__/customEventManager.test.js +1 -3
- package/{extra → dist/extra}/__tests__/userEventManager.test.js +2 -6
- package/{extra → dist/extra}/__tests__/utils.test.js +18 -18
- package/{extra → dist/extra}/events.js +32 -12
- package/{extra → dist/extra}/files.d.ts +5 -5
- package/{extra → dist/extra}/files.js +11 -11
- package/{extra → dist/extra}/generics.d.ts +1 -1
- package/{extra → dist/extra}/inbox.d.ts +1 -1
- package/{extra → dist/extra}/inbox.js +2 -2
- package/{extra → dist/extra}/index.d.ts +7 -7
- package/{extra → dist/extra}/managers.js +1 -1
- package/{extra → dist/extra}/utils.js +9 -9
- package/{index.d.ts → dist/index.d.ts} +3 -2
- package/{index.js → dist/index.js} +4 -1
- package/{service → dist/service}/Connection.js +13 -6
- package/{service → dist/service}/CryptoApi.js +2 -8
- package/{service → dist/service}/EndpointFactory.d.ts +11 -0
- package/{service → dist/service}/EndpointFactory.js +45 -10
- package/{service → dist/service}/EventApi.js +9 -5
- package/dist/service/EventDispatcher.d.ts +15 -0
- package/dist/service/EventDispatcher.js +25 -0
- package/{service → dist/service}/EventQueue.d.ts +4 -4
- package/{service → dist/service}/EventQueue.js +5 -9
- package/{service → dist/service}/ExtKey.d.ts +10 -10
- package/{service → dist/service}/ExtKey.js +10 -10
- package/{service → dist/service}/InboxApi.js +7 -11
- package/{service → dist/service}/KvdbApi.js +12 -7
- package/{service → dist/service}/StoreApi.js +10 -15
- package/dist/service/StreamApi.d.ts +237 -0
- package/dist/service/StreamApi.js +442 -0
- package/{service → dist/service}/ThreadApi.js +6 -7
- package/{service → dist/service}/UserVerifierInterface.d.ts +2 -2
- package/dist/service/UserVerifierInterface.js +2 -0
- package/dist/service/WebRtcInterface.d.ts +58 -0
- package/dist/service/WebRtcInterface.js +8 -0
- package/{service → dist/service}/index.d.ts +3 -2
- package/{service → dist/service}/index.js +5 -3
- package/dist/webStreams/CryptoUtils.d.ts +24 -0
- package/dist/webStreams/CryptoUtils.js +58 -0
- package/dist/webStreams/KeyStore.d.ts +9 -0
- package/dist/webStreams/KeyStore.js +29 -0
- package/dist/webStreams/Logger.d.ts +7 -0
- package/dist/webStreams/Logger.js +25 -0
- package/dist/webStreams/PeerConnectionsManager.d.ts +20 -0
- package/dist/webStreams/PeerConnectionsManager.js +92 -0
- package/dist/webStreams/Queue.d.ts +19 -0
- package/dist/webStreams/Queue.js +70 -0
- package/dist/webStreams/Utils.d.ts +20 -0
- package/dist/webStreams/Utils.js +211 -0
- package/dist/webStreams/WebRtcClient.d.ts +85 -0
- package/dist/webStreams/WebRtcClient.js +437 -0
- package/dist/webStreams/WebRtcClientTypes.d.ts +64 -0
- package/dist/webStreams/WebRtcClientTypes.js +2 -0
- package/dist/webStreams/WebRtcConfig.d.ts +20 -0
- package/dist/webStreams/WebRtcConfig.js +53 -0
- package/dist/webStreams/WebRtcInterfaceImpl.d.ts +28 -0
- package/dist/webStreams/WebRtcInterfaceImpl.js +85 -0
- package/dist/webStreams/WebWorkerHelper copy.d.ts +0 -0
- package/dist/webStreams/WebWorkerHelper copy.js +17 -0
- package/dist/webStreams/WebWorkerHelper.d.ts +18 -0
- package/dist/webStreams/WebWorkerHelper.js +69 -0
- package/dist/webStreams/audio/ActiveSpeakerDetector.d.ts +38 -0
- package/dist/webStreams/audio/ActiveSpeakerDetector.js +64 -0
- package/dist/webStreams/audio/LocalAudioLevelMeter.d.ts +12 -0
- package/dist/webStreams/audio/LocalAudioLevelMeter.js +101 -0
- package/dist/webStreams/types/ApiTypes.d.ts +74 -0
- package/dist/webStreams/types/ApiTypes.js +2 -0
- package/dist/webStreams/types/BaseServerTypes.d.ts +10 -0
- package/dist/webStreams/types/BaseServerTypes.js +2 -0
- package/dist/webStreams/types/MediaServerWebSocketApiTypes.d.ts +255 -0
- package/dist/webStreams/types/MediaServerWebSocketApiTypes.js +2 -0
- package/dist/webStreams/types/SignalingReceiverTypes.d.ts +13 -0
- package/dist/webStreams/types/SignalingReceiverTypes.js +2 -0
- package/dist/webStreams/types/SignalingSenderTypes.d.ts +24 -0
- package/dist/webStreams/types/SignalingSenderTypes.js +2 -0
- package/dist/webStreams/types/StreamsApiTypes.d.ts +144 -0
- package/dist/webStreams/types/StreamsApiTypes.js +2 -0
- package/dist/webStreams/worker/WorkerEvents.d.ts +11 -0
- package/dist/webStreams/worker/WorkerEvents.js +2 -0
- package/dist/webStreams/worker/worker.d.ts +13 -0
- package/dist/webStreams/worker/worker.js +202 -0
- package/package.json +46 -15
- package/assets/endpoint-wasm-module.worker.js +0 -1
- package/assets/privmx-endpoint-web.js +0 -2
- package/bundle/privmx-endpoint-web.js +0 -2
- package/bundle/privmx-endpoint-web.js.LICENSE.txt +0 -10
- /package/{FinalizationHelper.d.ts → dist/FinalizationHelper.d.ts} +0 -0
- /package/{extra/generics.js → dist/ServerTypes.js} +0 -0
- /package/{api → dist/api}/ApiStatic.d.ts +0 -0
- /package/{api → dist/api}/ApiStatic.js +0 -0
- /package/{api → dist/api}/BaseNative.d.ts +0 -0
- /package/{api → dist/api}/BaseNative.js +0 -0
- /package/{api → dist/api}/ConnectionNative.d.ts +0 -0
- /package/{api → dist/api}/CryptoApiNative.d.ts +0 -0
- /package/{api → dist/api}/EventApiNative.d.ts +0 -0
- /package/{api → dist/api}/EventApiNative.js +0 -0
- /package/{api → dist/api}/EventQueueNative.d.ts +0 -0
- /package/{api → dist/api}/EventQueueNative.js +0 -0
- /package/{api → dist/api}/ExtKeyNative.d.ts +0 -0
- /package/{api → dist/api}/ExtKeyNative.js +0 -0
- /package/{api → dist/api}/IdGenerator.d.ts +0 -0
- /package/{api → dist/api}/IdGenerator.js +0 -0
- /package/{api → dist/api}/InboxApiNative.js +0 -0
- /package/{api → dist/api}/KvdbApiNative.js +0 -0
- /package/{api → dist/api}/StoreApiNative.js +0 -0
- /package/{api → dist/api}/ThreadApiNative.js +0 -0
- /package/{bundle.d.ts → dist/bundle.d.ts} +0 -0
- /package/{bundle.js → dist/bundle.js} +0 -0
- /package/{extra → dist/extra}/__mocks__/constants.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/constants.js +0 -0
- /package/{extra → dist/extra}/__mocks__/mockContainerSubscriber.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/mockContainerSubscriber.js +0 -0
- /package/{extra → dist/extra}/__mocks__/mockEventQueue.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/mockEventQueue.js +0 -0
- /package/{extra → dist/extra}/__mocks__/utils.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/utils.js +0 -0
- /package/{extra → dist/extra}/__tests__/connectionEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/customEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/eventsManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/eventsManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/inboxEventManager.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/inboxEventManager.js +0 -0
- /package/{extra → dist/extra}/__tests__/storeEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/storeEventManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/threadEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/threadEventManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/userEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/utils.test.d.ts +0 -0
- /package/{extra → dist/extra}/events.d.ts +0 -0
- /package/{service/UserVerifierInterface.js → dist/extra/generics.js} +0 -0
- /package/{extra → dist/extra}/index.js +0 -0
- /package/{extra → dist/extra}/managers.d.ts +0 -0
- /package/{extra → dist/extra}/subscriptions.d.ts +0 -0
- /package/{extra → dist/extra}/subscriptions.js +0 -0
- /package/{extra → dist/extra}/utils.d.ts +0 -0
- /package/{service → dist/service}/BaseApi.d.ts +0 -0
- /package/{service → dist/service}/BaseApi.js +0 -0
- /package/{service → dist/service}/Connection.d.ts +0 -0
- /package/{service → dist/service}/CryptoApi.d.ts +0 -0
- /package/{service → dist/service}/EventApi.d.ts +0 -0
- /package/{service → dist/service}/InboxApi.d.ts +0 -0
- /package/{service → dist/service}/KvdbApi.d.ts +0 -0
- /package/{service → dist/service}/StoreApi.d.ts +0 -0
- /package/{service → dist/service}/ThreadApi.d.ts +0 -0
|
@@ -123,12 +123,7 @@ class ThreadApi extends BaseApi_1.BaseApi {
|
|
|
123
123
|
* @returns {string} ID of the new message
|
|
124
124
|
*/
|
|
125
125
|
async sendMessage(threadId, publicMeta, privateMeta, data) {
|
|
126
|
-
return this.native.sendMessage(this.servicePtr, [
|
|
127
|
-
threadId,
|
|
128
|
-
publicMeta,
|
|
129
|
-
privateMeta,
|
|
130
|
-
data,
|
|
131
|
-
]);
|
|
126
|
+
return this.native.sendMessage(this.servicePtr, [threadId, publicMeta, privateMeta, data]);
|
|
132
127
|
}
|
|
133
128
|
/**
|
|
134
129
|
* Deletes a message by given message ID.
|
|
@@ -205,7 +200,11 @@ class ThreadApi extends BaseApi_1.BaseApi {
|
|
|
205
200
|
* @param {string} selectorId ID of the selector
|
|
206
201
|
*/
|
|
207
202
|
async buildSubscriptionQuery(eventType, selectorType, selectorId) {
|
|
208
|
-
return this.native.buildSubscriptionQuery(this.servicePtr, [
|
|
203
|
+
return this.native.buildSubscriptionQuery(this.servicePtr, [
|
|
204
|
+
eventType,
|
|
205
|
+
selectorType,
|
|
206
|
+
selectorId,
|
|
207
|
+
]);
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
exports.ThreadApi = ThreadApi;
|
|
@@ -5,7 +5,7 @@ import { VerificationRequest } from "../Types";
|
|
|
5
5
|
*
|
|
6
6
|
* @type {UserVerifierInterface}
|
|
7
7
|
*
|
|
8
|
-
*/
|
|
8
|
+
*/
|
|
9
9
|
export interface UserVerifierInterface {
|
|
10
10
|
/**
|
|
11
11
|
* Verifies whether the specified users are valid.
|
|
@@ -13,6 +13,6 @@ export interface UserVerifierInterface {
|
|
|
13
13
|
*
|
|
14
14
|
* @param request List of user data to verification
|
|
15
15
|
* @returns List of verification results whose items correspond to the items in the input list
|
|
16
|
-
|
|
16
|
+
*/
|
|
17
17
|
verify(request: VerificationRequest[]): Promise<boolean[]>;
|
|
18
18
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Key } from "../Types";
|
|
2
|
+
import { ConnectionType } from "../webStreams/PeerConnectionsManager";
|
|
3
|
+
import { StreamRoomId } from "../webStreams/types/ApiTypes";
|
|
4
|
+
export declare class UpdateKeysModel {
|
|
5
|
+
streamRoomId: StreamRoomId;
|
|
6
|
+
keys: Key[];
|
|
7
|
+
}
|
|
8
|
+
export interface Jsep {
|
|
9
|
+
sdp: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SdpWithRoomModel extends Jsep {
|
|
13
|
+
roomId: StreamRoomId;
|
|
14
|
+
}
|
|
15
|
+
export interface RoomModel {
|
|
16
|
+
roomId: StreamRoomId;
|
|
17
|
+
}
|
|
18
|
+
export type CreateAnswerAndSetDescriptionsModel = SdpWithRoomModel;
|
|
19
|
+
export type SetAnswerAndSetRemoteDescriptionModel = SdpWithRoomModel;
|
|
20
|
+
export interface StreamsUpdatedData {
|
|
21
|
+
videoroom: "updated";
|
|
22
|
+
room: StreamRoomId;
|
|
23
|
+
streams: UpdatedStreamData[];
|
|
24
|
+
jsep?: Jsep;
|
|
25
|
+
}
|
|
26
|
+
export interface UpdatedStreamData {
|
|
27
|
+
type: "audio" | "video" | "data";
|
|
28
|
+
streamId: number;
|
|
29
|
+
streamMid: number;
|
|
30
|
+
stream_display: string;
|
|
31
|
+
mindex: number;
|
|
32
|
+
mid: string;
|
|
33
|
+
send: boolean;
|
|
34
|
+
ready: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface CurrentPublishersData {
|
|
37
|
+
room: StreamRoomId;
|
|
38
|
+
publishers: NewPublisherEvent[];
|
|
39
|
+
}
|
|
40
|
+
export interface NewPublisherEvent {
|
|
41
|
+
id: number;
|
|
42
|
+
video_codec: string;
|
|
43
|
+
streams: VideoRoomStreamTrack[];
|
|
44
|
+
}
|
|
45
|
+
export interface VideoRoomStreamTrack {
|
|
46
|
+
type: string;
|
|
47
|
+
codec: string;
|
|
48
|
+
mid: string;
|
|
49
|
+
mindex: number;
|
|
50
|
+
}
|
|
51
|
+
export interface WebRtcInterface {
|
|
52
|
+
createOfferAndSetLocalDescription(model: RoomModel): Promise<string>;
|
|
53
|
+
createAnswerAndSetDescriptions(model: CreateAnswerAndSetDescriptionsModel): Promise<string>;
|
|
54
|
+
setAnswerAndSetRemoteDescription(model: SetAnswerAndSetRemoteDescriptionModel): Promise<void>;
|
|
55
|
+
updateSessionId(roomId: StreamRoomId, sessionId: number, connectionType: ConnectionType): Promise<void>;
|
|
56
|
+
close(roomId: StreamRoomId): Promise<void>;
|
|
57
|
+
updateKeys(model: UpdateKeysModel): Promise<void>;
|
|
58
|
+
}
|
|
@@ -3,10 +3,11 @@ import { ThreadApi } from "./ThreadApi";
|
|
|
3
3
|
import { StoreApi } from "./StoreApi";
|
|
4
4
|
import { InboxApi } from "./InboxApi";
|
|
5
5
|
import { KvdbApi } from "./KvdbApi";
|
|
6
|
+
import { EventApi } from "./EventApi";
|
|
6
7
|
import { CryptoApi } from "./CryptoApi";
|
|
8
|
+
import { StreamApi } from "./StreamApi";
|
|
7
9
|
import { Connection } from "./Connection";
|
|
8
10
|
import { EventQueue } from "./EventQueue";
|
|
9
11
|
import { BaseApi } from "./BaseApi";
|
|
10
12
|
import { ExtKey } from "./ExtKey";
|
|
11
|
-
|
|
12
|
-
export { EndpointFactory, ThreadApi, StoreApi, InboxApi, KvdbApi, CryptoApi, Connection, EventQueue, BaseApi, ExtKey, EventApi };
|
|
13
|
+
export { EndpointFactory, ThreadApi, StoreApi, InboxApi, KvdbApi, CryptoApi, StreamApi, Connection, EventQueue, BaseApi, ExtKey, EventApi, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventApi = exports.ExtKey = exports.BaseApi = exports.EventQueue = exports.Connection = exports.CryptoApi = exports.KvdbApi = exports.InboxApi = exports.StoreApi = exports.ThreadApi = exports.EndpointFactory = void 0;
|
|
3
|
+
exports.EventApi = exports.ExtKey = exports.BaseApi = exports.EventQueue = exports.Connection = exports.StreamApi = exports.CryptoApi = exports.KvdbApi = exports.InboxApi = exports.StoreApi = exports.ThreadApi = exports.EndpointFactory = void 0;
|
|
4
4
|
const EndpointFactory_1 = require("./EndpointFactory");
|
|
5
5
|
Object.defineProperty(exports, "EndpointFactory", { enumerable: true, get: function () { return EndpointFactory_1.EndpointFactory; } });
|
|
6
6
|
const ThreadApi_1 = require("./ThreadApi");
|
|
@@ -11,8 +11,12 @@ const InboxApi_1 = require("./InboxApi");
|
|
|
11
11
|
Object.defineProperty(exports, "InboxApi", { enumerable: true, get: function () { return InboxApi_1.InboxApi; } });
|
|
12
12
|
const KvdbApi_1 = require("./KvdbApi");
|
|
13
13
|
Object.defineProperty(exports, "KvdbApi", { enumerable: true, get: function () { return KvdbApi_1.KvdbApi; } });
|
|
14
|
+
const EventApi_1 = require("./EventApi");
|
|
15
|
+
Object.defineProperty(exports, "EventApi", { enumerable: true, get: function () { return EventApi_1.EventApi; } });
|
|
14
16
|
const CryptoApi_1 = require("./CryptoApi");
|
|
15
17
|
Object.defineProperty(exports, "CryptoApi", { enumerable: true, get: function () { return CryptoApi_1.CryptoApi; } });
|
|
18
|
+
const StreamApi_1 = require("./StreamApi");
|
|
19
|
+
Object.defineProperty(exports, "StreamApi", { enumerable: true, get: function () { return StreamApi_1.StreamApi; } });
|
|
16
20
|
const Connection_1 = require("./Connection");
|
|
17
21
|
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return Connection_1.Connection; } });
|
|
18
22
|
const EventQueue_1 = require("./EventQueue");
|
|
@@ -21,5 +25,3 @@ const BaseApi_1 = require("./BaseApi");
|
|
|
21
25
|
Object.defineProperty(exports, "BaseApi", { enumerable: true, get: function () { return BaseApi_1.BaseApi; } });
|
|
22
26
|
const ExtKey_1 = require("./ExtKey");
|
|
23
27
|
Object.defineProperty(exports, "ExtKey", { enumerable: true, get: function () { return ExtKey_1.ExtKey; } });
|
|
24
|
-
const EventApi_1 = require("./EventApi");
|
|
25
|
-
Object.defineProperty(exports, "EventApi", { enumerable: true, get: function () { return EventApi_1.EventApi; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type BufferLike = ArrayBuffer | Uint8Array;
|
|
2
|
+
interface EncryptionResult {
|
|
3
|
+
success: true;
|
|
4
|
+
data: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
interface EncryptionError {
|
|
7
|
+
success: false;
|
|
8
|
+
error: string;
|
|
9
|
+
}
|
|
10
|
+
type EncryptionResponse = EncryptionResult | EncryptionError;
|
|
11
|
+
interface DecryptionResult {
|
|
12
|
+
success: true;
|
|
13
|
+
data: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
interface DecryptionError {
|
|
16
|
+
success: false;
|
|
17
|
+
error: string;
|
|
18
|
+
}
|
|
19
|
+
type DecryptionResponse = DecryptionResult | DecryptionError;
|
|
20
|
+
declare function encryptWithAES256GCM(key: BufferLike, iv: BufferLike, data: BufferLike, header: BufferLike): Promise<EncryptionResponse>;
|
|
21
|
+
declare function decryptWithAES256GCM(key: BufferLike, iv: BufferLike, encryptedData: BufferLike, header: BufferLike): Promise<DecryptionResponse>;
|
|
22
|
+
declare function isEncryptionSuccess(result: EncryptionResponse): result is EncryptionResult;
|
|
23
|
+
declare function isDecryptionSuccess(result: DecryptionResponse): result is DecryptionResult;
|
|
24
|
+
export { encryptWithAES256GCM, decryptWithAES256GCM, isEncryptionSuccess, isDecryptionSuccess, type EncryptionResponse, type DecryptionResponse, type BufferLike, };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encryptWithAES256GCM = encryptWithAES256GCM;
|
|
4
|
+
exports.decryptWithAES256GCM = decryptWithAES256GCM;
|
|
5
|
+
exports.isEncryptionSuccess = isEncryptionSuccess;
|
|
6
|
+
exports.isDecryptionSuccess = isDecryptionSuccess;
|
|
7
|
+
async function encryptWithAES256GCM(key, iv, data, header) {
|
|
8
|
+
try {
|
|
9
|
+
// Import the key for AES-GCM
|
|
10
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
11
|
+
// Encrypt the data
|
|
12
|
+
const encrypted = await crypto.subtle.encrypt({
|
|
13
|
+
name: "AES-GCM",
|
|
14
|
+
iv: iv,
|
|
15
|
+
additionalData: header,
|
|
16
|
+
tagLength: 128, // 16 bytes * 8 = 128 bits (TAG_LEN equivalent)
|
|
17
|
+
}, cryptoKey, data);
|
|
18
|
+
// The encrypted result contains both ciphertext and authentication tag
|
|
19
|
+
return {
|
|
20
|
+
success: true,
|
|
21
|
+
data: new Uint8Array(encrypted),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: "EncryptionFailed",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function decryptWithAES256GCM(key, iv, encryptedData, header) {
|
|
32
|
+
try {
|
|
33
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
34
|
+
const decrypted = await crypto.subtle.decrypt({
|
|
35
|
+
name: "AES-GCM",
|
|
36
|
+
iv: iv,
|
|
37
|
+
additionalData: header,
|
|
38
|
+
tagLength: 128,
|
|
39
|
+
}, cryptoKey, encryptedData);
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
data: new Uint8Array(decrypted),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: "DecryptionFailed",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Type guard functions for better type safety
|
|
53
|
+
function isEncryptionSuccess(result) {
|
|
54
|
+
return result.success;
|
|
55
|
+
}
|
|
56
|
+
function isDecryptionSuccess(result) {
|
|
57
|
+
return result.success;
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyStore = void 0;
|
|
4
|
+
class KeyStore {
|
|
5
|
+
_keys = new Map();
|
|
6
|
+
_encryptionKeyId = undefined;
|
|
7
|
+
setKeys(keys) {
|
|
8
|
+
this._keys.clear();
|
|
9
|
+
for (const k of keys) {
|
|
10
|
+
this._keys.set(k.keyId, k);
|
|
11
|
+
if (k.type === 0) {
|
|
12
|
+
this._encryptionKeyId = k.keyId;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
getKey(keyId) {
|
|
17
|
+
return this._keys.get(keyId);
|
|
18
|
+
}
|
|
19
|
+
hasKey(keyId) {
|
|
20
|
+
return this._keys.has(keyId);
|
|
21
|
+
}
|
|
22
|
+
getEncriptionKey() {
|
|
23
|
+
if (!this._encryptionKeyId) {
|
|
24
|
+
throw new Error("No encryption key set.");
|
|
25
|
+
}
|
|
26
|
+
return this._keys.get(this._encryptionKeyId);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.KeyStore = KeyStore;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
static instance;
|
|
6
|
+
static logLevel = "important-only";
|
|
7
|
+
static get() {
|
|
8
|
+
if (!this.instance) {
|
|
9
|
+
this.instance = new Logger();
|
|
10
|
+
}
|
|
11
|
+
return this.instance;
|
|
12
|
+
}
|
|
13
|
+
log(level, ...args) {
|
|
14
|
+
if (Logger.logLevel === "debug") {
|
|
15
|
+
console.log(...args);
|
|
16
|
+
}
|
|
17
|
+
else if (level === "info" && Logger.logLevel === "info") {
|
|
18
|
+
console.log(...args);
|
|
19
|
+
}
|
|
20
|
+
else if (level === "important-only" && Logger.logLevel === "important-only") {
|
|
21
|
+
console.log(...args);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StreamRoomId } from "./types/ApiTypes";
|
|
2
|
+
import { SessionId } from "./WebRtcClientTypes";
|
|
3
|
+
export type ConnectionType = "publisher" | "subscriber";
|
|
4
|
+
export interface JanusConnection {
|
|
5
|
+
pc: RTCPeerConnection;
|
|
6
|
+
sessionId: SessionId;
|
|
7
|
+
hasSubscriptions: boolean;
|
|
8
|
+
candidateQueue: RTCIceCandidate[];
|
|
9
|
+
}
|
|
10
|
+
export declare class PeerConnectionManager {
|
|
11
|
+
private createPeerConnection;
|
|
12
|
+
private onTrickle;
|
|
13
|
+
private connections;
|
|
14
|
+
constructor(createPeerConnection: (room: StreamRoomId) => RTCPeerConnection, onTrickle: (sessionId: SessionId, candidate: RTCIceCandidate) => void);
|
|
15
|
+
initialize(room: StreamRoomId, connectionType: ConnectionType, sessionId?: SessionId): void;
|
|
16
|
+
updateSessionForConnection(room: StreamRoomId, connectionType: ConnectionType, session: SessionId): void;
|
|
17
|
+
hasConnection(room: StreamRoomId, connectionType: ConnectionType): boolean;
|
|
18
|
+
getConnectionWithSession(room: StreamRoomId, connectionType: ConnectionType): JanusConnection;
|
|
19
|
+
closePeerConnectionBySessionIfExists(room: StreamRoomId, connectionType: ConnectionType): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PeerConnectionManager = void 0;
|
|
4
|
+
class PeerConnectionManager {
|
|
5
|
+
createPeerConnection;
|
|
6
|
+
onTrickle;
|
|
7
|
+
connections = {};
|
|
8
|
+
constructor(createPeerConnection, onTrickle) {
|
|
9
|
+
this.createPeerConnection = createPeerConnection;
|
|
10
|
+
this.onTrickle = onTrickle;
|
|
11
|
+
}
|
|
12
|
+
initialize(room, connectionType, sessionId = -1) {
|
|
13
|
+
// Prevent re-initialization if it already exists
|
|
14
|
+
if (room in this.connections &&
|
|
15
|
+
connectionType in this.connections[room] &&
|
|
16
|
+
this.connections[room][connectionType]?.pc) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!(room in this.connections)) {
|
|
20
|
+
this.connections[room] = {};
|
|
21
|
+
}
|
|
22
|
+
// Create the RTCPeerConnection
|
|
23
|
+
const pc = this.createPeerConnection(room);
|
|
24
|
+
// Prepare the connection object immediately so we can access the queue in the listener
|
|
25
|
+
const newConnection = {
|
|
26
|
+
sessionId: sessionId,
|
|
27
|
+
hasSubscriptions: false,
|
|
28
|
+
pc,
|
|
29
|
+
candidateQueue: [],
|
|
30
|
+
};
|
|
31
|
+
// Assign immediately so the listener has access to the reference
|
|
32
|
+
this.connections[room][connectionType] = newConnection;
|
|
33
|
+
pc.addEventListener("icecandidate", (event) => {
|
|
34
|
+
if (!event.candidate) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const conn = this.connections[room][connectionType];
|
|
38
|
+
if (!conn)
|
|
39
|
+
return;
|
|
40
|
+
const currentSessionId = conn.sessionId;
|
|
41
|
+
if (currentSessionId && currentSessionId > -1) {
|
|
42
|
+
try {
|
|
43
|
+
this.onTrickle(currentSessionId, event.candidate);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.warn("Failed to trickle candidate", err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
conn.candidateQueue.push(event.candidate);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
updateSessionForConnection(room, connectionType, session) {
|
|
55
|
+
if (!(room in this.connections) || !(connectionType in this.connections[room])) {
|
|
56
|
+
this.initialize(room, connectionType);
|
|
57
|
+
}
|
|
58
|
+
const conn = this.connections[room][connectionType];
|
|
59
|
+
conn.sessionId = session;
|
|
60
|
+
if (conn.candidateQueue.length > 0) {
|
|
61
|
+
conn.candidateQueue.forEach((candidate) => {
|
|
62
|
+
try {
|
|
63
|
+
this.onTrickle(session, candidate);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.warn("Failed to trickle buffered candidate", err);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
conn.candidateQueue = [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
hasConnection(room, connectionType) {
|
|
73
|
+
return !!(this.connections[room] && this.connections[room][connectionType]);
|
|
74
|
+
}
|
|
75
|
+
getConnectionWithSession(room, connectionType) {
|
|
76
|
+
if (!this.hasConnection(room, connectionType)) {
|
|
77
|
+
this.initialize(room, connectionType);
|
|
78
|
+
}
|
|
79
|
+
return this.connections[room][connectionType];
|
|
80
|
+
}
|
|
81
|
+
closePeerConnectionBySessionIfExists(room, connectionType) {
|
|
82
|
+
if (this.hasConnection(room, connectionType)) {
|
|
83
|
+
const conn = this.connections[room][connectionType];
|
|
84
|
+
if (conn?.pc) {
|
|
85
|
+
conn.pc.close();
|
|
86
|
+
}
|
|
87
|
+
// Optional: Clean up the reference to allow garbage collection
|
|
88
|
+
delete this.connections[room][connectionType];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.PeerConnectionManager = PeerConnectionManager;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface QueueTask<T> {
|
|
2
|
+
func(item: T): Promise<void>;
|
|
3
|
+
}
|
|
4
|
+
export declare class Queue<T> implements Iterable<T> {
|
|
5
|
+
private items;
|
|
6
|
+
private func;
|
|
7
|
+
private processing;
|
|
8
|
+
enqueue(item: T): void;
|
|
9
|
+
dequeue(): T | undefined;
|
|
10
|
+
peek(): T | undefined;
|
|
11
|
+
get size(): number;
|
|
12
|
+
isEmpty(): boolean;
|
|
13
|
+
clear(): void;
|
|
14
|
+
toArray(): T[];
|
|
15
|
+
assignProcessorFunc(func: (item: T) => Promise<void>): void;
|
|
16
|
+
processAll(): Promise<void>;
|
|
17
|
+
awaiter(): Promise<void>;
|
|
18
|
+
[Symbol.iterator](): Iterator<T>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
class Queue {
|
|
5
|
+
items = [];
|
|
6
|
+
func;
|
|
7
|
+
processing = false;
|
|
8
|
+
enqueue(item) {
|
|
9
|
+
this.items.push(item);
|
|
10
|
+
}
|
|
11
|
+
dequeue() {
|
|
12
|
+
return this.items.shift();
|
|
13
|
+
}
|
|
14
|
+
peek() {
|
|
15
|
+
return this.items[0];
|
|
16
|
+
}
|
|
17
|
+
get size() {
|
|
18
|
+
return this.items.length;
|
|
19
|
+
}
|
|
20
|
+
isEmpty() {
|
|
21
|
+
return this.items.length === 0;
|
|
22
|
+
}
|
|
23
|
+
clear() {
|
|
24
|
+
this.items.length = 0;
|
|
25
|
+
}
|
|
26
|
+
toArray() {
|
|
27
|
+
return this.items.slice();
|
|
28
|
+
}
|
|
29
|
+
assignProcessorFunc(func) {
|
|
30
|
+
this.func = func;
|
|
31
|
+
}
|
|
32
|
+
async processAll() {
|
|
33
|
+
if (this.processing) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!this.func) {
|
|
37
|
+
throw new Error("No task processor function assigned");
|
|
38
|
+
}
|
|
39
|
+
this.processing = true;
|
|
40
|
+
while (this.items.length > 0) {
|
|
41
|
+
const item = this.items.shift();
|
|
42
|
+
if (!item)
|
|
43
|
+
continue;
|
|
44
|
+
const randId = Math.random();
|
|
45
|
+
try {
|
|
46
|
+
await this.func(item);
|
|
47
|
+
await this.awaiter();
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.error("Error while processing queue item", randId, err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
this.processing = false;
|
|
54
|
+
}
|
|
55
|
+
async awaiter() {
|
|
56
|
+
return new Promise((resolve) => setTimeout(() => resolve(), 5000));
|
|
57
|
+
}
|
|
58
|
+
[Symbol.iterator]() {
|
|
59
|
+
let idx = 0;
|
|
60
|
+
const arr = this.items;
|
|
61
|
+
return {
|
|
62
|
+
next() {
|
|
63
|
+
if (idx < arr.length)
|
|
64
|
+
return { value: arr[idx++], done: false };
|
|
65
|
+
return { value: undefined, done: true };
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Queue = Queue;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class Utils {
|
|
2
|
+
static generateNumericId(): number;
|
|
3
|
+
static getRandomString(size: number): string;
|
|
4
|
+
static encryptSymmetric(plaintext: Uint8Array | string, key: string, iv: string): Promise<{
|
|
5
|
+
ciphertext: Buffer;
|
|
6
|
+
iv: string;
|
|
7
|
+
}>;
|
|
8
|
+
static decryptSymmetricBuffer(ciphertext: Buffer, iv: Buffer, key: Buffer): Promise<Buffer<ArrayBuffer>>;
|
|
9
|
+
static decryptSymmetric(ciphertext: string, iv: string, key: string): Promise<string>;
|
|
10
|
+
static genKey(): string;
|
|
11
|
+
static genIv(): string;
|
|
12
|
+
static genIvAsBuffer(): Uint8Array<ArrayBuffer>;
|
|
13
|
+
static base64abc: string[];
|
|
14
|
+
static base64codes: number[];
|
|
15
|
+
static bytesToBase64(bytes: Uint8Array): string;
|
|
16
|
+
static isBitOn(byte: number, index: number): boolean;
|
|
17
|
+
static getBits(data: Uint8Array, bitOffset: number, numBits: number): number;
|
|
18
|
+
static numAsOneByteUint(num: number): Uint8Array<ArrayBuffer>;
|
|
19
|
+
static oneByteUint8AsNum(arr: Uint8Array): number;
|
|
20
|
+
}
|