@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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
PrivMX Web Endpoint.
|
|
4
|
+
Copyright © 2024 Simplito sp. z o.o.
|
|
5
|
+
|
|
6
|
+
This file is part of the PrivMX Platform (https://privmx.dev).
|
|
7
|
+
This software is Licensed under the PrivMX Free License.
|
|
8
|
+
|
|
9
|
+
See the License for the specific language governing permissions and
|
|
10
|
+
limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.StreamApiNative = void 0;
|
|
14
|
+
const WebRtcInterfaceImpl_1 = require("../webStreams/WebRtcInterfaceImpl");
|
|
15
|
+
const BaseNative_1 = require("./BaseNative");
|
|
16
|
+
class StreamApiNative extends BaseNative_1.BaseNative {
|
|
17
|
+
webRtcClient;
|
|
18
|
+
static bindingId = -1;
|
|
19
|
+
static getBindingId() {
|
|
20
|
+
return ++this.bindingId;
|
|
21
|
+
}
|
|
22
|
+
webRtcInterfacePtr = -1;
|
|
23
|
+
selfPtr = -1;
|
|
24
|
+
webRtcInterfaceImpl;
|
|
25
|
+
constructor(api, webRtcClient) {
|
|
26
|
+
super(api);
|
|
27
|
+
this.webRtcClient = webRtcClient;
|
|
28
|
+
webRtcClient.bindApiInterface({
|
|
29
|
+
trickle: (sessionId, candidate) => {
|
|
30
|
+
return this.trickle(this.selfPtr, [sessionId, candidate]);
|
|
31
|
+
},
|
|
32
|
+
acceptOffer: (sessionId, sdp) => {
|
|
33
|
+
return this.acceptOfferOnReconfigure(this.selfPtr, [sessionId, sdp]);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async newApi(connectionPtr, eventApiPtr) {
|
|
38
|
+
const bindingId = StreamApiNative.getBindingId();
|
|
39
|
+
this.bindWebRtcInterfaceAsHandler(bindingId);
|
|
40
|
+
this.selfPtr = await this.runAsync((taskId) => this.api.lib.StreamApi_newStreamApi(taskId, connectionPtr, eventApiPtr, bindingId));
|
|
41
|
+
return this.selfPtr;
|
|
42
|
+
}
|
|
43
|
+
async deleteApi(ptr) {
|
|
44
|
+
await this.runAsync((taskId) => this.api.lib.StreamApi_deleteStreamApi(taskId, ptr));
|
|
45
|
+
this.deleteApiRef();
|
|
46
|
+
}
|
|
47
|
+
async create(ptr, args) {
|
|
48
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_create(taskId, ptr, args));
|
|
49
|
+
}
|
|
50
|
+
async createStreamRoom(ptr, args) {
|
|
51
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_createStreamRoom(taskId, ptr, args));
|
|
52
|
+
}
|
|
53
|
+
async updateStreamRoom(ptr, args) {
|
|
54
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_updateStreamRoom(taskId, ptr, args));
|
|
55
|
+
}
|
|
56
|
+
async deleteStreamRoom(ptr, args) {
|
|
57
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_deleteStreamRoom(taskId, ptr, args));
|
|
58
|
+
}
|
|
59
|
+
async getStreamRoom(ptr, args) {
|
|
60
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_getStreamRoom(taskId, ptr, args));
|
|
61
|
+
}
|
|
62
|
+
async listStreamRooms(ptr, args) {
|
|
63
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_listStreamRooms(taskId, ptr, args));
|
|
64
|
+
}
|
|
65
|
+
async createStream(ptr, args) {
|
|
66
|
+
// params from api: streamRoomId, streamId
|
|
67
|
+
// params to lib: streamRoomId, streamId, webrtcInterfacePtr
|
|
68
|
+
// const libArgs: [string, number, number] = [...args, this.webRtcInterfacePtr];
|
|
69
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_createStream(taskId, ptr, args));
|
|
70
|
+
}
|
|
71
|
+
async joinStreamRoom(ptr, args) {
|
|
72
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_joinStreamRoom(taskId, ptr, args));
|
|
73
|
+
}
|
|
74
|
+
async leaveStreamRoom(ptr, args) {
|
|
75
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_leaveStreamRoom(taskId, ptr, args));
|
|
76
|
+
}
|
|
77
|
+
async enableStreamRoomRecording(ptr, args) {
|
|
78
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_enableStreamRoomRecording(taskId, ptr, args));
|
|
79
|
+
}
|
|
80
|
+
async getStreamRoomRecordingKeys(ptr, args) {
|
|
81
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_getStreamRoomRecordingKeys(taskId, ptr, args));
|
|
82
|
+
}
|
|
83
|
+
async publishStream(ptr, args) {
|
|
84
|
+
const ret = await this.runAsync((taskId) => this.api.lib.StreamApi_publishStream(taskId, ptr, args));
|
|
85
|
+
return ret;
|
|
86
|
+
}
|
|
87
|
+
async updateStream(ptr, args) {
|
|
88
|
+
const ret = await this.runAsync((taskId) => this.api.lib.StreamApi_updateStream(taskId, ptr, args));
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
async unpublishStream(ptr, args) {
|
|
92
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_unpublishStream(taskId, ptr, args));
|
|
93
|
+
}
|
|
94
|
+
async listStreams(ptr, args) {
|
|
95
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_listStreams(taskId, ptr, args));
|
|
96
|
+
}
|
|
97
|
+
async subscribeToRemoteStreams(ptr, args) {
|
|
98
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_subscribeToRemoteStreams(taskId, ptr, args));
|
|
99
|
+
}
|
|
100
|
+
async modifyRemoteStreamsSubscriptions(ptr, args) {
|
|
101
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_modifyRemoteStreamsSubscriptions(taskId, ptr, args));
|
|
102
|
+
}
|
|
103
|
+
async unsubscribeFromRemoteStreams(ptr, args) {
|
|
104
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_unsubscribeFromRemoteStreams(taskId, ptr, args));
|
|
105
|
+
}
|
|
106
|
+
async keyManagement(ptr, args) {
|
|
107
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_keyManagement(taskId, ptr, args));
|
|
108
|
+
}
|
|
109
|
+
async getTurnCredentials(ptr, args) {
|
|
110
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_getTurnCredentials(taskId, ptr, args));
|
|
111
|
+
}
|
|
112
|
+
async subscribeFor(ptr, args) {
|
|
113
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_subscribeFor(taskId, ptr, args));
|
|
114
|
+
}
|
|
115
|
+
async unsubscribeFrom(ptr, args) {
|
|
116
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_unsubscribeFrom(taskId, ptr, args));
|
|
117
|
+
}
|
|
118
|
+
async buildSubscriptionQuery(ptr, args) {
|
|
119
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_buildSubscriptionQuery(taskId, ptr, args));
|
|
120
|
+
}
|
|
121
|
+
async trickle(ptr, args) {
|
|
122
|
+
const [sessionId, candidate] = args;
|
|
123
|
+
const convertedArgs = [sessionId, JSON.stringify(candidate)];
|
|
124
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_trickle(taskId, ptr, convertedArgs));
|
|
125
|
+
}
|
|
126
|
+
async acceptOfferOnReconfigure(ptr, args) {
|
|
127
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_acceptOfferOnReconfigure(taskId, ptr, args));
|
|
128
|
+
}
|
|
129
|
+
async setNewOfferOnReconfigure(ptr, args) {
|
|
130
|
+
return this.runAsync((taskId) => this.api.lib.StreamApi_setNewOfferOnReconfigure(taskId, ptr, args));
|
|
131
|
+
}
|
|
132
|
+
bindWebRtcInterfaceAsHandler(bindingId) {
|
|
133
|
+
this.webRtcInterfaceImpl = new WebRtcInterfaceImpl_1.WebRtcInterfaceImpl(this.webRtcClient);
|
|
134
|
+
let windowBinder = window.webRtcInterfaceToNativeHandler;
|
|
135
|
+
if (!windowBinder) {
|
|
136
|
+
windowBinder = {};
|
|
137
|
+
}
|
|
138
|
+
windowBinder[bindingId] = this.webRtcInterfaceImpl;
|
|
139
|
+
window.webRtcInterfaceToNativeHandler = windowBinder;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.StreamApiNative = StreamApiNative;
|
|
@@ -14,8 +14,25 @@ export declare class ThreadApiNative extends BaseNative {
|
|
|
14
14
|
newApi(connectionPtr: number): Promise<number>;
|
|
15
15
|
deleteApi(ptr: number): Promise<void>;
|
|
16
16
|
create(ptr: number, args: []): Promise<void>;
|
|
17
|
-
createThread(ptr: number, args: [
|
|
18
|
-
|
|
17
|
+
createThread(ptr: number, args: [
|
|
18
|
+
string,
|
|
19
|
+
UserWithPubKey[],
|
|
20
|
+
UserWithPubKey[],
|
|
21
|
+
Uint8Array,
|
|
22
|
+
Uint8Array,
|
|
23
|
+
ContainerPolicy | undefined
|
|
24
|
+
]): Promise<string>;
|
|
25
|
+
updateThread(ptr: number, args: [
|
|
26
|
+
string,
|
|
27
|
+
UserWithPubKey[],
|
|
28
|
+
UserWithPubKey[],
|
|
29
|
+
Uint8Array,
|
|
30
|
+
Uint8Array,
|
|
31
|
+
number,
|
|
32
|
+
boolean,
|
|
33
|
+
boolean,
|
|
34
|
+
ContainerPolicy | undefined
|
|
35
|
+
]): Promise<void>;
|
|
19
36
|
deleteThread(ptr: number, args: [string]): Promise<void>;
|
|
20
37
|
getThread(ptr: number, args: [string]): Promise<Thread>;
|
|
21
38
|
listThreads(ptr: number, args: [string, PagingQuery]): Promise<PagingList<Thread>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={320:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.encryptWithAES256GCM=async function(e,t,r,n){try{const a=await crypto.subtle.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:t,additionalData:n,tagLength:128},a,r);return{success:!0,data:new Uint8Array(s)}}catch(e){return{success:!1,error:"EncryptionFailed"}}},t.decryptWithAES256GCM=async function(e,t,r,n){try{const a=await crypto.subtle.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:t,additionalData:n,tagLength:128},a,r);return{success:!0,data:new Uint8Array(s)}}catch(e){return{success:!1,error:"DecryptionFailed"}}},t.isEncryptionSuccess=function(e){return e.success},t.isDecryptionSuccess=function(e){return e.success}},928:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.KeyStore=void 0,t.KeyStore=class{_keys=new Map;_encryptionKeyId=void 0;setKeys(e){this._keys.clear();for(const t of e)this._keys.set(t.keyId,t),0===t.type&&(this._encryptionKeyId=t.keyId)}getKey(e){return this._keys.get(e)}hasKey(e){return this._keys.has(e)}getEncriptionKey(){if(!this._encryptionKeyId)throw new Error("No encryption key set.");return this._keys.get(this._encryptionKeyId)}}},251:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Utils=void 0;class r{static generateNumericId(){return Math.round(1e15*Math.random())}static getRandomString(e){return[...Array(e)].map((()=>Math.floor(16*Math.random()).toString(16))).join("")}static async encryptSymmetric(e,t,r){let n;n="string"==typeof e?(new TextEncoder).encode(e):e;const a=await crypto.subtle.importKey("raw",Buffer.from(t,"base64"),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:Buffer.from(r,"base64")},a,n);return{ciphertext:Buffer.from(s),iv:r}}static async decryptSymmetricBuffer(e,t,r){const n=await crypto.subtle.importKey("raw",r,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),a=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},n,e);return Buffer.from(a)}static async decryptSymmetric(e,t,r){const n=await crypto.subtle.importKey("raw",Buffer.from(r,"base64"),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),a=await crypto.subtle.decrypt({name:"AES-GCM",iv:Buffer.from(t,"base64")},n,Buffer.from(e,"base64"));return(new TextDecoder).decode(a)}static genKey(){return Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}static genIv(){return Buffer.from(crypto.getRandomValues(new Uint8Array(12))).toString("base64")}static genIvAsBuffer(){return crypto.getRandomValues(new Uint8Array(12))}static base64abc=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"];static base64codes=[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,62,255,255,255,63,52,53,54,55,56,57,58,59,60,61,255,255,255,0,255,255,255,0,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,255,255,255,255,255,255,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];static bytesToBase64(e){let t,n="",a=e.length;for(t=2;t<a;t+=3)n+=r.base64abc[e[t-2]>>2],n+=r.base64abc[(3&e[t-2])<<4|e[t-1]>>4],n+=r.base64abc[(15&e[t-1])<<2|e[t]>>6],n+=r.base64abc[63&e[t]];return t===a+1&&(n+=r.base64abc[e[t-2]>>2],n+=r.base64abc[(3&e[t-2])<<4],n+="=="),t===a&&(n+=r.base64abc[e[t-2]>>2],n+=r.base64abc[(3&e[t-2])<<4|e[t-1]>>4],n+=r.base64abc[(15&e[t-1])<<2],n+="="),n}static isBitOn(e,t){return Boolean(e&1<<t)}static getBits(e,t,r){const n=Math.pow(2,r)-1,a=t/8,s=t%=8;return e[a]>>s&n}static numAsOneByteUint(e){if(e>255)throw new Error("Out of bounds value");const t=new Uint8Array(1);return t[0]=e,t}static oneByteUint8AsNum(e){if(e[0]>255)throw new Error("Out of bounds value");return e[0]}}t.Utils=r}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(()=>{const e=r(251),t=r(320),n=r(928),a=new Map,s=new Map;let i=-99,o=-99,c=Date.now();class y{keyStore;constructor(e){this.keyStore=e}getHeaderSizeByType(e){return"key"===e?10:"delta"===e?3:"empty"===e?1:0}async encryptFrame(r,n,a){const s="video"===n?this.getHeaderSizeByType(r.type):1,o=new Uint8Array(r.data,0,s),c=new Uint8Array(r.data,s),y=e.Utils.genIvAsBuffer(),u=this.keyStore.getEncriptionKey(),d=await(0,t.encryptWithAES256GCM)(u.key,y,c,o);if(!(0,t.isEncryptionSuccess)(d))throw new Error("Cannot encrypt frame");const p=(new TextEncoder).encode(u.keyId),f=o.byteLength,l=f+d.data.byteLength,m=l+y.byteLength,b=m+1,w=b+p.byteLength,h=w+1,g=new ArrayBuffer(h+1),S=new Uint8Array(g);S.set(o),S.set(new Uint8Array(d.data),f),S.set(y,l),S.set(e.Utils.numAsOneByteUint(y.byteLength),m),S.set(p,b),S.set(e.Utils.numAsOneByteUint(p.byteLength),w),S.set(e.Utils.numAsOneByteUint(i+100),h),r.data=g,a.enqueue(r)}async decryptFrame(e,r,n,a,s){const i="video"===r?this.getHeaderSizeByType(e.type):1,y=e.data;if(y.byteLength<i+5)return void n.enqueue(e);const u=new Uint8Array(y,0,i),d=y.byteLength-1;o=new Uint8Array(y,d,1)[0]-100;const f=Date.now();c+100<f&&(c=f,self.postMessage({type:"rms",rms:o,receiverId:a,publisherId:s}));const l=d-1,m=new Uint8Array(y,l,1)[0],b=l-m,w=(new TextDecoder).decode(new Uint8Array(y,b,m)),h=b-1,g=new Uint8Array(y,h,1)[0],S=h-g,A=new Uint8Array(y,S,g),v=i,M=S-i,U=y.slice(v,v+M);try{if(!this.keyStore.hasKey(w))return void n.enqueue(e);const r=this.keyStore.getKey(w),a=await(0,t.decryptWithAES256GCM)(r.key,A,U,u);if(!(0,t.isDecryptionSuccess)(a))return void n.enqueue(e);const s=a.data,i=new ArrayBuffer(u.byteLength+s.byteLength),o=new Uint8Array(i);o.set(u),o.set(new Uint8Array(s),u.byteLength),e.data=i,n.enqueue(e)}catch(t){p(t),n.enqueue(e)}}}self.keyStore=new n.KeyStore;const u=()=>self.keyStore;function d(e,t,r,n,s){let i;if(JSON.stringify({operation:t,context:e}),"encode"===t)i=function(e,t){const r=new y(e);return new TransformStream({async transform(e,n){await r.encryptFrame(e,t,n)}})}(e.keyStore,r),n.pipeThrough(i).pipeTo(s);else if("decode"===t){i=function(e,t){const r=new y(e.keyStore);return new TransformStream({async transform(n,a){await r.decryptFrame(n,t,a,e.id,e.publisherId)}})}(e,r);const t=n.pipeThrough(i).pipeTo(s).catch((e=>{String(e).includes("Destination stream closed")||console.error("pipeline error",e)}));e.id&&a.set(e.id,{pipeline:t})}}function p(e){self.postMessage({type:"error",data:e})}self.onmessage=async e=>{const{operation:t,kind:r}=e.data;if("initialize"===t);else if("init-pipeline"===t)s.set(e.data.id,{ready:!1}),self.postMessage({operation:"init-pipeline",id:e.data.id});else if("encode"===t||"decode"===t){const{readableStream:n,writableStream:a,id:s,publisherId:i}=e.data;d({keyStore:u(),id:s,publisherId:i},t,r,n,a)}else if("setKeys"===t){const t=e.data;u().setKeys(t.keys)}else"rms"===t&&(i=Math.round(e.data.rms))},self.RTCTransformEvent&&(self.onrtctransform=e=>{const t=e.transformer,r=t.options;if(!r)return void p("onrtctransform: options is undefined");const{operation:n,kind:a,id:s,publisherId:i}=r;d({keyStore:u(),id:s,publisherId:i},n,a,t.readable,t.writable)})})()})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see privmx-endpoint-web.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["privmx-webendpoint"]=t():e.PrivmxWebEndpoint=t()}(this,(()=>(()=>{var e={526:(e,t)=>{"use strict";t.byteLength=function(e){var t=o(e),i=t[0],r=t[1];return 3*(i+r)/4-r},t.toByteArray=function(e){var t,i,s=o(e),a=s[0],c=s[1],u=new n(function(e,t,i){return 3*(t+i)/4-i}(0,a,c)),h=0,l=c>0?a-4:a;for(i=0;i<l;i+=4)t=r[e.charCodeAt(i)]<<18|r[e.charCodeAt(i+1)]<<12|r[e.charCodeAt(i+2)]<<6|r[e.charCodeAt(i+3)],u[h++]=t>>16&255,u[h++]=t>>8&255,u[h++]=255&t;return 2===c&&(t=r[e.charCodeAt(i)]<<2|r[e.charCodeAt(i+1)]>>4,u[h++]=255&t),1===c&&(t=r[e.charCodeAt(i)]<<10|r[e.charCodeAt(i+1)]<<4|r[e.charCodeAt(i+2)]>>2,u[h++]=t>>8&255,u[h++]=255&t),u},t.fromByteArray=function(e){for(var t,r=e.length,n=r%3,s=[],a=16383,o=0,u=r-n;o<u;o+=a)s.push(c(e,o,o+a>u?u:o+a));return 1===n?(t=e[r-1],s.push(i[t>>2]+i[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],s.push(i[t>>10]+i[t>>4&63]+i[t<<2&63]+"=")),s.join("")};for(var i=[],r=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0;a<64;++a)i[a]=s[a],r[s.charCodeAt(a)]=a;function o(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function c(e,t,r){for(var n,s,a=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(i[(s=n)>>18&63]+i[s>>12&63]+i[s>>6&63]+i[63&s]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},287:(e,t,i)=>{"use strict";const r=i(526),n=i(632),s="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.hp=c,t.IS=50;const a=2147483647;function o(e){if(e>a)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,i){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return l(e)}return u(e,t,i)}function u(e,t,i){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const i=0|f(e,t);let r=o(i);const n=r.write(e,t);return n!==i&&(r=r.slice(0,n)),r}(e,t);if(ArrayBuffer.isView(e))return function(e){if(q(e,Uint8Array)){const t=new Uint8Array(e);return d(t.buffer,t.byteOffset,t.byteLength)}return p(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(q(e,ArrayBuffer)||e&&q(e.buffer,ArrayBuffer))return d(e,t,i);if("undefined"!=typeof SharedArrayBuffer&&(q(e,SharedArrayBuffer)||e&&q(e.buffer,SharedArrayBuffer)))return d(e,t,i);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=e.valueOf&&e.valueOf();if(null!=r&&r!==e)return c.from(r,t,i);const n=function(e){if(c.isBuffer(e)){const t=0|y(e.length),i=o(t);return 0===i.length||e.copy(i,0,0,t),i}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?o(0):p(e):"Buffer"===e.type&&Array.isArray(e.data)?p(e.data):void 0}(e);if(n)return n;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,i);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function l(e){return h(e),o(e<0?0:0|y(e))}function p(e){const t=e.length<0?0:0|y(e.length),i=o(t);for(let r=0;r<t;r+=1)i[r]=255&e[r];return i}function d(e,t,i){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(i||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===t&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,t):new Uint8Array(e,t,i),Object.setPrototypeOf(r,c.prototype),r}function y(e){if(e>=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return 0|e}function f(e,t){if(c.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const i=e.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===i)return 0;let n=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return $(e).length;default:if(n)return r?-1:H(e).length;t=(""+t).toLowerCase(),n=!0}}function b(e,t,i){let r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,i);case"utf8":case"utf-8":return I(this,t,i);case"ascii":return R(this,t,i);case"latin1":case"binary":return k(this,t,i);case"base64":return _(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,t,i);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function v(e,t,i){const r=e[t];e[t]=e[i],e[i]=r}function g(e,t,i,r,n){if(0===e.length)return-1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),Y(i=+i)&&(i=n?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(n)return-1;i=e.length-1}else if(i<0){if(!n)return-1;i=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:m(e,t,i,r,n);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):m(e,[t],i,r,n);throw new TypeError("val must be string, number or Buffer")}function m(e,t,i,r,n){let s,a=1,o=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;a=2,o/=2,c/=2,i/=2}function u(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(n){let r=-1;for(s=i;s<o;s++)if(u(e,s)===u(t,-1===r?0:s-r)){if(-1===r&&(r=s),s-r+1===c)return r*a}else-1!==r&&(s-=s-r),r=-1}else for(i+c>o&&(i=o-c),s=i;s>=0;s--){let i=!0;for(let r=0;r<c;r++)if(u(e,s+r)!==u(t,r)){i=!1;break}if(i)return s}return-1}function A(e,t,i,r){i=Number(i)||0;const n=e.length-i;r?(r=Number(r))>n&&(r=n):r=n;const s=t.length;let a;for(r>s/2&&(r=s/2),a=0;a<r;++a){const r=parseInt(t.substr(2*a,2),16);if(Y(r))return a;e[i+a]=r}return a}function w(e,t,i,r){return G(H(t,e.length-i),e,i,r)}function S(e,t,i,r){return G(function(e){const t=[];for(let i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,r)}function E(e,t,i,r){return G($(t),e,i,r)}function P(e,t,i,r){return G(function(e,t){let i,r,n;const s=[];for(let a=0;a<e.length&&!((t-=2)<0);++a)i=e.charCodeAt(a),r=i>>8,n=i%256,s.push(n),s.push(r);return s}(t,e.length-i),e,i,r)}function _(e,t,i){return 0===t&&i===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,i))}function I(e,t,i){i=Math.min(e.length,i);const r=[];let n=t;for(;n<i;){const t=e[n];let s=null,a=t>239?4:t>223?3:t>191?2:1;if(n+a<=i){let i,r,o,c;switch(a){case 1:t<128&&(s=t);break;case 2:i=e[n+1],128==(192&i)&&(c=(31&t)<<6|63&i,c>127&&(s=c));break;case 3:i=e[n+1],r=e[n+2],128==(192&i)&&128==(192&r)&&(c=(15&t)<<12|(63&i)<<6|63&r,c>2047&&(c<55296||c>57343)&&(s=c));break;case 4:i=e[n+1],r=e[n+2],o=e[n+3],128==(192&i)&&128==(192&r)&&128==(192&o)&&(c=(15&t)<<18|(63&i)<<12|(63&r)<<6|63&o,c>65535&&c<1114112&&(s=c))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),n+=a}return function(e){const t=e.length;if(t<=C)return String.fromCharCode.apply(String,e);let i="",r=0;for(;r<t;)i+=String.fromCharCode.apply(String,e.slice(r,r+=C));return i}(r)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),c.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,i){return u(e,t,i)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array),c.alloc=function(e,t,i){return function(e,t,i){return h(e),e<=0?o(e):void 0!==t?"string"==typeof i?o(e).fill(t,i):o(e).fill(t):o(e)}(e,t,i)},c.allocUnsafe=function(e){return l(e)},c.allocUnsafeSlow=function(e){return l(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(q(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),q(t,Uint8Array)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,r=t.length;for(let n=0,s=Math.min(i,r);n<s;++n)if(e[n]!==t[n]){i=e[n],r=t[n];break}return i<r?-1:r<i?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;const r=c.allocUnsafe(t);let n=0;for(i=0;i<e.length;++i){let t=e[i];if(q(t,Uint8Array))n+t.length>r.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(r,n)):Uint8Array.prototype.set.call(r,t,n);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(r,n)}n+=t.length}return r},c.byteLength=f,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)v(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)v(this,t,t+3),v(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)v(this,t,t+7),v(this,t+1,t+6),v(this,t+2,t+5),v(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?I(this,0,e):b.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let e="";const i=t.IS;return e=this.toString("hex",0,i).replace(/(.{2})/g,"$1 ").trim(),this.length>i&&(e+=" ... "),"<Buffer "+e+">"},s&&(c.prototype[s]=c.prototype.inspect),c.prototype.compare=function(e,t,i,r,n){if(q(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===r&&(r=0),void 0===n&&(n=this.length),t<0||i>e.length||r<0||n>this.length)throw new RangeError("out of range index");if(r>=n&&t>=i)return 0;if(r>=n)return-1;if(t>=i)return 1;if(this===e)return 0;let s=(n>>>=0)-(r>>>=0),a=(i>>>=0)-(t>>>=0);const o=Math.min(s,a),u=this.slice(r,n),h=e.slice(t,i);for(let e=0;e<o;++e)if(u[e]!==h[e]){s=u[e],a=h[e];break}return s<a?-1:a<s?1:0},c.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},c.prototype.indexOf=function(e,t,i){return g(this,e,t,i,!0)},c.prototype.lastIndexOf=function(e,t,i){return g(this,e,t,i,!1)},c.prototype.write=function(e,t,i,r){if(void 0===t)r="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)r=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(i)?(i>>>=0,void 0===r&&(r="utf8")):(r=i,i=void 0)}const n=this.length-t;if((void 0===i||i>n)&&(i=n),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let s=!1;for(;;)switch(r){case"hex":return A(this,e,t,i);case"utf8":case"utf-8":return w(this,e,t,i);case"ascii":case"latin1":case"binary":return S(this,e,t,i);case"base64":return E(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,e,t,i);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const C=4096;function R(e,t,i){let r="";i=Math.min(e.length,i);for(let n=t;n<i;++n)r+=String.fromCharCode(127&e[n]);return r}function k(e,t,i){let r="";i=Math.min(e.length,i);for(let n=t;n<i;++n)r+=String.fromCharCode(e[n]);return r}function T(e,t,i){const r=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>r)&&(i=r);let n="";for(let r=t;r<i;++r)n+=J[e[r]];return n}function M(e,t,i){const r=e.slice(t,i);let n="";for(let e=0;e<r.length-1;e+=2)n+=String.fromCharCode(r[e]+256*r[e+1]);return n}function B(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function F(e,t,i,r,n,s){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<s)throw new RangeError('"value" argument is out of bounds');if(i+r>e.length)throw new RangeError("Index out of range")}function x(e,t,i,r,n){j(t,r,n,e,i,7);let s=Number(t&BigInt(4294967295));e[i++]=s,s>>=8,e[i++]=s,s>>=8,e[i++]=s,s>>=8,e[i++]=s;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[i++]=a,a>>=8,e[i++]=a,a>>=8,e[i++]=a,a>>=8,e[i++]=a,i}function K(e,t,i,r,n){j(t,r,n,e,i,7);let s=Number(t&BigInt(4294967295));e[i+7]=s,s>>=8,e[i+6]=s,s>>=8,e[i+5]=s,s>>=8,e[i+4]=s;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[i+3]=a,a>>=8,e[i+2]=a,a>>=8,e[i+1]=a,a>>=8,e[i]=a,i+8}function L(e,t,i,r,n,s){if(i+r>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function O(e,t,i,r,s){return t=+t,i>>>=0,s||L(e,0,i,4),n.write(e,t,i,r,23,4),i+4}function U(e,t,i,r,s){return t=+t,i>>>=0,s||L(e,0,i,8),n.write(e,t,i,r,52,8),i+8}c.prototype.slice=function(e,t){const i=this.length;(e=~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),(t=void 0===t?i:~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),t<e&&(t=e);const r=this.subarray(e,t);return Object.setPrototypeOf(r,c.prototype),r},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,i){e>>>=0,t>>>=0,i||B(e,t,this.length);let r=this[e],n=1,s=0;for(;++s<t&&(n*=256);)r+=this[e+s]*n;return r},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,i){e>>>=0,t>>>=0,i||B(e,t,this.length);let r=this[e+--t],n=1;for(;t>0&&(n*=256);)r+=this[e+--t]*n;return r},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=Z((function(e){Q(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||z(e,this.length-8);const r=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,n=this[++e]+256*this[++e]+65536*this[++e]+i*2**24;return BigInt(r)+(BigInt(n)<<BigInt(32))})),c.prototype.readBigUInt64BE=Z((function(e){Q(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||z(e,this.length-8);const r=t*2**24+65536*this[++e]+256*this[++e]+this[++e],n=this[++e]*2**24+65536*this[++e]+256*this[++e]+i;return(BigInt(r)<<BigInt(32))+BigInt(n)})),c.prototype.readIntLE=function(e,t,i){e>>>=0,t>>>=0,i||B(e,t,this.length);let r=this[e],n=1,s=0;for(;++s<t&&(n*=256);)r+=this[e+s]*n;return n*=128,r>=n&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,i){e>>>=0,t>>>=0,i||B(e,t,this.length);let r=t,n=1,s=this[e+--r];for(;r>0&&(n*=256);)s+=this[e+--r]*n;return n*=128,s>=n&&(s-=Math.pow(2,8*t)),s},c.prototype.readInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||B(e,2,this.length);const i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt16BE=function(e,t){e>>>=0,t||B(e,2,this.length);const i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=Z((function(e){Q(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||z(e,this.length-8);const r=this[e+4]+256*this[e+5]+65536*this[e+6]+(i<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),c.prototype.readBigInt64BE=Z((function(e){Q(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||z(e,this.length-8);const r=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+i)})),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||B(e,4,this.length),n.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||B(e,4,this.length),n.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||B(e,8,this.length),n.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||B(e,8,this.length),n.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,i,r){e=+e,t>>>=0,i>>>=0,r||F(this,e,t,i,Math.pow(2,8*i)-1,0);let n=1,s=0;for(this[t]=255&e;++s<i&&(n*=256);)this[t+s]=e/n&255;return t+i},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,i,r){e=+e,t>>>=0,i>>>=0,r||F(this,e,t,i,Math.pow(2,8*i)-1,0);let n=i-1,s=1;for(this[t+n]=255&e;--n>=0&&(s*=256);)this[t+n]=e/s&255;return t+i},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=Z((function(e,t=0){return x(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),c.prototype.writeBigUInt64BE=Z((function(e,t=0){return K(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),c.prototype.writeIntLE=function(e,t,i,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*i-1);F(this,e,t,i,r-1,-r)}let n=0,s=1,a=0;for(this[t]=255&e;++n<i&&(s*=256);)e<0&&0===a&&0!==this[t+n-1]&&(a=1),this[t+n]=(e/s|0)-a&255;return t+i},c.prototype.writeIntBE=function(e,t,i,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*i-1);F(this,e,t,i,r-1,-r)}let n=i-1,s=1,a=0;for(this[t+n]=255&e;--n>=0&&(s*=256);)e<0&&0===a&&0!==this[t+n+1]&&(a=1),this[t+n]=(e/s|0)-a&255;return t+i},c.prototype.writeInt8=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,i){return e=+e,t>>>=0,i||F(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=Z((function(e,t=0){return x(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),c.prototype.writeBigInt64BE=Z((function(e,t=0){return K(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),c.prototype.writeFloatLE=function(e,t,i){return O(this,e,t,!0,i)},c.prototype.writeFloatBE=function(e,t,i){return O(this,e,t,!1,i)},c.prototype.writeDoubleLE=function(e,t,i){return U(this,e,t,!0,i)},c.prototype.writeDoubleBE=function(e,t,i){return U(this,e,t,!1,i)},c.prototype.copy=function(e,t,i,r){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<i&&(r=i),r===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-i&&(r=e.length-t+i);const n=r-i;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,i,r):Uint8Array.prototype.set.call(e,this.subarray(i,r),t),n},c.prototype.fill=function(e,t,i,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,i=this.length):"string"==typeof i&&(r=i,i=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===e.length){const t=e.charCodeAt(0);("utf8"===r&&t<128||"latin1"===r)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;let n;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(n=t;n<i;++n)this[n]=e;else{const s=c.isBuffer(e)?e:c.from(e,r),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(n=0;n<i-t;++n)this[n+t]=s[n%a]}return this};const N={};function W(e,t,i){N[e]=class extends i{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function D(e){let t="",i=e.length;const r="-"===e[0]?1:0;for(;i>=r+4;i-=3)t=`_${e.slice(i-3,i)}${t}`;return`${e.slice(0,i)}${t}`}function j(e,t,i,r,n,s){if(e>i||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=s>3?0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(s+1)}${r}`:`>= -(2${r} ** ${8*(s+1)-1}${r}) and < 2 ** ${8*(s+1)-1}${r}`:`>= ${t}${r} and <= ${i}${r}`,new N.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,i){Q(t,"offset"),void 0!==e[t]&&void 0!==e[t+i]||z(t,e.length-(i+1))}(r,n,s)}function Q(e,t){if("number"!=typeof e)throw new N.ERR_INVALID_ARG_TYPE(t,"number",e)}function z(e,t,i){if(Math.floor(e)!==e)throw Q(e,i),new N.ERR_OUT_OF_RANGE(i||"offset","an integer",e);if(t<0)throw new N.ERR_BUFFER_OUT_OF_BOUNDS;throw new N.ERR_OUT_OF_RANGE(i||"offset",`>= ${i?1:0} and <= ${t}`,e)}W("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),W("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),W("ERR_OUT_OF_RANGE",(function(e,t,i){let r=`The value of "${e}" is out of range.`,n=i;return Number.isInteger(i)&&Math.abs(i)>2**32?n=D(String(i)):"bigint"==typeof i&&(n=String(i),(i>BigInt(2)**BigInt(32)||i<-(BigInt(2)**BigInt(32)))&&(n=D(n)),n+="n"),r+=` It must be ${t}. Received ${n}`,r}),RangeError);const V=/[^+/0-9A-Za-z-_]/g;function H(e,t){let i;t=t||1/0;const r=e.length;let n=null;const s=[];for(let a=0;a<r;++a){if(i=e.charCodeAt(a),i>55295&&i<57344){if(!n){if(i>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(a+1===r){(t-=3)>-1&&s.push(239,191,189);continue}n=i;continue}if(i<56320){(t-=3)>-1&&s.push(239,191,189),n=i;continue}i=65536+(n-55296<<10|i-56320)}else n&&(t-=3)>-1&&s.push(239,191,189);if(n=null,i<128){if((t-=1)<0)break;s.push(i)}else if(i<2048){if((t-=2)<0)break;s.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;s.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return s}function $(e){return r.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(V,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function G(e,t,i,r){let n;for(n=0;n<r&&!(n+i>=t.length||n>=e.length);++n)t[n+i]=e[n];return n}function q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const J=function(){const e="0123456789abcdef",t=new Array(256);for(let i=0;i<16;++i){const r=16*i;for(let n=0;n<16;++n)t[r+n]=e[i]+e[n]}return t}();function Z(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}},632:(e,t)=>{t.read=function(e,t,i,r,n){var s,a,o=8*n-r-1,c=(1<<o)-1,u=c>>1,h=-7,l=i?n-1:0,p=i?-1:1,d=e[t+l];for(l+=p,s=d&(1<<-h)-1,d>>=-h,h+=o;h>0;s=256*s+e[t+l],l+=p,h-=8);for(a=s&(1<<-h)-1,s>>=-h,h+=r;h>0;a=256*a+e[t+l],l+=p,h-=8);if(0===s)s=1-u;else{if(s===c)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,r),s-=u}return(d?-1:1)*a*Math.pow(2,s-r)},t.write=function(e,t,i,r,n,s){var a,o,c,u=8*s-n-1,h=(1<<u)-1,l=h>>1,p=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,y=r?1:-1,f=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=h):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+l>=1?p/c:p*Math.pow(2,1-l))*c>=2&&(a++,c/=2),a+l>=h?(o=0,a=h):a+l>=1?(o=(t*c-1)*Math.pow(2,n),a+=l):(o=t*Math.pow(2,l-1)*Math.pow(2,n),a=0));n>=8;e[i+d]=255&o,d+=y,o/=256,n-=8);for(a=a<<n|o,u+=n;u>0;e[i+d]=255&a,d+=y,a/=256,u-=8);e[i+d-y]|=128*f}},54:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FinalizationHelper=void 0;const r=i(457);class n{wasmLib;static instance;static wasmLib;static init(e){n.wasmLib=e}static getInstance(){if(!n.wasmLib)throw new Error("Initialize first with the WASM Library object");return this.instance||(this.instance=new n(n.wasmLib)),this.instance}finalizationRegistry;finalizationQueue=[];scheduler=null;constructor(e){this.wasmLib=e,this.finalizationRegistry=new FinalizationRegistry((e=>{r.ApiStatic.getInstance(),this.finalizationQueue.push(e.onFree),this.scheduleCleanup()}))}scheduleCleanup(){this.scheduler||(this.scheduler=setTimeout((async()=>{for(const e of this.finalizationQueue)await e();this.finalizationQueue=[],clearTimeout(this.scheduler),this.scheduler=null}),1e3))}register(e,t){this.finalizationRegistry.register(e,t,e)}}t.FinalizationHelper=n},667:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;const r=i(785),n=i(708);t.Api=class{lib;promises;taskIdGenerator;constructor(e){this.lib=e,this.taskIdGenerator=new r.IdGenerator,this.promises=new Map,this.setResultsCallback()}async runAsync(e){return new Promise(((t,i)=>{const r=this.generateId();this.promises.set(r,{resolve:t,reject:i}),e(r)}))}resolveResult(e){1==e.status?this.promises.get(e.taskId).resolve(e.result):this.promises.get(e.taskId).reject(this.toNativeError(e.error)),this.promises.delete(e.taskId)}generateId(){return this.taskIdGenerator.generateId()}setResultsCallback(){this.lib.setResultsCallback((e=>this.resolveResult(e)))}toNativeError(e){return this.isRawCppError(e)?new n.NativeError(e):e instanceof Error?e:new Error("string"==typeof e?e:JSON.stringify(e))}isRawCppError(e){return"object"==typeof e&&null!==e&&"code"in e&&"name"in e&&"scope"in e}}},457:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ApiStatic=void 0,t.ApiStatic=class{static instance;static init(e){this.instance=e}static getInstance(){if(!this.instance)throw new Error("API Static not initialized");return this.instance}}},361:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseNative=void 0,t.BaseNative=class{_api;constructor(e){this._api=e}get api(){if(!this._api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._api}deleteApiRef(){this._api=null}async runAsync(e){if(!this.api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this.api.runAsync(e)}}},140:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ConnectionNative=void 0;const r=i(361);class n extends r.BaseNative{lastConnectionId=-1;userVerifierPtr=-1;static verifierBindingId=-1;static getVerifierBindingId(){return++this.verifierBindingId}async newApi(e){throw new Error("Use the newConnection() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async newConnection(){return this.runAsync((e=>this.api.lib.Connection_newConnection(e)))}async deleteConnection(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async connect(e,t){await this.runAsync((i=>this.api.lib.Connection_connect(i,e,t))),await this.getConnectionId(e,[])}async connectPublic(e,t){return this.runAsync((i=>this.api.lib.Connection_connectPublic(i,e,t)))}async getConnectionId(e,t){return this.lastConnectionId<0&&(this.lastConnectionId=await this.runAsync((i=>this.api.lib.Connection_getConnectionId(i,e,t)))),this.lastConnectionId}async listContexts(e,t){return this.runAsync((i=>this.api.lib.Connection_listContexts(i,e,t)))}async listContextUsers(e,t){return this.runAsync((i=>this.api.lib.Connection_listContextUsers(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.Connection_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.Connection_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.Connection_buildSubscriptionQuery(i,e,t)))}async disconnect(e,t){await this.runAsync((i=>this.api.lib.Connection_disconnect(i,e,t)))}async setUserVerifier(e,t){this.userVerifierPtr>-1&&(await this.deleteUserVerifierInterface(this.userVerifierPtr),this.userVerifierPtr=-1);const[i,r]=t,s=n.getVerifierBindingId();window.userVerifierBinder||(window.userVerifierBinder={}),window.userVerifierBinder[s]={userVierifier_verify:async e=>{if(r&&"function"==typeof r.verify)return r.verify(e);throw new Error("Call on UserVerifierInterface with missing implementation")}},this.userVerifierPtr=await this.runAsync((e=>this.api.lib.Connection_newUserVerifierInterface(e,i,s)))}async newUserVerifierInterface(e){return this.runAsync((t=>this.api.lib.Connection_newUserVerifierInterface(t,e)))}async deleteUserVerifierInterface(e){await this.runAsync((t=>this.api.lib.Connection_deleteUserVerifierInterface(t,e)))}}t.ConnectionNative=n},711:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApiNative=void 0;const r=i(504),n=i(361);class s extends n.BaseNative{async newApi(){return this.runAsync((e=>this.api.lib.CryptoApi_newCryptoApi(e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.CryptoApi_deleteCryptoApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_create(i,e,t)))}async signData(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_signData(i,e,t)))}async verifySignature(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_verifySignature(i,e,t)))}async generatePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generatePrivateKey(i,e,t)))}async derivePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey(i,e,t)))}async derivePrivateKey2(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey2(i,e,t)))}async derivePublicKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePublicKey(i,e,t)))}async generateKeySymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generateKeySymmetric(i,e,t)))}async encryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_encryptDataSymmetric(i,e,t)))}async decryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_decryptDataSymmetric(i,e,t)))}async convertPEMKeytoWIFKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_convertPEMKeytoWIFKey(i,e,t)))}async generateBip39(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_generateBip39(i,e,t)));return this.convertBIP(i)}async fromMnemonic(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_fromMnemonic(i,e,t)));return this.convertBIP(i)}async fromEntropy(e,t){const i=await this.runAsync((i=>this.api.lib.CryptoApi_fromEntropy(i,e,t)));return this.convertBIP(i)}async entropyToMnemonic(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_entropyToMnemonic(i,e,t)))}async mnemonicToEntropy(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_mnemonicToEntropy(i,e,t)))}async mnemonicToSeed(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_mnemonicToSeed(i,e,t)))}convertBIP(e){return{mnemonic:e.mnemonic,entropy:e.entropy,extKey:r.ExtKey.fromPtr(e.extKey)}}}t.CryptoApiNative=s},688:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EventApiNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.EventApi_newEventApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventApi_deleteEventApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.EventApi_create(i,e,t)))}async emitEvent(e,t){return this.runAsync((i=>this.api.lib.EventApi_emitEvent(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.EventApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.EventApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.EventApi_buildSubscriptionQuery(i,e,t)))}}t.EventApiNative=n},467:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueueNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e){throw new Error("Use the newEventQueue() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async newEventQueue(){return this.runAsync((e=>this.api.lib.EventQueue_newEventQueue(e)))}async deleteEventQueue(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async waitEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_waitEvent(i,e,t)))}async emitBreakEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_emitBreakEvent(i,e,t)))}}t.EventQueueNative=n},614:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ExtKeyNative=void 0;const r=i(457),n=i(361);class s extends n.BaseNative{async newApi(){throw new Error("Use the specialized version of method instead.")}async deleteApi(e){return this.runAsync((t=>this.api.lib.ExtKey_deleteExtKey(t,e)))}async deleteExtKey(e){return this.runAsync((t=>this.api.lib.ExtKey_deleteExtKey(t,e)))}static async fromSeed(e){const t=r.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_fromSeed(i,e)))}static async fromBase58(e){const t=r.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_fromBase58(i,e)))}static async generateRandom(e){const t=r.ApiStatic.getInstance();return t.runAsync((i=>t.lib.ExtKey_generateRandom(i,e)))}async derive(e,t){return this.runAsync((i=>this.api.lib.ExtKey_derive(i,e,t)))}async deriveHardened(e,t){return this.runAsync((i=>this.api.lib.ExtKey_deriveHardened(i,e,t)))}getPrivatePartAsBase58(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivatePartAsBase58(i,e,t)))}getPublicPartAsBase58(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicPartAsBase58(i,e,t)))}getPrivateKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivateKey(i,e,t)))}getPublicKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicKey(i,e,t)))}getPrivateEncKey(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPrivateEncKey(i,e,t)))}getPublicKeyAsBase58Address(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getPublicKeyAsBase58Address(i,e,t)))}getChainCode(e,t){return this.runAsync((i=>this.api.lib.ExtKey_getChainCode(i,e,t)))}verifyCompactSignatureWithHash(e,t){return this.runAsync((i=>this.api.lib.ExtKey_verifyCompactSignatureWithHash(i,e,t)))}isPrivate(e,t){return this.runAsync((i=>this.api.lib.ExtKey_isPrivate(i,e,t)))}}t.ExtKeyNative=s},785:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.IdGenerator=void 0,t.IdGenerator=class{_id=0;generateId(){return this._id++,this._id}}},252:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApiNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e,t,i){return this.runAsync((r=>this.api.lib.InboxApi_newInboxApi(r,e,t,i)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.InboxApi_deleteInboxApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.InboxApi_create(i,e,t)))}async createInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createInbox(i,e,t)))}async updateInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_updateInbox(i,e,t)))}async getInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInbox(i,e,t)))}async listInboxes(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listInboxes(i,e,t)))}async getInboxPublicView(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInboxPublicView(i,e,t)))}async deleteInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteInbox(i,e,t)))}async prepareEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_prepareEntry(i,e,t)))}async sendEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_sendEntry(i,e,t)))}async readEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readEntry(i,e,t)))}async deleteEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteEntry(i,e,t)))}async listEntries(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listEntries(i,e,t)))}async createFileHandle(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createFileHandle(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_writeToFile(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_closeFile(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.InboxApi_buildSubscriptionQuery(i,e,t)))}}t.InboxApiNative=n},453:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KvdbApiNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.KvdbApi_newKvdbApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.KvdbApi_deleteKvdbApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_create(i,e,t)))}async createKvdb(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_createKvdb(i,e,t)))}async updateKvdb(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_updateKvdb(i,e,t)))}async deleteKvdb(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_deleteKvdb(i,e,t)))}async getKvdb(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_getKvdb(i,e,t)))}async listKvdbs(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_listKvdbs(i,e,t)))}async hasEntry(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_hasEntry(i,e,t)))}async getEntry(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_getEntry(i,e,t)))}async listEntriesKeys(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_listEntriesKeys(i,e,t)))}async listEntries(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_listEntries(i,e,t)))}async setEntry(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_setEntry(i,e,t)))}async deleteEntry(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_deleteEntry(i,e,t)))}async deleteEntries(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_deleteEntries(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_buildSubscriptionQuery(i,e,t)))}async buildSubscriptionQueryForSelectedEntry(e,t){return this.runAsync((i=>this.api.lib.KvdbApi_buildSubscriptionQueryForSelectedEntry(i,e,t)))}}t.KvdbApiNative=n},708:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NativeError=void 0;class i extends Error{code;scope;fullMessage;constructor(e){super(e.description||e.full),Object.setPrototypeOf(this,i.prototype),this.name=e.name||"NativeError",this.code=e.code,this.scope=e.scope,this.fullMessage=e.full,this.stack&&e.full&&(this.stack+=`\n Caused by Native C++ Exception: ${e.full}`)}}t.NativeError=i},243:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApiNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.StoreApi_newStoreApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.StoreApi_deleteStoreApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.StoreApi_create(i,e,t)))}async createStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createStore(i,e,t)))}async updateStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateStore(i,e,t)))}async deleteStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteStore(i,e,t)))}async getStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getStore(i,e,t)))}async listStores(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listStores(i,e,t)))}async createFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createFile(i,e,t)))}async updateFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFile(i,e,t)))}async updateFileMeta(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFileMeta(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_writeToFile(i,e,t)))}async deleteFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteFile(i,e,t)))}async getFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getFile(i,e,t)))}async listFiles(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listFiles(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_closeFile(i,e,t)))}async syncFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_syncFile(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.StoreApi_buildSubscriptionQuery(i,e,t)))}}t.StoreApiNative=n},620:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StreamApiNative=void 0;const r=i(332),n=i(361);class s extends n.BaseNative{webRtcClient;static bindingId=-1;static getBindingId(){return++this.bindingId}webRtcInterfacePtr=-1;selfPtr=-1;webRtcInterfaceImpl;constructor(e,t){super(e),this.webRtcClient=t,t.bindApiInterface({trickle:(e,t)=>this.trickle(this.selfPtr,[e,t]),acceptOffer:(e,t)=>this.acceptOfferOnReconfigure(this.selfPtr,[e,t])})}async newApi(e,t){const i=s.getBindingId();return this.bindWebRtcInterfaceAsHandler(i),this.selfPtr=await this.runAsync((r=>this.api.lib.StreamApi_newStreamApi(r,e,t,i))),this.selfPtr}async deleteApi(e){await this.runAsync((t=>this.api.lib.StreamApi_deleteStreamApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.StreamApi_create(i,e,t)))}async createStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_createStreamRoom(i,e,t)))}async updateStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_updateStreamRoom(i,e,t)))}async deleteStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_deleteStreamRoom(i,e,t)))}async getStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_getStreamRoom(i,e,t)))}async listStreamRooms(e,t){return this.runAsync((i=>this.api.lib.StreamApi_listStreamRooms(i,e,t)))}async createStream(e,t){return this.runAsync((i=>this.api.lib.StreamApi_createStream(i,e,t)))}async joinStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_joinStreamRoom(i,e,t)))}async leaveStreamRoom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_leaveStreamRoom(i,e,t)))}async enableStreamRoomRecording(e,t){return this.runAsync((i=>this.api.lib.StreamApi_enableStreamRoomRecording(i,e,t)))}async getStreamRoomRecordingKeys(e,t){return this.runAsync((i=>this.api.lib.StreamApi_getStreamRoomRecordingKeys(i,e,t)))}async publishStream(e,t){return await this.runAsync((i=>this.api.lib.StreamApi_publishStream(i,e,t)))}async updateStream(e,t){return await this.runAsync((i=>this.api.lib.StreamApi_updateStream(i,e,t)))}async unpublishStream(e,t){return this.runAsync((i=>this.api.lib.StreamApi_unpublishStream(i,e,t)))}async listStreams(e,t){return this.runAsync((i=>this.api.lib.StreamApi_listStreams(i,e,t)))}async subscribeToRemoteStreams(e,t){return this.runAsync((i=>this.api.lib.StreamApi_subscribeToRemoteStreams(i,e,t)))}async modifyRemoteStreamsSubscriptions(e,t){return this.runAsync((i=>this.api.lib.StreamApi_modifyRemoteStreamsSubscriptions(i,e,t)))}async unsubscribeFromRemoteStreams(e,t){return this.runAsync((i=>this.api.lib.StreamApi_unsubscribeFromRemoteStreams(i,e,t)))}async keyManagement(e,t){return this.runAsync((i=>this.api.lib.StreamApi_keyManagement(i,e,t)))}async getTurnCredentials(e,t){return this.runAsync((i=>this.api.lib.StreamApi_getTurnCredentials(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.StreamApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.StreamApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.StreamApi_buildSubscriptionQuery(i,e,t)))}async trickle(e,t){const[i,r]=t,n=[i,JSON.stringify(r)];return this.runAsync((t=>this.api.lib.StreamApi_trickle(t,e,n)))}async acceptOfferOnReconfigure(e,t){return this.runAsync((i=>this.api.lib.StreamApi_acceptOfferOnReconfigure(i,e,t)))}async setNewOfferOnReconfigure(e,t){return this.runAsync((i=>this.api.lib.StreamApi_setNewOfferOnReconfigure(i,e,t)))}bindWebRtcInterfaceAsHandler(e){this.webRtcInterfaceImpl=new r.WebRtcInterfaceImpl(this.webRtcClient);let t=window.webRtcInterfaceToNativeHandler;t||(t={}),t[e]=this.webRtcInterfaceImpl,window.webRtcInterfaceToNativeHandler=t}}t.StreamApiNative=s},272:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApiNative=void 0;const r=i(361);class n extends r.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.ThreadApi_newThreadApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.ThreadApi_deleteThreadApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_create(i,e,t)))}async createThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_createThread(i,e,t)))}async updateThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateThread(i,e,t)))}async deleteThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteThread(i,e,t)))}async getThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getThread(i,e,t)))}async listThreads(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listThreads(i,e,t)))}async getMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getMessage(i,e,t)))}async listMessages(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listMessages(i,e,t)))}async sendMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_sendMessage(i,e,t)))}async deleteMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteMessage(i,e,t)))}async updateMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateMessage(i,e,t)))}async subscribeFor(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeFor(i,e,t)))}async unsubscribeFrom(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFrom(i,e,t)))}async buildSubscriptionQuery(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_buildSubscriptionQuery(i,e,t)))}}t.ThreadApiNative=n},647:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApi=void 0,t.BaseApi=class{_servicePtr;constructor(e){this._servicePtr=e}get servicePtr(){if(this._servicePtr<0)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._servicePtr}destroyRefs(){this._servicePtr=-1}}},262:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const r=i(647);class n extends r.BaseApi{native;apisRefs={};nativeApisDeps={};constructor(e,t){super(t),this.native=e}async getConnectionId(){return this.native.getConnectionId(this.servicePtr,[])}async listContexts(e){return this.native.listContexts(this.servicePtr,[e])}async listContextUsers(e,t){return this.native.listContextUsers(this.servicePtr,[e,t])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}async disconnect(){await this.native.disconnect(this.servicePtr,[]),await this.freeApis(),await this.native.deleteConnection(this.servicePtr)}setUserVerifier(e){return this.native.setUserVerifier(this.servicePtr,[this.servicePtr,e])}async freeApis(){console.warn("freeApis disabled for debugging purposes. Please re-enable")}}t.Connection=n},11:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async signData(e,t){return this.native.signData(this.servicePtr,[e,t])}async verifySignature(e,t,i){return this.native.verifySignature(this.servicePtr,[e,t,i])}async generatePrivateKey(e){return this.native.generatePrivateKey(this.servicePtr,[e])}async derivePrivateKey(e,t){return this.native.derivePrivateKey(this.servicePtr,[e,t])}async derivePrivateKey2(e,t){return this.native.derivePrivateKey2(this.servicePtr,[e,t])}async derivePublicKey(e){return this.native.derivePublicKey(this.servicePtr,[e])}async generateKeySymmetric(){return this.native.generateKeySymmetric(this.servicePtr,[])}async encryptDataSymmetric(e,t){return this.native.encryptDataSymmetric(this.servicePtr,[e,t])}async decryptDataSymmetric(e,t){return this.native.decryptDataSymmetric(this.servicePtr,[e,t])}async convertPEMKeytoWIFKey(e){return this.native.convertPEMKeytoWIFKey(this.servicePtr,[e])}async generateBip39(e,t=""){return this.native.generateBip39(this.servicePtr,[e,t])}async fromMnemonic(e,t=""){return this.native.fromMnemonic(this.servicePtr,[e,t])}async fromEntropy(e,t=""){return this.native.fromEntropy(this.servicePtr,[e,t])}async entropyToMnemonic(e){return this.native.entropyToMnemonic(this.servicePtr,[e])}async mnemonicToEntropy(e){return this.native.mnemonicToEntropy(this.servicePtr,[e])}async mnemonicToSeed(e,t=""){return this.native.mnemonicToSeed(this.servicePtr,[e,t])}}t.CryptoApi=n},181:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EndpointFactory=void 0;const r=i(667),n=i(457),s=i(140),a=i(711),o=i(688),c=i(467),u=i(252),h=i(453),l=i(243),p=i(620),d=i(272),y=i(54),f=i(934),b=i(262),v=i(11),g=i(590),m=i(297),A=i(134),w=i(789),S=i(985),E=i(372),P=i(148);class _{static api;static eventQueueInstance;static assetsBasePath;static async setup(e){const t=e||document.currentScript.src.split("/").slice(0,-1).join("/");this.assetsBasePath=t;const i=["driver-web-context.js","endpoint-wasm-module.js"];for(const e of i)await this.loadScript(t+"/"+e);const r=await endpointWasmModule();_.init(r)}static async loadScript(e){return new Promise((t=>{const i=document.getElementsByTagName("head")[0],r=document.createElement("script");r.type="text/javascript",r.src=e,r.onload=()=>{t()},i.appendChild(r)}))}static init(e){this.api=new r.Api(e),n.ApiStatic.init(this.api),y.FinalizationHelper.init(e)}static async getEventQueue(){if(!this.eventQueueInstance){const e=new c.EventQueueNative(this.api),t=await e.newEventQueue();this.eventQueueInstance=new m.EventQueue(e,t)}return this.eventQueueInstance}static generateDefaultPKIVerificationOptions(){return{bridgeInstanceId:void 0,bridgePubKey:void 0}}static async connect(e,t,i,r){const n=new s.ConnectionNative(this.api),a=await n.newConnection();return await n.connect(a,[e,t,i,r||this.generateDefaultPKIVerificationOptions()]),new b.Connection(n,a)}static async connectPublic(e,t,i){const r=new s.ConnectionNative(this.api),n=await r.newConnection();return await r.connectPublic(n,[e,t,i||this.generateDefaultPKIVerificationOptions()]),new b.Connection(r,n)}static async createThreadApi(e){if("threads"in e.apisRefs)throw new Error("ThreadApi already registered for given connection.");const t=new d.ThreadApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.threads={_apiServicePtr:i},e.nativeApisDeps.threads=t,new P.ThreadApi(t,i)}static async createStoreApi(e){if("stores"in e.apisRefs)throw new Error("StoreApi already registered for given connection.");const t=new l.StoreApiNative(this.api),i=await t.newApi(e.servicePtr);return e.apisRefs.stores={_apiServicePtr:i},e.nativeApisDeps.stores=t,await t.create(i,[]),new S.StoreApi(t,i)}static async createInboxApi(e,t,i){if("inboxes"in e.apisRefs)throw new Error("InboxApi already registered for given connection.");const r=new u.InboxApiNative(this.api),n=await r.newApi(e.servicePtr,t.servicePtr,i.servicePtr);return await r.create(n,[]),e.apisRefs.inboxes={_apiServicePtr:n},e.nativeApisDeps.inboxes=r,new A.InboxApi(r,n)}static async createKvdbApi(e){if("kvdbs"in e.apisRefs)throw new Error("KvdbApi already registered for given connection.");const t=new h.KvdbApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.kvdbs={_apiServicePtr:i},e.nativeApisDeps.kvdbs=t,new w.KvdbApi(t,i)}static async createCryptoApi(){const e=new a.CryptoApiNative(this.api),t=await e.newApi();return await e.create(t,[]),new v.CryptoApi(e,t)}static async createEventApi(e){if("events"in e.apisRefs)throw new Error("EventApi already registered for given connection.");const t=new o.EventApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.events={_apiServicePtr:i},e.nativeApisDeps.events=t,new g.EventApi(t,i)}static async createStreamApi(e,t){if("streams"in e.apisRefs)throw new Error("StreamApi already registered for given connection.");const i=new f.WebRtcClient(this.assetsBasePath),r=new p.StreamApiNative(this.api,i),n=await r.newApi(e.servicePtr,t.servicePtr);return await r.create(n,[]),e.apisRefs.streams={_apiServicePtr:n},e.nativeApisDeps.streams=r,new E.StreamApi(r,n,i)}}t.EndpointFactory=_},590:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EventApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async emitEvent(e,t,i,r){return this.native.emitEvent(this.servicePtr,[e,t,i,r])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}}t.EventApi=n},641:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StateChangeDispatcher=void 0,t.StateChangeDispatcher=class{listeners=new Set;addOnStateChangeListener(e,t){const i={filter:e,listener:t};this.listeners.add(i)}removeOnStateChangeListener(e){for(const t of this.listeners.values())t.filter===e&&this.listeners.delete(t)}emit(e){for(const{filter:t,listener:i}of this.listeners)t.streamHandle===e.streamHandle&&i(e)}}},297:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueue=void 0;const r=i(647);class n extends r.BaseApi{native;deferedPromise;constructor(e,t){super(t),this.native=e}async waitEvent(){return this.deferedPromise||(this.deferedPromise=this.native.waitEvent(this.servicePtr,[]),this.deferedPromise.finally((()=>this.deferedPromise=null))),this.deferedPromise}async emitBreakEvent(){return this.native.emitBreakEvent(this.servicePtr,[])}}t.EventQueue=n},504:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ExtKey=void 0;const r=i(457),n=i(614),s=i(54),a=i(647);class o extends a.BaseApi{native;ptr;static async freeExtKey(e){const t=new n.ExtKeyNative(r.ApiStatic.getInstance());await t.deleteExtKey(e)}static async fromSeed(e){const t=await n.ExtKeyNative.fromSeed([e]),i=new n.ExtKeyNative(r.ApiStatic.getInstance()),a=new o(i,t);return s.FinalizationHelper.getInstance().register(a,{ptr:t,onFree:()=>this.freeExtKey(t)}),a}static async fromBase58(e){const t=await n.ExtKeyNative.fromBase58([e]),i=new n.ExtKeyNative(r.ApiStatic.getInstance()),a=new o(i,t);return s.FinalizationHelper.getInstance().register(a,{ptr:t,onFree:()=>this.freeExtKey(t)}),a}static async generateRandom(){const e=await n.ExtKeyNative.generateRandom([]),t=new n.ExtKeyNative(r.ApiStatic.getInstance()),i=new o(t,e);return s.FinalizationHelper.getInstance().register(i,{ptr:e,onFree:()=>this.freeExtKey(e)}),i}constructor(e,t){super(t),this.native=e,this.ptr=t}static fromPtr(e){const t=new n.ExtKeyNative(r.ApiStatic.getInstance());return new o(t,e)}async derive(e){const t=await this.native.derive(this.servicePtr,[e]),i=new o(this.native,t);return s.FinalizationHelper.getInstance().register(i,{ptr:t,onFree:()=>o.freeExtKey(t)}),i}async deriveHardened(e){const t=await this.native.deriveHardened(this.servicePtr,[e]);return new o(this.native,t)}async getPrivatePartAsBase58(){return this.native.getPrivatePartAsBase58(this.servicePtr,[])}async getPublicPartAsBase58(){return this.native.getPublicPartAsBase58(this.servicePtr,[])}async getPrivateKey(){return this.native.getPrivateKey(this.servicePtr,[])}async getPublicKey(){return this.native.getPublicKey(this.servicePtr,[])}async getPrivateEncKey(){return this.native.getPrivateEncKey(this.servicePtr,[])}async getPublicKeyAsBase58Address(){return this.native.getPublicKeyAsBase58Address(this.servicePtr,[])}async getChainCode(){return this.native.getChainCode(this.servicePtr,[])}async verifyCompactSignatureWithHash(e,t){return this.native.verifyCompactSignatureWithHash(this.servicePtr,[e,t])}async isPrivate(){return this.native.isPrivate(this.servicePtr,[])}}t.ExtKey=o},134:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async createInbox(e,t,i,r,n,s,a){return this.native.createInbox(this.servicePtr,[e,t,i,r,n,s,a])}async updateInbox(e,t,i,r,n,s,a,o,c,u){return this.native.updateInbox(this.servicePtr,[e,t,i,r,n,s,a,o,c,u])}async getInbox(e){return this.native.getInbox(this.servicePtr,[e])}async listInboxes(e,t){return this.native.listInboxes(this.servicePtr,[e,t])}async getInboxPublicView(e){return this.native.getInboxPublicView(this.servicePtr,[e])}async deleteInbox(e){return this.native.deleteInbox(this.servicePtr,[e])}async prepareEntry(e,t,i,r){return this.native.prepareEntry(this.servicePtr,[e,t,i,r])}async sendEntry(e){return this.native.sendEntry(this.servicePtr,[e])}async readEntry(e){return this.native.readEntry(this.servicePtr,[e])}async listEntries(e,t){return this.native.listEntries(this.servicePtr,[e,t])}async deleteEntry(e){return this.native.deleteEntry(this.servicePtr,[e])}async createFileHandle(e,t,i){return this.native.createFileHandle(this.servicePtr,[e,t,i])}async writeToFile(e,t,i){return this.native.writeToFile(this.servicePtr,[e,t,i])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}}t.InboxApi=n},789:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KvdbApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async createKvdb(e,t,i,r,n,s){return this.native.createKvdb(this.servicePtr,[e,t,i,r,n,s])}async updateKvdb(e,t,i,r,n,s,a,o,c){return this.native.updateKvdb(this.servicePtr,[e,t,i,r,n,s,a,o,c])}async deleteKvdb(e){return this.native.deleteKvdb(this.servicePtr,[e])}async getKvdb(e){return this.native.getKvdb(this.servicePtr,[e])}async listKvdbs(e,t){return this.native.listKvdbs(this.servicePtr,[e,t])}async getEntry(e,t){return this.native.getEntry(this.servicePtr,[e,t])}async hasEntry(e,t){return this.native.hasEntry(this.servicePtr,[e,t])}async listEntriesKeys(e,t){return this.native.listEntriesKeys(this.servicePtr,[e,t])}async listEntries(e,t){return this.native.listEntries(this.servicePtr,[e,t])}async setEntry(e,t,i,r,n,s){return this.native.setEntry(this.servicePtr,[e,t,i,r,n,s||0])}async deleteEntry(e,t){return this.native.deleteEntry(this.servicePtr,[e,t])}async deleteEntries(e,t){return this.native.deleteEntries(this.servicePtr,[e,t])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}async buildSubscriptionQueryForSelectedEntry(e,t,i){return this.native.buildSubscriptionQueryForSelectedEntry(this.servicePtr,[e,t,i])}}t.KvdbApi=n},985:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async createStore(e,t,i,r,n,s){return this.native.createStore(this.servicePtr,[e,t,i,r,n,s])}async updateStore(e,t,i,r,n,s,a,o,c){return this.native.updateStore(this.servicePtr,[e,t,i,r,n,s,a,o,c])}async deleteStore(e){return this.native.deleteStore(this.servicePtr,[e])}async getStore(e){return this.native.getStore(this.servicePtr,[e])}async listStores(e,t){return this.native.listStores(this.servicePtr,[e,t])}async createFile(e,t,i,r,n=!1){return this.native.createFile(this.servicePtr,[e,t,i,r,n])}async updateFile(e,t,i,r){return this.native.updateFile(this.servicePtr,[e,t,i,r])}async updateFileMeta(e,t,i){return this.native.updateFileMeta(this.servicePtr,[e,t,i])}async writeToFile(e,t,i=!1){return this.native.writeToFile(this.servicePtr,[e,t,i])}async deleteFile(e){return this.native.deleteFile(this.servicePtr,[e])}async getFile(e){return this.native.getFile(this.servicePtr,[e])}async listFiles(e,t){return this.native.listFiles(this.servicePtr,[e,t])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async syncFile(e){return this.native.syncFile(this.servicePtr,[e])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}}t.StoreApi=n},372:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.StreamApi=void 0;const r=i(251),n=i(647);class s extends n.BaseApi{native;client;constructor(e,t,i){super(t),this.native=e,this.client=i}streams=new Map;streamTracks=new Map;async createStreamRoom(e,t,i,r,n,s){return await this.native.createStreamRoom(this.servicePtr,[e,t,i,r,n,s])}async updateStreamRoom(e,t,i,r,n,s,a,o,c){return this.native.updateStreamRoom(this.servicePtr,[e,t,i,r,n,s,a,o,c])}async listStreamRooms(e,t){return this.native.listStreamRooms(this.servicePtr,[e,t])}async joinStreamRoom(e){return this.native.joinStreamRoom(this.servicePtr,[e])}async leaveStreamRoom(e){return this.native.leaveStreamRoom(this.servicePtr,[e])}async enableStreamRoomRecording(e){return this.native.enableStreamRoomRecording(this.servicePtr,[e])}async getStreamRoomRecordingKeys(e){return this.native.getStreamRoomRecordingKeys(this.servicePtr,[e])}async getStreamRoom(e){return this.native.getStreamRoom(this.servicePtr,[e])}async deleteStreamRoom(e){return this.native.deleteStreamRoom(this.servicePtr,[e])}async createStream(e){const t=await this.native.createStream(this.servicePtr,[e]);return this.streams.set(t,{handle:t,streamRoomId:e,createStreamMeta:{},remote:!1}),t}async listStreams(e){return await this.native.listStreams(this.servicePtr,[e])}async addStreamTrack(e,t){if(!this.streams.has(e))throw new Error("[addStreamTrack]: there is no Stream with given Id: "+e);let i="";const n=Array.from(this.streamTracks.values()).filter((t=>t.streamHandle===e));for(const e of n)if(e.track&&e.track?.id===t.track?.id){if(!0===e.markedToRemove){e.markedToRemove,i=e.id;break}throw new Error("[addStreamTrack] StreamTrack with given browser's track already added.")}if(i.length>0)return i;if(!this.streams.get(e))throw new Error("Cannot find stream by id");const s=r.Utils.getRandomString(16),a={id:s,streamHandle:e,track:t.track,dataChannelMeta:t.dataChannel,published:!1};return this.streamTracks.set(s,a),s}async removeStreamTrack(e,t){if(!this.streams.has(e))throw new Error("[removeStreamTrack]: there is no Stream with given Id: "+e);for(const[i,r]of this.streamTracks.entries())r.track&&r.track?.id===t.track?.id&&r.streamHandle===e&&(r.markedToRemove=!0)}async streamTrackSendData(e,t){throw new Error("not implemented")}async streamTrackRecvData(e,t){throw new Error("not implemented")}async publishStream(e,t){const i=[];for(const t of this.streamTracks.values())t.streamHandle===e&&t.track&&!t.markedToRemove&&!1===t.published&&(i.push(t.track),t.published=!0);const r=this.streams.get(e);if(!r)throw new Error("No stream defined to publish");const n=new MediaStream(i);r.localMediaStream=n;const s=await this.native.getTurnCredentials(this.servicePtr,[]);return await this.client.setTurnCredentials(s),await this.client.createPeerConnectionWithLocalStream(e,r.streamRoomId,n),t&&"function"==typeof t&&this.client.getStreamStateChangeDispatcher().addOnStateChangeListener({streamHandle:e},(e=>t(e.state))),await this.native.publishStream(this.servicePtr,[e])}async updateStream(e){const t=[],i=[];for(const r of this.streamTracks.values())r.streamHandle===e&&r.track&&(r.published||r.markedToRemove||t.push(r.track),r.markedToRemove&&i.push(r.track));const r=this.streams.get(e);if(!r)throw new Error("No stream defined to publish");const n=await this.native.getTurnCredentials(this.servicePtr,[]);return await this.client.setTurnCredentials(n),await this.client.updatePeerConnectionWithLocalStream(r.streamRoomId,r.localMediaStream,t,i),await this.native.updateStream(this.servicePtr,[e])}filterMapByValue(e,t){const i=new Map;for(const[r,n]of e)t(n,r)&&i.set(r,n);return i}async unpublishStream(e){if(!this.streams.has(e))throw new Error("No local stream with given id to unpublish");const t=this.streams.get(e),i=this.filterMapByValue(this.streamTracks,(t=>t.streamHandle!==e));this.streamTracks=i,await this.native.unpublishStream(this.servicePtr,[e]),this.client.removeSenderPeerConnectionOnUnpublish(t.streamRoomId,t.localMediaStream),this.streams.delete(e),this.client.getStreamStateChangeDispatcher().removeOnStateChangeListener({streamHandle:e})}async subscribeToRemoteStreams(e,t){const i=await this.native.getTurnCredentials(this.servicePtr,[]);await this.client.setTurnCredentials(i),await this.native.subscribeToRemoteStreams(this.servicePtr,[e,t]),this.client.getConnectionManager().initialize(e,"subscriber")}async modifyRemoteStreamsSubscriptions(e,t,i){await this.native.modifyRemoteStreamsSubscriptions(this.servicePtr,[e,t,i])}async unsubscribeFromRemoteStreams(e,t){await this.native.unsubscribeFromRemoteStreams(this.servicePtr,[e,t])}addRemoteStreamListener(e){this.client.addRemoteStreamListener(e)}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}async addAudioLevelStatsListener(e){e&&"function"==typeof e&&this.client.setAudioLevelCallback(e)}}t.StreamApi=s},148:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApi=void 0;const r=i(647);class n extends r.BaseApi{native;constructor(e,t){super(t),this.native=e}async createThread(e,t,i,r,n,s){return this.native.createThread(this.servicePtr,[e,t,i,r,n,s])}async updateThread(e,t,i,r,n,s,a,o,c){return this.native.updateThread(this.servicePtr,[e,t,i,r,n,s,a,o,c])}async deleteThread(e){return this.native.deleteThread(this.servicePtr,[e])}async getThread(e){return this.native.getThread(this.servicePtr,[e])}async listThreads(e,t){return this.native.listThreads(this.servicePtr,[e,t])}async getMessage(e){return this.native.getMessage(this.servicePtr,[e])}async listMessages(e,t){return this.native.listMessages(this.servicePtr,[e,t])}async sendMessage(e,t,i,r){return this.native.sendMessage(this.servicePtr,[e,t,i,r])}async deleteMessage(e){return this.native.deleteMessage(this.servicePtr,[e])}async updateMessage(e,t,i,r){return this.native.updateMessage(this.servicePtr,[e,t,i,r])}async subscribeFor(e){return this.native.subscribeFor(this.servicePtr,[e])}async unsubscribeFrom(e){return this.native.unsubscribeFrom(this.servicePtr,[e])}async buildSubscriptionQuery(e,t,i){return this.native.buildSubscriptionQuery(this.servicePtr,[e,t,i])}}t.ThreadApi=n},928:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KeyStore=void 0,t.KeyStore=class{_keys=new Map;_encryptionKeyId=void 0;setKeys(e){this._keys.clear();for(const t of e)this._keys.set(t.keyId,t),0===t.type&&(this._encryptionKeyId=t.keyId)}getKey(e){return this._keys.get(e)}hasKey(e){return this._keys.has(e)}getEncriptionKey(){if(!this._encryptionKeyId)throw new Error("No encryption key set.");return this._keys.get(this._encryptionKeyId)}}},144:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Logger=void 0;class i{static instance;static logLevel="important-only";static get(){return this.instance||(this.instance=new i),this.instance}log(e,...t){("debug"===i.logLevel||"info"===e&&"info"===i.logLevel||"important-only"===e&&"important-only"===i.logLevel)&&console.log(...t)}}t.Logger=i},796:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PeerConnectionManager=void 0,t.PeerConnectionManager=class{createPeerConnection;onTrickle;connections={};constructor(e,t){this.createPeerConnection=e,this.onTrickle=t}initialize(e,t,i=-1){if(e in this.connections&&t in this.connections[e]&&this.connections[e][t]?.pc)return;e in this.connections||(this.connections[e]={});const r=this.createPeerConnection(e),n={sessionId:i,hasSubscriptions:!1,pc:r,candidateQueue:[]};this.connections[e][t]=n,r.addEventListener("icecandidate",(i=>{if(!i.candidate)return;const r=this.connections[e][t];if(!r)return;const n=r.sessionId;if(n&&n>-1)try{this.onTrickle(n,i.candidate)}catch(e){console.warn("Failed to trickle candidate",e)}else r.candidateQueue.push(i.candidate)}))}updateSessionForConnection(e,t,i){e in this.connections&&t in this.connections[e]||this.initialize(e,t);const r=this.connections[e][t];r.sessionId=i,r.candidateQueue.length>0&&(r.candidateQueue.forEach((e=>{try{this.onTrickle(i,e)}catch(e){console.warn("Failed to trickle buffered candidate",e)}})),r.candidateQueue=[])}hasConnection(e,t){return!(!this.connections[e]||!this.connections[e][t])}getConnectionWithSession(e,t){return this.hasConnection(e,t)||this.initialize(e,t),this.connections[e][t]}closePeerConnectionBySessionIfExists(e,t){if(this.hasConnection(e,t)){const i=this.connections[e][t];i?.pc&&i.pc.close(),delete this.connections[e][t]}}}},621:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Queue=void 0;class i{items=[];func;processing=!1;enqueue(e){this.items.push(e)}dequeue(){return this.items.shift()}peek(){return this.items[0]}get size(){return this.items.length}isEmpty(){return 0===this.items.length}clear(){this.items.length=0}toArray(){return this.items.slice()}assignProcessorFunc(e){this.func=e}async processAll(){if(!this.processing){if(!this.func)throw new Error("No task processor function assigned");for(this.processing=!0;this.items.length>0;){const e=this.items.shift();if(!e)continue;const t=Math.random();try{await this.func(e),await this.awaiter()}catch(e){console.error("Error while processing queue item",t,e)}}this.processing=!1}}async awaiter(){return new Promise((e=>setTimeout((()=>e()),5e3)))}[Symbol.iterator](){let e=0;const t=this.items;return{next:()=>e<t.length?{value:t[e++],done:!1}:{value:void 0,done:!0}}}}t.Queue=i},251:(e,t,i)=>{"use strict";var r=i(287).hp;Object.defineProperty(t,"__esModule",{value:!0}),t.Utils=void 0;class n{static generateNumericId(){return Math.round(1e15*Math.random())}static getRandomString(e){return[...Array(e)].map((()=>Math.floor(16*Math.random()).toString(16))).join("")}static async encryptSymmetric(e,t,i){let n;n="string"==typeof e?(new TextEncoder).encode(e):e;const s=await crypto.subtle.importKey("raw",r.from(t,"base64"),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:r.from(i,"base64")},s,n);return{ciphertext:r.from(a),iv:i}}static async decryptSymmetricBuffer(e,t,i){const n=await crypto.subtle.importKey("raw",i,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},n,e);return r.from(s)}static async decryptSymmetric(e,t,i){const n=await crypto.subtle.importKey("raw",r.from(i,"base64"),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:r.from(t,"base64")},n,r.from(e,"base64"));return(new TextDecoder).decode(s)}static genKey(){return r.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}static genIv(){return r.from(crypto.getRandomValues(new Uint8Array(12))).toString("base64")}static genIvAsBuffer(){return crypto.getRandomValues(new Uint8Array(12))}static base64abc=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"];static base64codes=[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,62,255,255,255,63,52,53,54,55,56,57,58,59,60,61,255,255,255,0,255,255,255,0,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,255,255,255,255,255,255,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];static bytesToBase64(e){let t,i="",r=e.length;for(t=2;t<r;t+=3)i+=n.base64abc[e[t-2]>>2],i+=n.base64abc[(3&e[t-2])<<4|e[t-1]>>4],i+=n.base64abc[(15&e[t-1])<<2|e[t]>>6],i+=n.base64abc[63&e[t]];return t===r+1&&(i+=n.base64abc[e[t-2]>>2],i+=n.base64abc[(3&e[t-2])<<4],i+="=="),t===r&&(i+=n.base64abc[e[t-2]>>2],i+=n.base64abc[(3&e[t-2])<<4|e[t-1]>>4],i+=n.base64abc[(15&e[t-1])<<2],i+="="),i}static isBitOn(e,t){return Boolean(e&1<<t)}static getBits(e,t,i){const r=Math.pow(2,i)-1,n=t/8,s=t%=8;return e[n]>>s&r}static numAsOneByteUint(e){if(e>255)throw new Error("Out of bounds value");const t=new Uint8Array(1);return t[0]=e,t}static oneByteUint8AsNum(e){if(e[0]>255)throw new Error("Out of bounds value");return e[0]}}t.Utils=n},934:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebRtcClient=void 0;const r=i(578),n=i(439),s=i(928),a=i(796),o=i(144),c=i(621),u=i(247),h=i(474),l=i(641);t.WebRtcClient=class{assetsDir;uniqId;e2eeWorker;webWorkerApi;dataChannels=[];configuration;keyStore=new s.KeyStore;publishStreamHandle;peerCredentials;remoteStreamsListeners=new Map;peerConnectionsManager;streamsApiInterface;activeSpeakerDetector;audioLevelCallback;encByReceiver=new WeakMap;logger=o.Logger.get();peerConnectionReconfigureQueue;lastProcessedAnswer={};lastMeasuredLocalRMS=-99;eventsDispatcher=new l.StateChangeDispatcher;localAudioLevelMeters=new Map;constructor(e){this.assetsDir=e,this.uniqId=Math.random()+"-"+Math.random(),this.peerConnectionsManager=new a.PeerConnectionManager((e=>this.createPeerConnectionMultiForRoom(e,this.getPeerConnectionConfiguration())),((e,t)=>this.streamsApiInterface.trickle(e,t))),this.peerConnectionReconfigureQueue=new c.Queue,this.peerConnectionReconfigureQueue.assignProcessorFunc((async e=>{await this.reconfigureSingle(e._room,e.offer)})),this.activeSpeakerDetector=new h.ActiveSpeakerDetector(h.DEFAULTS)}async ensureLocalAudioLevelMeter(e){if(this.localAudioLevelMeters.has(e.id))return;const t=await this.getWorker(),i=new u.LocalAudioLevelMeter(e,(e=>{t.postMessage({operation:"rms",rms:e}),this.lastMeasuredLocalRMS=e}));this.localAudioLevelMeters.set(e.id,i);try{await i.init(this.assetsDir+"/rms-processor.js")}catch(t){throw this.localAudioLevelMeters.delete(e.id),i.stop(),t}}stopLocalAudioLevelMeter(e){const t=this.localAudioLevelMeters.get(e.id);t&&(this.localAudioLevelMeters.delete(e.id),t.stop())}setAudioLevelCallback(e){this.audioLevelCallback=e}bindApiInterface(e){this.streamsApiInterface=e}addRemoteStreamListener(e){let t=this.remoteStreamsListeners.get(e.streamRoomId)||[];if(t.find((t=>t.streamId===e.streamId)))throw new Error("RemoteStreamListener with given params already exists.");t.push(e),this.remoteStreamsListeners.set(e.streamRoomId,t)}getStreamStateChangeDispatcher(){return this.eventsDispatcher}getConnectionManager(){if(!this.peerConnectionsManager)throw new Error("No peerConnectionManager initialized.");return this.peerConnectionsManager}getWebRtcEventDispatcher(){return this.eventsDispatcher}getEncKey(){return this.keyStore.getEncriptionKey()}async getWorker(){if(!this.e2eeWorker){const e=await this.getWorkerApi();this.e2eeWorker=e.getWorker()}if(!this.e2eeWorker)throw new Error("Worker not initialized.");return this.e2eeWorker}async initPipeline(e,t){const i=await this.getWorker();return new Promise((r=>{const n=t=>{"init-pipeline"===t.data.operation&&t.data.id===e&&(i.removeEventListener("message",n),r())};i.addEventListener("message",n),i.postMessage({operation:"init-pipeline",id:e,publisherId:t})}))}async getWorkerApi(){return this.webWorkerApi||(this.webWorkerApi=new r.WebWorker(this.assetsDir,(e=>{if(this.audioLevelCallback&&"function"==typeof this.audioLevelCallback){this.activeSpeakerDetector.onFrame({id:0,rms:this.lastMeasuredLocalRMS,timestamp:Date.now()});const t=this.activeSpeakerDetector.onFrame({id:e.publisherId,rms:e.rms,timestamp:Date.now()});this.audioLevelCallback({levels:t})}})),await this.webWorkerApi.init_e2ee()),this.webWorkerApi}getPeerConnectionConfiguration(){return this.configuration||(this.configuration=n.WebRtcConfig.generateTurnConfiguration(this.peerCredentials)),this.configuration}async setTurnCredentials(e){this.peerCredentials=e}async createPeerConnectionWithLocalStream(e,t,i){this.publishStreamHandle=e,this.configuration=n.WebRtcConfig.generateTurnConfiguration(this.peerCredentials),this.getConnectionManager().initialize(t,"publisher");const r=this.getConnectionManager().getConnectionWithSession(t,"publisher").pc;if(i.getTracks().length>0){const e=i.getTracks();this.e2eeWorker=await this.getWorker();for(const t of e){"audio"===t.kind&&await this.ensureLocalAudioLevelMeter(t);const e=r.addTrack(t,i);this.setupSenderTransform(e)}}return r}removeSenderPeerConnectionOnUnpublish(e,t){const i=this.getConnectionManager().getConnectionWithSession(e,"publisher");for(const e of t.getAudioTracks())this.stopLocalAudioLevelMeter(e);i.pc.close(),i.pc=void 0}async updatePeerConnectionWithLocalStream(e,t,i,r){this.configuration=n.WebRtcConfig.generateTurnConfiguration(this.peerCredentials),this.getConnectionManager().initialize(e,"publisher");const s=this.getConnectionManager().getConnectionWithSession(e,"publisher").pc;if(i.length>0){this.e2eeWorker=await this.getWorker();for(const e of i){"audio"===e.kind&&await this.ensureLocalAudioLevelMeter(e);const i=s.addTrack(e,t);if(window.RTCRtpScriptTransform){const e={operation:"encode"};i.transform=new RTCRtpScriptTransform(this.e2eeWorker,e)}else{const e=i.createEncodedStreams();this.e2eeWorker.postMessage({operation:"encode",readableStream:e.readable,writableStream:e.writable},[e.readable,e.writable])}}}if(r.length>0){const e=s.getSenders();for(const t of r){"audio"===t.kind&&this.stopLocalAudioLevelMeter(t);const i=e.find((e=>e.track===t));i&&s.removeTrack(i)}}return s}createPeerConnectionMultiForRoom(e,t,i,r){const n=t;n.encodedInsertableStreams=!0;const s=new RTCPeerConnection(n);return s.addEventListener("icegatheringstatechange",(e=>{this.logger.log("info","on ice state change: ",e)})),s.addEventListener("icecandidateerror",(e=>{this.logger.log("info","on ice error: ",e)})),s.addEventListener("connectionstatechange",(e=>{this.logger.log("info","connectionstatechange: ",e),"connected"===s.connectionState?this.logger.log("important-only","Peers connected!"):this.logger.log("info","connection state: ",s.connectionState),this.eventsDispatcher.emit({streamHandle:this.publishStreamHandle,state:s.connectionState})})),s.addEventListener("iceconnectionstatechange",(e=>{this.logger.log("info","iceconnectionstatechange: ",e)})),s.addEventListener("negotiationneeded",(async e=>{this.logger.log("info","negotiationneeded: ",e)})),s.addEventListener("signalingstatechange",(e=>{this.logger.log("info","signalingstatechange: ",e)})),s.addEventListener("track",(async t=>{await this.addRemoteTrack(e,t)})),s}async updateKeys(e,t){this.keyStore.setKeys(t),(await this.getWorkerApi()).setKeys(t)}setupSenderTransform(e){if(window.RTCRtpScriptTransform){const t={operation:"encode"};e.transform=new RTCRtpScriptTransform(this.e2eeWorker,t)}else{this.logger.log("important-only","Worker - encoding frames using EncodedStreams");const t=e.createEncodedStreams();this.e2eeWorker.postMessage({operation:"encode",readableStream:t.readable,writableStream:t.writable},[t.readable,t.writable])}}async setupReceiverTransform(e,t,i){if(!("RTCRtpScriptTransform"in window)||e.transform)if(this.logger.log("important-only","-> using EncodedStreams"),!this.encByReceiver.has(e)&&"createEncodedStreams"in e&&"function"==typeof e.createEncodedStreams){this.logger.log("important-only","-> call for createEncodedStreams()");const{readable:r,writable:n}=await e.createEncodedStreams(),s={readable:r,writable:n,id:e.track.id,publisherId:t,posted:!1};this.encByReceiver.set(e,s),this.logger.log("important-only","-> posting EncodedStreams to worker (should happen only once)"),await this.initPipeline(s.id,s.publisherId),i.postMessage({operation:"decode",id:s.id,publisherId:s.publisherId,readableStream:s.readable,writableStream:s.writable},[s.readable,s.writable])}else this.logger.log("important-only","-> EncodedStreams posted to worker already.");else{this.logger.log("important-only","-> using RtpScriptTransform");const r=e.track.id;e.transform=new window.RTCRtpScriptTransform(i,{operation:"decode",id:r,publisherId:t})}}async waitUntilConnected(e){return"connected"===e.iceConnectionState||"completed"===e.iceConnectionState?Promise.resolve():new Promise(((t,i)=>{const r=()=>{"connected"===e.iceConnectionState||"completed"===e.iceConnectionState?t():"failed"!==e.iceConnectionState&&"failed"!==e.connectionState&&"closed"!==e.connectionState||(e.removeEventListener("iceconnectionstatechange",r),i(new Error("ICE/DTLS not connected")))};e.addEventListener("iceconnectionstatechange",r)}))}async teardownReceiver(e,t){const i=this.encByReceiver.get(e);i&&(t.postMessage({operation:"stop",id:i.id}),this.encByReceiver.delete(e))}async addRemoteTrack(e,t){const i=await this.getWorker(),r=t.track,n=t.receiver,s=Number(t.streams[0].id),a=(this.getEncKey(),this.getConnectionManager().getConnectionWithSession(e,"subscriber").pc);this.logger.log("important-only","waitUntilConnected..."),await this.waitUntilConnected(a),this.logger.log("important-only","setupReceiverTransform..."),await this.setupReceiverTransform(n,s,i),r.addEventListener("ended",(async()=>await this.teardownReceiver(n,i))),this.callRegisteredListeners(e,t)}callRegisteredListeners(e,t){const i=Number(t.streams[0].id),r=this.remoteStreamsListeners.get(e);if(!r)return void this.logger.log("info","No remoteTrack listener registered for room: "+e);const n=r.filter((e=>e.streamId===i||void 0===e.streamId));for(const e of n)e.onRemoteStreamTrack&&"function"==typeof e.onRemoteStreamTrack&&e.onRemoteStreamTrack(t)}async onSubscriptionUpdated(e,t){if(!this.peerConnectionReconfigureQueue)throw new Error("ReconfigureQueue does not exist.");this.peerConnectionReconfigureQueue.enqueue({taskId:Math.floor(1+1e4*Math.random()),_room:e,offer:t});try{await this.peerConnectionReconfigureQueue.processAll()}catch(e){console.error("Error on onSubscriberAttached",e)}}async onSubscriptionUpdatedSingle(e,t){return this.reconfigureSingle(e,t)}async reconfigureSingle(e,t){if(!this.configuration)throw new Error("Configuration missing.");const i=this.getConnectionManager().getConnectionWithSession(e,"subscriber").pc;this.logger.log("important-only","1. Setting up remoteDescription..."),await i.setRemoteDescription(new RTCSessionDescription({type:t.type,sdp:t.sdp})),this.logger.log("important-only","offer from Janus: ",JSON.stringify(t,null,2)),this.logger.log("important-only","2. Creating an answer...","peerConnection state",i.connectionState);const r=await i.createAnswer();return this.logger.log("important-only","3. Setting up localDescription..."),await i.setLocalDescription(new RTCSessionDescription(r)),this.lastProcessedAnswer[e]=r,r}}},439:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebRtcConfig=void 0,t.WebRtcConfig=class{static iv="uMuF0aaCZ6+kLrwp";static key="7c4ba0c3e256369f7c4ba0c3e256369f";static iceTransportPolicy="all";static appServer="localhost:8810";static getIV(){return this.iv}static getKey(){return this.key}static getTurnServers(){return["turn:172.16.238.1:3478"]}static getRTCIceTransportPolicy(){return this.iceTransportPolicy}static generateTurnConfiguration(e){return{iceServers:e.map((e=>({urls:e.url,username:e.username,credential:e.password}))),iceTransportPolicy:this.iceTransportPolicy}}static getAppServerAddress(){return this.appServer}}},332:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebRtcInterfaceImpl=void 0,t.WebRtcInterfaceImpl=class{webRtcClient;constructor(e){this.webRtcClient=e}methodsMap={createOfferAndSetLocalDescription:this.createOfferAndSetLocalDescription,createAnswerAndSetDescriptions:this.createAnswerAndSetDescriptions,setAnswerAndSetRemoteDescription:this.setAnswerAndSetRemoteDescription,updateSessionId:this.updateSessionId,close:this.close,updateKeys:this.updateKeys};isMainThread(){return"undefined"!=typeof window}getClient(){if(!this.webRtcClient)throw new Error("WebRtcClient not initialized. Aborting...");return this.webRtcClient}async methodCall(e,t){if(this.methodsMap[e]&&"function"==typeof this.methodsMap[e])return this.methodsMap[e].call(this,t);throw new Error(`Method '${e}' is not implemented.`)}async createOfferAndSetLocalDescription(e){const t=this.getClient().getConnectionManager().getConnectionWithSession(e.roomId,"publisher").pc,i=await t.createOffer();return await t.setLocalDescription(i),i.sdp}async createAnswerAndSetDescriptions(e){const t={sdp:e.sdp,type:e.type};return await this.getClient().onSubscriptionUpdated(e.roomId,t),this.webRtcClient.lastProcessedAnswer[e.roomId].sdp}async setAnswerAndSetRemoteDescription(e){const t=this.getClient().getConnectionManager().getConnectionWithSession(e.roomId,"publisher");if(!("pc"in t))throw new Error("WebRtcInterfaceImpl: No peerConnection available on setAnswerAndSetRemoteDescription");const i=t.pc;await i.setRemoteDescription(new RTCSessionDescription({sdp:e.sdp,type:e.type}))}async close(e){this.getClient().getConnectionManager().closePeerConnectionBySessionIfExists(e,"subscriber"),this.getClient().getConnectionManager().closePeerConnectionBySessionIfExists(e,"publisher")}async updateKeys(e){return this.getClient().updateKeys(e.streamRoomId,e.keys)}async updateSessionId(e,t,i){this.getClient().getConnectionManager().updateSessionForConnection(e,i,t)}}},578:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WebWorker=void 0,t.WebWorker=class{assetsDir;onFrame;worker;constructor(e,t){this.assetsDir=e,this.onFrame=t}async init_e2ee(){this.worker=new Worker(this.assetsDir+"/e2ee-worker.js"),this.worker.onmessage=e=>{try{"rms"===e.data.type&&void 0!==this.onFrame&&"function"==typeof this.onFrame&&this.onFrame({rms:e.data.rms,kind:"audio",receiverId:e.data.receiverId,publisherId:e.data.publisherId})}catch(e){console.error("[Worker]: invalid event")}},this.worker.onerror=e=>console.error(e),this.worker.postMessage({operation:"initialize"})}getWorker(){return this.worker}setKeys(e){this.worker?this.worker.postMessage({operation:"setKeys",keys:e}):console.warn("Cannot pass keys to e2ee worker as it is not initialized yet.")}createWorkerFromFunction(e){const t=new Blob([`(${e.toString()})()`],{type:"application/javascript"});return new Worker(URL.createObjectURL(t))}async createWorkerFromScript(e){const t=await fetch(e).then((e=>e.text())),i=new Blob([t],{type:"application/javascript"}),r=URL.createObjectURL(i);return new Worker(r)}}},474:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ActiveSpeakerDetector=t.DEFAULTS=void 0,t.DEFAULTS={rmsEmaAlpha:.2,noiseEmaAlpha:.02,thresholdOffset:6,activityWindowMs:400,holdMs:200},t.ActiveSpeakerDetector=class{opts;speakers=new Map;activeSpeaker=null;constructor(e){this.opts=e}onFrame({id:e,rms:t,timestamp:i}){const r=this.getOrCreateState(e,t);r.emaRms=this.opts.rmsEmaAlpha*t+(1-this.opts.rmsEmaAlpha)*r.emaRms,r.emaRms<r.noiseFloor+this.opts.thresholdOffset&&(r.noiseFloor=this.opts.noiseEmaAlpha*r.emaRms+(1-this.opts.noiseEmaAlpha)*r.noiseFloor);const n=r.noiseFloor+this.opts.thresholdOffset;return r.emaRms>=n?(r.lastAboveThresholdTs=i,r.activeSince=i,r.active=!0):(r.active=!1,r.activeSince=0),this.selectActiveSpeakers(i)}selectActiveSpeakers(e){for(const[t,i]of this.speakers.entries())i.active=e-i.lastAboveThresholdTs<=this.opts.activityWindowMs&&e-i.activeSince<this.opts.holdMs;return Array.from(this.speakers.values())}getOrCreateState(e,t){let i=this.speakers.get(e);return i||(i={streamId:e,emaRms:t,noiseFloor:t,lastAboveThresholdTs:-1/0,active:!1,activeSince:0},this.speakers.set(e,i)),i}}},247:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LocalAudioLevelMeter=void 0,t.LocalAudioLevelMeter=class{track;onLevel;ctx;node;source;keepAliveGain;stopped=!1;constructor(e,t){this.track=e,this.onLevel=t}async init(e){const t=[];try{const e=this.track.getSettings?.();"number"==typeof e?.sampleRate&&t.push(e.sampleRate)}catch{}let i;t.push(void 0);for(const r of t){if(this.stopped)throw new Error("LocalAudioLevelMeter stopped during init");try{this.ctx=r?new AudioContext({sampleRate:r}):new AudioContext,await this.ctx.audioWorklet.addModule(e);try{await this.ctx.resume()}catch{}this.source=this.ctx.createMediaStreamSource(new MediaStream([this.track])),this.node=new AudioWorkletNode(this.ctx,"rms-processor"),this.node.port.onmessage=e=>this.onLevel(e.data.rmsDb),this.keepAliveGain=this.ctx.createGain(),this.keepAliveGain.gain.value=0,this.source.connect(this.node),this.node.connect(this.keepAliveGain),this.keepAliveGain.connect(this.ctx.destination),i=void 0;break}catch(e){i=e;try{this.ctx?.close()}catch{}}}if(i)throw i}stop(){this.stopped=!0;try{this.node?.port?.close()}catch{}try{this.source?.disconnect()}catch{}try{this.node?.disconnect()}catch{}try{this.keepAliveGain?.disconnect()}catch{}try{this.ctx?.close()}catch{}}}}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}var r={};return(()=>{"use strict";var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.Endpoint=void 0;const t=i(181);Object.defineProperty(e,"Endpoint",{enumerable:!0,get:function(){return t.EndpointFactory}})})(),r})()));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* The buffer module from node.js, for the browser.
|
|
3
|
+
*
|
|
4
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*!
|
|
9
|
+
PrivMX Endpoint.
|
|
10
|
+
Copyright © 2024 Simplito sp. z o.o.
|
|
11
|
+
|
|
12
|
+
This file is part of the PrivMX Platform (https://privmx.dev).
|
|
13
|
+
This software is Licensed under the PrivMX Free License.
|
|
14
|
+
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/*!
|
|
20
|
+
PrivMX Web Endpoint.
|
|
21
|
+
Copyright © 2024 Simplito sp. z o.o.
|
|
22
|
+
|
|
23
|
+
This file is part of the PrivMX Platform (https://privmx.dev).
|
|
24
|
+
This software is Licensed under the PrivMX Free License.
|
|
25
|
+
|
|
26
|
+
See the License for the specific language governing permissions and
|
|
27
|
+
limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class RMSProcessor extends AudioWorkletProcessor{constructor(){super(),this.smoothing=.3,this.prev=0}process(s){const t=s[0];if(!t||!t[0])return!0;const o=t[0];let r=0;for(let s=0;s<o.length;s++){const t=o[s];r+=t*t}const e=Math.sqrt(r/o.length),h=this.smoothing*e+(1-this.smoothing)*this.prev;this.prev=h;let c=20*Math.log10(h||1e-8);return c<-100&&(c=-100),this.port.postMessage({rmsDb:c}),!0}}registerProcessor("rms-processor",RMSProcessor);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection, CryptoApi, EventQueue, InboxApi, StoreApi, ThreadApi, KvdbApi, EventApi } from
|
|
2
|
-
import { PublicConnection } from
|
|
1
|
+
import { Connection, CryptoApi, EventQueue, InboxApi, StoreApi, ThreadApi, KvdbApi, EventApi } from "../service";
|
|
2
|
+
import { PublicConnection } from "./PublicConnection";
|
|
3
3
|
import { ConnectionEventsManager, CustomEventsManager, InboxEventsManager, KvdbEventsManager, StoreEventsManager, ThreadEventsManager, UserEventsManager } from "./managers";
|
|
4
4
|
import { EventManager } from "./events";
|
|
5
5
|
/**
|
|
@@ -82,13 +82,13 @@ export declare class PrivmxClient {
|
|
|
82
82
|
*/
|
|
83
83
|
static connect(privateKey: string, solutionId: string, bridgeUrl: string): Promise<PrivmxClient>;
|
|
84
84
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
* Connects to the Platform backend as a guest user.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} solutionId ID of the Solution
|
|
88
|
+
* @param {string} bridgeUrl the Bridge Server URL
|
|
89
|
+
*
|
|
90
|
+
* @returns {Promise<PublicConnection>} Promised instance of Connection
|
|
91
|
+
*/
|
|
92
92
|
static connectPublic(solutionId: string, bridgeUrl: string): Promise<PublicConnection>;
|
|
93
93
|
/**
|
|
94
94
|
* @description Gets the connection object.
|
|
@@ -67,7 +67,7 @@ class PrivmxClient {
|
|
|
67
67
|
}
|
|
68
68
|
static checkSetup() {
|
|
69
69
|
if (!this.isSetup) {
|
|
70
|
-
throw new Error(
|
|
70
|
+
throw new Error("Endpoint not initialized, use PrivMXClient.setup(folderPath).");
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -125,23 +125,23 @@ class PrivmxClient {
|
|
|
125
125
|
this.checkSetup();
|
|
126
126
|
const connection = await service_1.EndpointFactory.connect(privateKey, solutionId, bridgeUrl);
|
|
127
127
|
if (!connection) {
|
|
128
|
-
throw new Error(
|
|
128
|
+
throw new Error("ERROR: Could not connect to bridge");
|
|
129
129
|
}
|
|
130
130
|
return new PrivmxClient(connection);
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
* Connects to the Platform backend as a guest user.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} solutionId ID of the Solution
|
|
136
|
+
* @param {string} bridgeUrl the Bridge Server URL
|
|
137
|
+
*
|
|
138
|
+
* @returns {Promise<PublicConnection>} Promised instance of Connection
|
|
139
|
+
*/
|
|
140
140
|
static async connectPublic(solutionId, bridgeUrl) {
|
|
141
141
|
this.checkSetup();
|
|
142
142
|
const connection = await service_1.EndpointFactory.connectPublic(solutionId, bridgeUrl);
|
|
143
143
|
if (!connection) {
|
|
144
|
-
throw new Error(
|
|
144
|
+
throw new Error("ERROR: Could not connect to bridge");
|
|
145
145
|
}
|
|
146
146
|
return new PublicConnection_1.PublicConnection(connection);
|
|
147
147
|
}
|
|
@@ -152,7 +152,7 @@ class PrivmxClient {
|
|
|
152
152
|
*/
|
|
153
153
|
getConnection() {
|
|
154
154
|
if (!this.connection) {
|
|
155
|
-
throw new Error(
|
|
155
|
+
throw new Error("No active connection");
|
|
156
156
|
}
|
|
157
157
|
return this.connection;
|
|
158
158
|
}
|
|
@@ -336,7 +336,7 @@ class PrivmxClient {
|
|
|
336
336
|
this.kvdbEventsManager = null;
|
|
337
337
|
}
|
|
338
338
|
catch (e) {
|
|
339
|
-
console.error(
|
|
339
|
+
console.error("Error during disconnection:", e);
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection } from
|
|
2
|
-
import { InboxEntryPayload } from
|
|
1
|
+
import { Connection } from "../service";
|
|
2
|
+
import { InboxEntryPayload } from "./inbox";
|
|
3
3
|
/**
|
|
4
4
|
* @class PublicConnection
|
|
5
5
|
* @classdesc A client for interacting with the PrivMX Endpoint API as a guest. The scope is limited to sending an entries to inboxes.
|
|
@@ -46,7 +46,7 @@ class PublicConnection {
|
|
|
46
46
|
*/
|
|
47
47
|
getConnection() {
|
|
48
48
|
if (!this.connection) {
|
|
49
|
-
throw new Error(
|
|
49
|
+
throw new Error("No active connection");
|
|
50
50
|
}
|
|
51
51
|
return this.connection;
|
|
52
52
|
}
|
|
@@ -101,7 +101,7 @@ class PublicConnection {
|
|
|
101
101
|
this.inboxApi = null;
|
|
102
102
|
}
|
|
103
103
|
catch (e) {
|
|
104
|
-
console.error(
|
|
104
|
+
console.error("Error during disconnection:", e);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
@@ -18,9 +18,7 @@ describe("Connection event manager", () => {
|
|
|
18
18
|
type: subscriptions_1.ConnectionStatusEventType.LIB_CONNECTED,
|
|
19
19
|
callbacks: [callback],
|
|
20
20
|
});
|
|
21
|
-
const [libSubscriptionId] = await connectionEventsManager.subscribeFor([
|
|
22
|
-
libSubscription,
|
|
23
|
-
]);
|
|
21
|
+
const [libSubscriptionId] = await connectionEventsManager.subscribeFor([libSubscription]);
|
|
24
22
|
expect(libSubscriptionId).toBe("1/channel/lib_connected");
|
|
25
23
|
q.dispatchEvent((0, constants_1.MOCK_LIB_CONNECTED_EVENT)(1));
|
|
26
24
|
await (0, utils_1.waitForNextTick)();
|
|
@@ -54,9 +54,7 @@ describe("Custom event manager", () => {
|
|
|
54
54
|
id: "ctx-1",
|
|
55
55
|
callbacks: [callback],
|
|
56
56
|
});
|
|
57
|
-
const [subscriptionId] = await customEventsManager.subscribeFor([
|
|
58
|
-
subscription,
|
|
59
|
-
]);
|
|
57
|
+
const [subscriptionId] = await customEventsManager.subscribeFor([subscription]);
|
|
60
58
|
await customEventsManager.unsubscribeFrom([subscriptionId]);
|
|
61
59
|
q.dispatchEvent((0, constants_1.MOCK_CUSTOM_EVENT)(subscriptionId));
|
|
62
60
|
await (0, utils_1.waitForNextTick)();
|