@jibb-open/jssdk 3.17.7 → 3.18.2

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/ws/eventbus.js CHANGED
@@ -1 +1,293 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventBusConnection=void 0,require("core-js/modules/es.array-buffer.constructor.js"),require("core-js/modules/es.array-buffer.slice.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.typed-array.uint8-array.js"),require("core-js/modules/es.typed-array.fill.js"),require("core-js/modules/es.typed-array.set.js"),require("core-js/modules/es.typed-array.sort.js"),require("core-js/modules/es.typed-array.to-locale-string.js"),require("core-js/modules/es.weak-map.js"),require("core-js/modules/esnext.aggregate-error.js"),require("core-js/modules/esnext.promise.any.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/web.url.js"),require("core-js/modules/web.url.to-json.js"),require("core-js/modules/web.url-search-params.js");var _config=require("../config.js"),_index=require("../utils/logger/index.js"),_exceptions=require("../types/exceptions.js"),_types=require("../types/types.js"),_proto=require("../types/proto.js"),_auth=require("../api/auth.js"),_observable_connection=require("./observable_connection.js");function _classPrivateMethodInitSpec(a,b){_checkPrivateRedeclaration(a,b),b.add(a)}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classPrivateFieldGet(b,c){return b.get(_assertClassBrand(b,c))}function _classPrivateFieldSet(b,c,a){return b.set(_assertClassBrand(b,c),a),a}function _assertClassBrand(a,b,c){if("function"==typeof a?a===b:a.has(b))return 3>arguments.length?b:c;throw new TypeError("Private element is not present on this object")}const ClientType=_proto.types.ClientType,BusMessage=_proto.cilix.BusMessage;let instance,clientType=ClientType.WEBAPP,clientName="client";const observable=new _observable_connection.Observable;var _expiryTimer=/*#__PURE__*/new WeakMap,_EventBusConnection_brand=/*#__PURE__*/new WeakSet;class EventBusConnection extends _observable_connection.ObservableRetryConnection{static getInstance(){return instance||(instance=new EventBusConnection),instance}static addEventListener(a){return observable.addEventListener(a)}static removeEventListener(a){observable.removeEventListener(a)}static setClientName(a){clientName=a}static setClientType(a){clientType=a}constructor(){super("eventbus-".concat(clientName)),_classPrivateMethodInitSpec(this,_EventBusConnection_brand),_classPrivateFieldInitSpec(this,_expiryTimer,void 0),this.observable=observable,this.userToken=null,_classPrivateFieldSet(_expiryTimer,this,null)}async stop(){clearTimeout(_classPrivateFieldGet(_expiryTimer,this)),super.stop()}async write(a){_index.logger.debug("".concat(this.name,".write: "),BusMessage.toObject(a));let b=BusMessage.encode(a).finish();return super.write(b)}writeObject(a){let b=BusMessage.verify(a);if(b)throw new Error(b);let c=BusMessage.fromObject(a);return this.write(c)}async getURI(){try{this.userToken=await(0,_auth.getUserToken)(),this.userClaims=new _types.UserClaims(this.userToken);let a=this.userClaims.getSecondsUntilExpiry();if(0>=a){let a=new _exceptions.PermissionDeniedError("user token expired");throw this.onError(a),a}_classPrivateFieldSet(_expiryTimer,this,setTimeout(()=>{this.onError(new _exceptions.SessionTimeoutError("user token expired"))},a))}catch(a){let b=new _exceptions.PermissionDeniedError(a);throw this.onError(b),b}let a=new URL(_config.Config.apiBaseURL),b=a.host+("/"===a.pathname?"":a.pathname),c=_assertClassBrand(_EventBusConnection_brand,this,_getClientTypeAsString).call(this,clientType);return"wss://".concat(b,"/ws/eventbus/").concat(c,"?user_token=").concat(this.userToken,"&name=").concat(clientName)}onData(a){try{if(a instanceof ArrayBuffer){let b=new Uint8Array(a),c=BusMessage.decode(b);return b=null,_index.logger.debug("".concat(this.name,".read: "),c),void _assertClassBrand(_EventBusConnection_brand,this,_onMessage).call(this,c)}}catch(a){_index.logger.error(a)}this.parseJSONResponse(a)}stopStream(a){return this.writeObject({stopRequest:{},dst:{id:a}})}stopAllStreams(){return this.writeObject({stopRequest:{}})}startStream(a){let{config:b,runtimeConfig:c,camera:d,clientId:e,meetingToken:f}=a;return this.writeObject({startRequest:{config:b,runtimeConfig:c,camera:d,meetingToken:f},dst:{id:e}})}requestCameraPreview(a,b){return this.writeObject({previewRequest:{source:{id:b}},dst:{id:a}})}setRuntimeConfig(a,b){return this.writeObject({runtimeConfigRequest:b,dst:{id:a}})}getCameraList(a){return this.writeObject({cameraListRequest:{},dst:{id:a}})}sendCameraList(a,b,c){return this.writeObject({cameraListResponse:{items:a},src:b,dst:c})}getClientStatusList(){return this.writeObject({clientStatusRequest:{}})}}exports.EventBusConnection=EventBusConnection;async function _onMessage(a){if(a&&"object"==typeof a)try{a.clientConnected&&_assertClassBrand(_EventBusConnection_brand,this,_onClientConnected).call(this,a),a.clientDisconnected&&_assertClassBrand(_EventBusConnection_brand,this,_onClientDisconnected).call(this,a),a.cameraListRequest&&_assertClassBrand(_EventBusConnection_brand,this,_onCameraListRequest).call(this,a),a.cameraListResponse&&_assertClassBrand(_EventBusConnection_brand,this,_onCameraListResponse).call(this,a),a.runtimeConfigRequest&&_assertClassBrand(_EventBusConnection_brand,this,_onRuntimeConfigRequest).call(this,a),a.startRequest&&_assertClassBrand(_EventBusConnection_brand,this,_onStartRequest).call(this,a),a.stopRequest&&_assertClassBrand(_EventBusConnection_brand,this,_onStopRequest).call(this,a),a.previewRequest&&_assertClassBrand(_EventBusConnection_brand,this,_onPreviewRequest).call(this,a),a.previewResponse&&_assertClassBrand(_EventBusConnection_brand,this,_onPreviewResponse).call(this,a),a.ipsaResponse&&_assertClassBrand(_EventBusConnection_brand,this,_onIPSAResponse).call(this,a),a.tooManyPublishers&&_assertClassBrand(_EventBusConnection_brand,this,_onTooManyPublishers).call(this,a),a.recordingStarted&&_assertClassBrand(_EventBusConnection_brand,this,_onRecordingStarted).call(this,a),a.recordingStopped&&_assertClassBrand(_EventBusConnection_brand,this,_onRecordingStopped).call(this,a)}catch(a){_index.logger.error(a)}}function _getClientTypeAsString(a){let b=Object.entries(ClientType).find(b=>{let[c,d]=b;return d==a});if(!b)throw new _exceptions.InvalidArgumentError("Invalid client type: ".concat(a));let c=b[0].toLowerCase();return c}function _sendPreview(a,b){this.writeObject({previewResponse:{image:a},dst:b})}async function _onCameraListRequest(a){let b=await _assertClassBrand(_EventBusConnection_brand,this,_callSubscribers).call(this,"onCameraListRequest",a.cameraListRequest);this.sendCameraList(b,a.dst,a.src)}function _onCameraListResponse(a){observable.notify("onCameraListResponse",a.cameraListResponse)}function _onClientConnected(a){_index.logger.info("".concat(this.name,": client connected: "),a.src),observable.notify("onClientConnected",a.src)}function _onClientDisconnected(a){_index.logger.warn("".concat(this.name,": client disconnected: "),a.src),observable.notify("onClientDisconnected",a.src)}function _onRuntimeConfigRequest(a){observable.notify("onRuntimeConfigRequest",a.runtimeConfigRequest)}function _onStopRequest(a){observable.notify("onStopRequest",a.stopRequest)}async function _onPreviewRequest(a){let b=await _assertClassBrand(_EventBusConnection_brand,this,_callSubscribers).call(this,"onPreviewRequest",a.previewRequest);_assertClassBrand(_EventBusConnection_brand,this,_sendPreview).call(this,b,a.src)}function _onPreviewResponse(a){observable.notify("onPreviewResponse",a.previewResponse)}function _onStartRequest(a){var b,c;let d=a.startRequest;!(null!==d&&void 0!==d&&null!==(b=d.camera)&&void 0!==b&&b.id)&&null!==d&&void 0!==d&&null!==(c=d.inputSource)&&void 0!==c&&c.id&&(d.camera={id:d.inputSource.id}),observable.notify("onStartRequest",d)}function _onCornersReceived(a){observable.notify("onCornersReceived",a.corners.corners)}function _onIPSAResponse(a){a&&observable.notify("onIPSAResponse",a.ipsaResponse)}function _onTooManyPublishers(a){observable.notify("onTooManyPublishers",a.tooManyPublishers)}function _onRecordingStarted(a){observable.notify("onRecordingStarted",a.recordingStarted)}function _onRecordingStopped(a){observable.notify("onRecordingStopped",a.recordingStopped)}function _callSubscribers(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];let e=[...observable.observers].map(b=>{let[c,d]=b;return d[a]}).filter(a=>a!==void 0).map(a=>a(...c));return Promise.any(e)}
1
+ import "core-js/modules/es.array-buffer.constructor.js";
2
+ import "core-js/modules/es.array-buffer.slice.js";
3
+ import "core-js/modules/es.promise.js";
4
+ import "core-js/modules/es.typed-array.uint8-array.js";
5
+ import "core-js/modules/es.typed-array.fill.js";
6
+ import "core-js/modules/es.typed-array.set.js";
7
+ import "core-js/modules/es.typed-array.sort.js";
8
+ import "core-js/modules/es.typed-array.to-locale-string.js";
9
+ import "core-js/modules/es.weak-map.js";
10
+ import "core-js/modules/esnext.aggregate-error.js";
11
+ import "core-js/modules/esnext.promise.any.js";
12
+ import "core-js/modules/web.dom-collections.iterator.js";
13
+ import "core-js/modules/web.url.js";
14
+ import "core-js/modules/web.url.to-json.js";
15
+ import "core-js/modules/web.url-search-params.js";
16
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
17
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
18
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
19
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
20
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
21
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
22
+ import { Config } from "../config.js";
23
+ import { logger } from "../utils/logger/index.js";
24
+ import { InvalidArgumentError, PermissionDeniedError, SessionTimeoutError } from '../types/exceptions.js';
25
+ import { UserClaims } from "../types/types.js";
26
+ import { types, cilix } from "../types/proto.js";
27
+ import { getUserToken } from "../api/auth.js";
28
+ import { Observable, ObservableRetryConnection } from "./observable_connection.js";
29
+ const ClientType = types.ClientType;
30
+ const BusMessage = cilix.BusMessage;
31
+ let clientType = ClientType.WEBAPP;
32
+ let clientName = "client";
33
+ let instance = undefined;
34
+ const observable = new Observable();
35
+ var _expiryTimer = /*#__PURE__*/new WeakMap();
36
+ var _EventBusConnection_brand = /*#__PURE__*/new WeakSet();
37
+ class EventBusConnection extends ObservableRetryConnection {
38
+ static getInstance() {
39
+ if (!instance) instance = new EventBusConnection();
40
+ return instance;
41
+ }
42
+ static addEventListener(observer) {
43
+ return observable.addEventListener(observer);
44
+ }
45
+ static removeEventListener(id) {
46
+ observable.removeEventListener(id);
47
+ }
48
+ static setClientName(name) {
49
+ clientName = name;
50
+ }
51
+ static setClientType(t) {
52
+ clientType = t;
53
+ }
54
+ constructor() {
55
+ super("eventbus-".concat(clientName));
56
+ _classPrivateMethodInitSpec(this, _EventBusConnection_brand);
57
+ _classPrivateFieldInitSpec(this, _expiryTimer, void 0);
58
+ this.observable = observable;
59
+ this.userToken = null;
60
+ _classPrivateFieldSet(_expiryTimer, this, null);
61
+ }
62
+ async stop() {
63
+ clearTimeout(_classPrivateFieldGet(_expiryTimer, this));
64
+ super.stop();
65
+ }
66
+ async write(msg) {
67
+ logger.debug("".concat(this.name, ".write: "), BusMessage.toObject(msg));
68
+ let data = BusMessage.encode(msg).finish();
69
+ return super.write(data);
70
+ }
71
+ writeObject(msg) {
72
+ let err = BusMessage.verify(msg);
73
+ if (err) throw new Error(err);
74
+ let request = BusMessage.fromObject(msg);
75
+ return this.write(request);
76
+ }
77
+ async getURI() {
78
+ try {
79
+ this.userToken = await getUserToken();
80
+ this.userClaims = new UserClaims(this.userToken);
81
+ let seconds = this.userClaims.getSecondsUntilExpiry();
82
+ if (seconds <= 0) {
83
+ let e = new PermissionDeniedError("user token expired");
84
+ this.onError(e);
85
+ throw e;
86
+ }
87
+ _classPrivateFieldSet(_expiryTimer, this, setTimeout(() => {
88
+ this.onError(new SessionTimeoutError("user token expired"));
89
+ }, seconds));
90
+ } catch (err) {
91
+ let e = new PermissionDeniedError(err);
92
+ this.onError(e);
93
+ throw e;
94
+ }
95
+ let base = new URL(Config.apiBaseURL);
96
+ let url = base.host + (base.pathname !== '/' ? base.pathname : '');
97
+ let typeStr = _assertClassBrand(_EventBusConnection_brand, this, _getClientTypeAsString).call(this, clientType);
98
+ return "wss://".concat(url, "/ws/eventbus/").concat(typeStr, "?user_token=").concat(this.userToken, "&name=").concat(clientName);
99
+ }
100
+ onData(msg) {
101
+ try {
102
+ if (msg instanceof ArrayBuffer) {
103
+ let buffer = new Uint8Array(msg);
104
+ let response = BusMessage.decode(buffer);
105
+ buffer = null;
106
+ logger.debug("".concat(this.name, ".read: "), response);
107
+ _assertClassBrand(_EventBusConnection_brand, this, _onMessage).call(this, response);
108
+ return;
109
+ }
110
+ } catch (err) {
111
+ logger.error(err);
112
+ }
113
+ this.parseJSONResponse(msg);
114
+ }
115
+ stopStream(clientId) {
116
+ return this.writeObject({
117
+ stopRequest: {},
118
+ dst: {
119
+ id: clientId
120
+ }
121
+ });
122
+ }
123
+ stopAllStreams() {
124
+ return this.writeObject({
125
+ stopRequest: {}
126
+ });
127
+ }
128
+ startStream(_ref) {
129
+ let {
130
+ config,
131
+ runtimeConfig,
132
+ camera,
133
+ clientId,
134
+ meetingToken
135
+ } = _ref;
136
+ return this.writeObject({
137
+ startRequest: {
138
+ config,
139
+ runtimeConfig,
140
+ camera,
141
+ meetingToken
142
+ },
143
+ dst: {
144
+ id: clientId
145
+ }
146
+ });
147
+ }
148
+ requestCameraPreview(clientId, sourceId) {
149
+ return this.writeObject({
150
+ previewRequest: {
151
+ source: {
152
+ id: sourceId
153
+ }
154
+ },
155
+ dst: {
156
+ id: clientId
157
+ }
158
+ });
159
+ }
160
+ setRuntimeConfig(clientId, cfg) {
161
+ return this.writeObject({
162
+ runtimeConfigRequest: cfg,
163
+ dst: {
164
+ id: clientId
165
+ }
166
+ });
167
+ }
168
+ getCameraList(clientId) {
169
+ return this.writeObject({
170
+ cameraListRequest: {},
171
+ dst: {
172
+ id: clientId
173
+ }
174
+ });
175
+ }
176
+ sendCameraList(camList, src, dst) {
177
+ let response = {
178
+ cameraListResponse: {
179
+ items: camList
180
+ },
181
+ src: src,
182
+ dst: dst
183
+ };
184
+ return this.writeObject(response);
185
+ }
186
+ getClientStatusList() {
187
+ let request = {
188
+ clientStatusRequest: {}
189
+ };
190
+ return this.writeObject(request);
191
+ }
192
+ }
193
+ async function _onMessage(msg) {
194
+ if (!msg || typeof msg !== 'object') return;
195
+ try {
196
+ msg.clientConnected && _assertClassBrand(_EventBusConnection_brand, this, _onClientConnected).call(this, msg);
197
+ msg.clientDisconnected && _assertClassBrand(_EventBusConnection_brand, this, _onClientDisconnected).call(this, msg);
198
+ msg.cameraListRequest && _assertClassBrand(_EventBusConnection_brand, this, _onCameraListRequest).call(this, msg);
199
+ msg.cameraListResponse && _assertClassBrand(_EventBusConnection_brand, this, _onCameraListResponse).call(this, msg);
200
+ msg.runtimeConfigRequest && _assertClassBrand(_EventBusConnection_brand, this, _onRuntimeConfigRequest).call(this, msg);
201
+ msg.startRequest && _assertClassBrand(_EventBusConnection_brand, this, _onStartRequest).call(this, msg);
202
+ msg.stopRequest && _assertClassBrand(_EventBusConnection_brand, this, _onStopRequest).call(this, msg);
203
+ msg.previewRequest && _assertClassBrand(_EventBusConnection_brand, this, _onPreviewRequest).call(this, msg);
204
+ msg.previewResponse && _assertClassBrand(_EventBusConnection_brand, this, _onPreviewResponse).call(this, msg);
205
+ msg.ipsaResponse && _assertClassBrand(_EventBusConnection_brand, this, _onIPSAResponse).call(this, msg);
206
+ msg.tooManyPublishers && _assertClassBrand(_EventBusConnection_brand, this, _onTooManyPublishers).call(this, msg);
207
+ msg.recordingStarted && _assertClassBrand(_EventBusConnection_brand, this, _onRecordingStarted).call(this, msg);
208
+ msg.recordingStopped && _assertClassBrand(_EventBusConnection_brand, this, _onRecordingStopped).call(this, msg);
209
+ } catch (e) {
210
+ logger.error(e);
211
+ }
212
+ }
213
+ function _getClientTypeAsString(clientType) {
214
+ let found = Object.entries(ClientType).find(_ref2 => {
215
+ let [k, v] = _ref2;
216
+ return v == clientType;
217
+ });
218
+ if (!found) throw new InvalidArgumentError("Invalid client type: ".concat(clientType));
219
+ let name = found[0].toLowerCase();
220
+ return name;
221
+ }
222
+ function _sendPreview(image, dst) {
223
+ this.writeObject({
224
+ previewResponse: {
225
+ image: image
226
+ },
227
+ dst: dst
228
+ });
229
+ }
230
+ async function _onCameraListRequest(msg) {
231
+ let response = await _assertClassBrand(_EventBusConnection_brand, this, _callSubscribers).call(this, 'onCameraListRequest', msg.cameraListRequest);
232
+ this.sendCameraList(response, msg.dst, msg.src);
233
+ }
234
+ function _onCameraListResponse(msg) {
235
+ observable.notify('onCameraListResponse', msg.cameraListResponse);
236
+ }
237
+ function _onClientConnected(msg) {
238
+ logger.info("".concat(this.name, ": client connected: "), msg.src);
239
+ observable.notify('onClientConnected', msg.src);
240
+ }
241
+ function _onClientDisconnected(msg) {
242
+ logger.warn("".concat(this.name, ": client disconnected: "), msg.src);
243
+ observable.notify('onClientDisconnected', msg.src);
244
+ }
245
+ function _onRuntimeConfigRequest(msg) {
246
+ observable.notify('onRuntimeConfigRequest', msg.runtimeConfigRequest);
247
+ }
248
+ function _onStopRequest(msg) {
249
+ observable.notify('onStopRequest', msg.stopRequest);
250
+ }
251
+ async function _onPreviewRequest(msg) {
252
+ let response = await _assertClassBrand(_EventBusConnection_brand, this, _callSubscribers).call(this, 'onPreviewRequest', msg.previewRequest);
253
+ _assertClassBrand(_EventBusConnection_brand, this, _sendPreview).call(this, response, msg.src);
254
+ }
255
+ function _onPreviewResponse(msg) {
256
+ observable.notify('onPreviewResponse', msg.previewResponse);
257
+ }
258
+ function _onStartRequest(msg) {
259
+ var _req$camera, _req$inputSource;
260
+ let req = msg.startRequest;
261
+ if (!(req !== null && req !== void 0 && (_req$camera = req.camera) !== null && _req$camera !== void 0 && _req$camera.id) && req !== null && req !== void 0 && (_req$inputSource = req.inputSource) !== null && _req$inputSource !== void 0 && _req$inputSource.id) {
262
+ req.camera = {
263
+ id: req.inputSource.id
264
+ };
265
+ }
266
+ observable.notify('onStartRequest', req);
267
+ }
268
+ function _onCornersReceived(msg) {
269
+ observable.notify('onCornersReceived', msg.corners.corners);
270
+ }
271
+ function _onIPSAResponse(msg) {
272
+ msg && observable.notify('onIPSAResponse', msg.ipsaResponse);
273
+ }
274
+ function _onTooManyPublishers(msg) {
275
+ observable.notify('onTooManyPublishers', msg.tooManyPublishers);
276
+ }
277
+ function _onRecordingStarted(msg) {
278
+ observable.notify('onRecordingStarted', msg.recordingStarted);
279
+ }
280
+ function _onRecordingStopped(msg) {
281
+ observable.notify('onRecordingStopped', msg.recordingStopped);
282
+ }
283
+ function _callSubscribers(functionName) {
284
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
285
+ args[_key - 1] = arguments[_key];
286
+ }
287
+ let promises = [...observable.observers].map(_ref3 => {
288
+ let [k, o] = _ref3;
289
+ return o[functionName];
290
+ }).filter(fn => fn !== undefined).map(fn => fn(...args));
291
+ return Promise.any(promises);
292
+ }
293
+ export { EventBusConnection };
package/ws/index.js CHANGED
@@ -1 +1,11 @@
1
- "use strict";require("core-js/modules/es.weak-map.js"),require("core-js/modules/web.dom-collections.iterator.js"),Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"EventBusConnection",{enumerable:!0,get:function get(){return _eventbus.EventBusConnection}}),Object.defineProperty(exports,"IPSA",{enumerable:!0,get:function get(){return _ipsa.IPSA}}),Object.defineProperty(exports,"MeetingConnection",{enumerable:!0,get:function get(){return _meeting.MeetingConnection}}),require("core-js/modules/es.global-this.js"),require("core-js/modules/es.promise.js");var _eventbus=require("./eventbus.js"),_ipsa=require("./ipsa.js"),_meeting=require("./meeting.js");function _getRequireWildcardCache(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(_getRequireWildcardCache=function(a){return a?c:b})(a)}function _interopRequireWildcard(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!=typeof b&&"function"!=typeof b)return{default:b};var d=_getRequireWildcardCache(c);if(d&&d.has(b))return d.get(b);var e={__proto__:null},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in b)if("default"!=a&&{}.hasOwnProperty.call(b,a)){var g=f?Object.getOwnPropertyDescriptor(b,a):null;g&&(g.get||g.set)?Object.defineProperty(e,a,g):e[a]=b[a]}return e.default=b,d&&d.set(b,e),e}(null===globalThis||void 0===globalThis?void 0:globalThis.WebSocket)==null&&Promise.resolve().then(()=>_interopRequireWildcard(require("isomorphic-ws"))).then(a=>{globalThis.WebSocket=a.default});
1
+ import "core-js/modules/es.global-this.js";
2
+ import "core-js/modules/es.promise.js";
3
+ import { EventBusConnection } from "./eventbus.js";
4
+ import { IPSA } from "./ipsa.js";
5
+ import { MeetingConnection } from "./meeting.js";
6
+ if ((globalThis === null || globalThis === void 0 ? void 0 : globalThis.WebSocket) == undefined) {
7
+ import("isomorphic-ws").then(webSocket => {
8
+ globalThis.WebSocket = webSocket.default;
9
+ });
10
+ }
11
+ export { MeetingConnection, EventBusConnection, IPSA };
package/ws/ipsa.js CHANGED
@@ -1 +1,161 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IPSA=void 0,require("core-js/modules/es.array-buffer.constructor.js"),require("core-js/modules/es.array-buffer.slice.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.typed-array.uint8-array.js"),require("core-js/modules/es.typed-array.fill.js"),require("core-js/modules/es.typed-array.set.js"),require("core-js/modules/es.typed-array.sort.js"),require("core-js/modules/es.typed-array.to-locale-string.js"),require("core-js/modules/es.weak-map.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/web.url.js"),require("core-js/modules/web.url.to-json.js"),require("core-js/modules/web.url-search-params.js");var _IPSAClass,_config=require("../config.js"),_index=require("../utils/logger/index.js"),_types=require("../types/types.js"),_proto=require("../types/proto.js"),_auth=require("../api/auth.js"),_observable_connection=require("./observable_connection.js"),_exceptions=require("../types/exceptions.js");function _classPrivateMethodInitSpec(a,b){_checkPrivateRedeclaration(a,b),b.add(a)}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(a,b,c){var d=_superPropBase(a,b);if(d){var e=Object.getOwnPropertyDescriptor(d,b);return e.get?e.get.call(3>arguments.length?a:c):e.value}},_get.apply(this,arguments)}function _superPropBase(a,b){for(;!Object.prototype.hasOwnProperty.call(a,b)&&(a=_getPrototypeOf(a),null!==a););return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classPrivateFieldGet(b,c){return b.get(_assertClassBrand(b,c))}function _classPrivateFieldSet(b,c,a){return b.set(_assertClassBrand(b,c),a),a}function _assertClassBrand(a,b,c){if("function"==typeof a?a===b:a.has(b))return 3>arguments.length?b:c;throw new TypeError("Private element is not present on this object")}var _meetingExpiryTimer=/*#__PURE__*/new WeakMap,_IPSAClass_brand=/*#__PURE__*/new WeakSet;class IPSAClass extends _observable_connection.ObservableRetryConnection{constructor(a){super("ipsa",a),_classPrivateMethodInitSpec(this,_IPSAClass_brand),_classPrivateFieldInitSpec(this,_meetingExpiryTimer,void 0),this.socket=null,_classPrivateFieldSet(_meetingExpiryTimer,this,null),this.meetingToken=null,this.meetingClaims=null}async start(a){let{meetingToken:b,request:c}=a;if(this.isStarted())return void this.onError(new _exceptions.AlreadyStartedError("already started"));this.setRuntimeConfig(c.runtimeConfig),_assertClassBrand(_IPSAClass_brand,this,_setConfig).call(this,c.config),this.meetingToken=b,this.meetingClaims=new _types.MeetingClaims(this.meetingToken);let d=this.meetingClaims.getSecondsUntilExpiry();if(0>=d){let a=new _exceptions.PermissionDeniedError("meeting token expired");throw this.onError(a),a}else clearTimeout(_classPrivateFieldGet(_meetingExpiryTimer,this)),_classPrivateFieldSet(_meetingExpiryTimer,this,setTimeout(()=>{let a=new _exceptions.SessionTimeoutError("meeting token expired");this.onError(a)},d));super.start()}stop(){clearTimeout(_classPrivateFieldGet(_meetingExpiryTimer,this)),this.configRequest=null,this.runtimeConfigRequest=null,super.stop()}async getURI(){let a;try{a=await(0,_auth.getUserToken)({minExpiry:3600});let b=new _types.UserClaims(a),c=b.getSecondsUntilExpiry();if(0>=c){let a=new _exceptions.PermissionDeniedError("user token expired");throw this.onError(a),a}}catch(a){let b=new _exceptions.PermissionDeniedError(a);throw this.onError(b),b}let b=this.meetingClaims.meetindId;_index.logger.info("Starting IPSA...");let c=new URL(_config.Config.apiBaseURL),d=c.host+("/"===c.pathname?"":c.pathname);return"wss://".concat(d,"/ws/ipsa/").concat(b,"?user_token=").concat(a,"&meeting_token=").concat(this.meetingToken)}onData(a){try{if(a instanceof ArrayBuffer){let b=new Uint8Array(a),c=_proto.ipsa.Response.decode(b);return void this.notify("onResponse",c)}}catch(a){_index.logger.error(a)}this.parseJSONResponse(a)}writeData(a){let b=this.getBufferedAmount();0<b&&_index.logger.warn("ipsa: low internet speed connection. [buffer size: ".concat(b,"]"));let c=_proto.ipsa.Request.create({ipsa:{data:a}});return _assertClassBrand(_IPSAClass_brand,this,_write).call(this,c)}onConnected(){super.onConnected(),_assertClassBrand(_IPSAClass_brand,this,_write).call(this,this.configRequest),_assertClassBrand(_IPSAClass_brand,this,_write).call(this,this.runtimeConfigRequest)}setRuntimeConfig(a){if(!a)throw new _exceptions.InvalidArgumentError("bad request");let b=_proto.ipsa.Request.create({runtimeConfig:a});this.runtimeConfigRequest=b,this.isConnected()&&_assertClassBrand(_IPSAClass_brand,this,_write).call(this,b)}}_IPSAClass=IPSAClass;async function _write(a){let b=_proto.ipsa.Request.verify(a);if(b){let a=new _exceptions.InvalidArgumentError("invalid message: "+b);throw this.onError(a),a}if(a){let b=_proto.ipsa.Request.encode(a).finish();_get(_getPrototypeOf(_IPSAClass.prototype),"write",this).call(this,b)}}function _setConfig(a){if(!a)throw new _exceptions.InvalidArgumentError("bad request");let b=_proto.ipsa.Request.create({config:a});this.configRequest=b}let IPSA=exports.IPSA=new IPSAClass({maxRetryCount:10,minRetryIntervalMs:500,maxRetryIntervalMs:4e3});
1
+ var _IPSAClass;
2
+ import "core-js/modules/es.array-buffer.constructor.js";
3
+ import "core-js/modules/es.array-buffer.slice.js";
4
+ import "core-js/modules/es.promise.js";
5
+ import "core-js/modules/es.typed-array.uint8-array.js";
6
+ import "core-js/modules/es.typed-array.fill.js";
7
+ import "core-js/modules/es.typed-array.set.js";
8
+ import "core-js/modules/es.typed-array.sort.js";
9
+ import "core-js/modules/es.typed-array.to-locale-string.js";
10
+ import "core-js/modules/es.weak-map.js";
11
+ import "core-js/modules/web.dom-collections.iterator.js";
12
+ import "core-js/modules/web.url.js";
13
+ import "core-js/modules/web.url.to-json.js";
14
+ import "core-js/modules/web.url-search-params.js";
15
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
16
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
17
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
20
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
21
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
22
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
23
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
24
+ import { Config as SDKConfig } from "../config.js";
25
+ import { logger } from "../utils/logger/index.js";
26
+ import { MeetingClaims, UserClaims } from "../types/types.js";
27
+ import { ipsa } from "../types/proto.js";
28
+ import { getUserToken } from "../api/auth.js";
29
+ import { ObservableRetryConnection } from "./observable_connection.js";
30
+ import { AlreadyStartedError, InvalidArgumentError, NotConnectedError, PermissionDeniedError, SessionTimeoutError } from "../types/exceptions.js";
31
+ var _meetingExpiryTimer = /*#__PURE__*/new WeakMap();
32
+ var _IPSAClass_brand = /*#__PURE__*/new WeakSet();
33
+ class IPSAClass extends ObservableRetryConnection {
34
+ constructor(options) {
35
+ super('ipsa', options);
36
+ _classPrivateMethodInitSpec(this, _IPSAClass_brand);
37
+ _classPrivateFieldInitSpec(this, _meetingExpiryTimer, void 0);
38
+ this.socket = null;
39
+ _classPrivateFieldSet(_meetingExpiryTimer, this, null);
40
+ this.meetingToken = null;
41
+ this.meetingClaims = null;
42
+ }
43
+ async start(_ref) {
44
+ let {
45
+ meetingToken,
46
+ request
47
+ } = _ref;
48
+ if (this.isStarted()) {
49
+ this.onError(new AlreadyStartedError("already started"));
50
+ return;
51
+ }
52
+ this.setRuntimeConfig(request.runtimeConfig);
53
+ _assertClassBrand(_IPSAClass_brand, this, _setConfig).call(this, request.config);
54
+ this.meetingToken = meetingToken;
55
+ this.meetingClaims = new MeetingClaims(this.meetingToken);
56
+ let seconds = this.meetingClaims.getSecondsUntilExpiry();
57
+ if (seconds <= 0) {
58
+ let e = new PermissionDeniedError("meeting token expired");
59
+ this.onError(e);
60
+ throw e;
61
+ } else {
62
+ clearTimeout(_classPrivateFieldGet(_meetingExpiryTimer, this));
63
+ _classPrivateFieldSet(_meetingExpiryTimer, this, setTimeout(() => {
64
+ let e = new SessionTimeoutError("meeting token expired");
65
+ this.onError(e);
66
+ }, seconds));
67
+ }
68
+ super.start();
69
+ }
70
+ stop() {
71
+ clearTimeout(_classPrivateFieldGet(_meetingExpiryTimer, this));
72
+ this.configRequest = null;
73
+ this.runtimeConfigRequest = null;
74
+ super.stop();
75
+ }
76
+ async getURI() {
77
+ let userToken;
78
+ try {
79
+ userToken = await getUserToken({
80
+ minExpiry: 3600
81
+ });
82
+ let claims = new UserClaims(userToken);
83
+ let seconds = claims.getSecondsUntilExpiry();
84
+ if (seconds <= 0) {
85
+ let e = new PermissionDeniedError("user token expired");
86
+ this.onError(e);
87
+ throw e;
88
+ }
89
+ } catch (err) {
90
+ let e = new PermissionDeniedError(err);
91
+ this.onError(e);
92
+ throw e;
93
+ }
94
+ let meetingId = this.meetingClaims.meetindId;
95
+ logger.info("Starting IPSA...");
96
+ let base = new URL(SDKConfig.apiBaseURL);
97
+ let url = base.host + (base.pathname !== '/' ? base.pathname : '');
98
+ return "wss://".concat(url, "/ws/ipsa/").concat(meetingId, "?user_token=").concat(userToken, "&meeting_token=").concat(this.meetingToken);
99
+ }
100
+ onData(msg) {
101
+ try {
102
+ if (msg instanceof ArrayBuffer) {
103
+ let buffer = new Uint8Array(msg);
104
+ let response = ipsa.Response.decode(buffer);
105
+ this.notify('onResponse', response);
106
+ return;
107
+ }
108
+ } catch (err) {
109
+ logger.error(err);
110
+ }
111
+ this.parseJSONResponse(msg);
112
+ }
113
+ writeData(data) {
114
+ let sz = this.getBufferedAmount();
115
+ if (sz > 0) logger.warn("ipsa: low internet speed connection. [buffer size: ".concat(sz, "]"));
116
+ let request = ipsa.Request.create({
117
+ ipsa: {
118
+ data: data
119
+ }
120
+ });
121
+ return _assertClassBrand(_IPSAClass_brand, this, _write).call(this, request);
122
+ }
123
+ onConnected() {
124
+ super.onConnected();
125
+ _assertClassBrand(_IPSAClass_brand, this, _write).call(this, this.configRequest);
126
+ _assertClassBrand(_IPSAClass_brand, this, _write).call(this, this.runtimeConfigRequest);
127
+ }
128
+ setRuntimeConfig(cfg) {
129
+ if (!cfg) throw new InvalidArgumentError("bad request");
130
+ let request = ipsa.Request.create({
131
+ runtimeConfig: cfg
132
+ });
133
+ this.runtimeConfigRequest = request;
134
+ if (this.isConnected()) _assertClassBrand(_IPSAClass_brand, this, _write).call(this, request);
135
+ }
136
+ }
137
+ _IPSAClass = IPSAClass;
138
+ async function _write(msg) {
139
+ let err = ipsa.Request.verify(msg);
140
+ if (err) {
141
+ let e = new InvalidArgumentError("invalid message: " + err);
142
+ this.onError(e);
143
+ throw e;
144
+ }
145
+ if (msg) {
146
+ let data = ipsa.Request.encode(msg).finish();
147
+ _get(_getPrototypeOf(_IPSAClass.prototype), "write", this).call(this, data);
148
+ }
149
+ }
150
+ function _setConfig(cfg) {
151
+ if (!cfg) throw new InvalidArgumentError("bad request");
152
+ let request = ipsa.Request.create({
153
+ config: cfg
154
+ });
155
+ this.configRequest = request;
156
+ }
157
+ export let IPSA = new IPSAClass({
158
+ maxRetryCount: 10,
159
+ minRetryIntervalMs: 500,
160
+ maxRetryIntervalMs: 4000
161
+ });