@techsee/techsee-media-service 0.21.2 → 0.22.0-alphagb2

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.
Files changed (97) hide show
  1. package/lib/LocalStreamManager.js +435 -317
  2. package/lib/LocalStreamManager.js.map +1 -1
  3. package/lib/MediaConstants.js +72 -44
  4. package/lib/MediaConstants.js.map +1 -1
  5. package/lib/MediaContracts.js +3 -3
  6. package/lib/MediaContracts.js.map +1 -1
  7. package/lib/MediaPublisher.js +45 -35
  8. package/lib/MediaPublisher.js.map +1 -1
  9. package/lib/MediaServiceBase.js +922 -706
  10. package/lib/MediaServiceBase.js.map +1 -1
  11. package/lib/MediaSession/MediaServer.js +512 -379
  12. package/lib/MediaSession/MediaServer.js.map +1 -1
  13. package/lib/MediaSession/MediaSessionBase.js +123 -88
  14. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  15. package/lib/MediaSession/SessionOpentok.js +499 -384
  16. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  17. package/lib/MediaSession/SessionTurn.js +606 -466
  18. package/lib/MediaSession/SessionTurn.js.map +1 -1
  19. package/lib/MediaSession/TurnConstants.js +30 -30
  20. package/lib/MediaSession/TurnConstants.js.map +1 -1
  21. package/lib/MediaSubscriber.js +235 -192
  22. package/lib/MediaSubscriber.js.map +1 -1
  23. package/lib/MediaUtils/Compatibility.js +127 -90
  24. package/lib/MediaUtils/Compatibility.js.map +1 -1
  25. package/lib/MediaUtils/MediaDomUtils.js +230 -179
  26. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  27. package/lib/MediaUtils/MediaTracer.js +8 -4
  28. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  29. package/lib/MultiParty/Contracts.js +3 -3
  30. package/lib/MultiParty/Contracts.js.map +1 -1
  31. package/lib/MultiParty/DetectWebRtcService.js +66 -50
  32. package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
  33. package/lib/MultiParty/MediaCapabilitiesHelper.js +258 -154
  34. package/lib/MultiParty/MediaCapabilitiesHelper.js.map +1 -1
  35. package/lib/MultiParty/MultiParty.d.ts +1 -8
  36. package/lib/MultiParty/MultiParty.d.ts.map +1 -1
  37. package/lib/MultiParty/MultiParty.js +221 -128
  38. package/lib/MultiParty/MultiParty.js.map +1 -1
  39. package/lib/MultiParty/MultipartyFactory.d.ts +1 -2
  40. package/lib/MultiParty/MultipartyFactory.d.ts.map +1 -1
  41. package/lib/MultiParty/MultipartyFactory.js +12 -7
  42. package/lib/MultiParty/MultipartyFactory.js.map +1 -1
  43. package/lib/MultiParty/OpentokMultiparty.js +611 -384
  44. package/lib/MultiParty/OpentokMultiparty.js.map +1 -1
  45. package/lib/TechseeMediaStream.js +58 -53
  46. package/lib/TechseeMediaStream.js.map +1 -1
  47. package/lib/oldCode/constants.js +20 -15
  48. package/lib/oldCode/constants.js.map +1 -1
  49. package/lib/oldCode/event-emitter.js +45 -22
  50. package/lib/oldCode/event-emitter.js.map +1 -1
  51. package/lib/oldCode/index.js +48 -52
  52. package/lib/oldCode/index.js.map +1 -1
  53. package/lib/oldCode/opentok/session.js +261 -236
  54. package/lib/oldCode/opentok/session.js.map +1 -1
  55. package/lib/oldCode/opentok/stream.js +283 -269
  56. package/lib/oldCode/opentok/stream.js.map +1 -1
  57. package/lib/oldCode/publisher.js +96 -71
  58. package/lib/oldCode/publisher.js.map +1 -1
  59. package/lib/oldCode/service.js +294 -272
  60. package/lib/oldCode/service.js.map +1 -1
  61. package/lib/oldCode/session.js +82 -60
  62. package/lib/oldCode/session.js.map +1 -1
  63. package/lib/oldCode/stream.js +153 -125
  64. package/lib/oldCode/stream.js.map +1 -1
  65. package/lib/oldCode/subscriber.js +60 -35
  66. package/lib/oldCode/subscriber.js.map +1 -1
  67. package/lib/oldCode/tracer.js +179 -138
  68. package/lib/oldCode/tracer.js.map +1 -1
  69. package/lib/oldCode/utils/ImageFixer.js +66 -44
  70. package/lib/oldCode/utils/ImageFixer.js.map +1 -1
  71. package/lib/oldCode/webrtc/constants.js +102 -110
  72. package/lib/oldCode/webrtc/constants.js.map +1 -1
  73. package/lib/oldCode/webrtc/helper.js +176 -124
  74. package/lib/oldCode/webrtc/helper.js.map +1 -1
  75. package/lib/oldCode/webrtc/session-kms.js +408 -393
  76. package/lib/oldCode/webrtc/session-kms.js.map +1 -1
  77. package/lib/oldCode/webrtc/session-loopback.js +245 -227
  78. package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
  79. package/lib/oldCode/webrtc/session-turn.js +705 -658
  80. package/lib/oldCode/webrtc/session-turn.js.map +1 -1
  81. package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
  82. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
  83. package/lib/oldCode/webrtc/session.js +12 -6
  84. package/lib/oldCode/webrtc/session.js.map +1 -1
  85. package/lib/oldCode/webrtc/stream.js +526 -504
  86. package/lib/oldCode/webrtc/stream.js.map +1 -1
  87. package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
  88. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
  89. package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
  90. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
  91. package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
  92. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
  93. package/lib/qos/raw-qos.js +348 -274
  94. package/lib/qos/raw-qos.js.map +1 -1
  95. package/lib/webrtc-ie-shim.js +3386 -2985
  96. package/lib/webrtc-ie-shim.js.map +1 -1
  97. package/package.json +12 -15
@@ -1,412 +1,639 @@
1
1
  "use strict";
2
2
 
3
- var __extends = undefined && undefined.__extends || function () {
4
- var _extendStatics = function extendStatics(d, b) {
5
- _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
6
- d.__proto__ = b;
7
- } || function (d, b) {
8
- for (var p in b) {
9
- if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
10
- }
11
- };
12
- return _extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- _extendStatics(d, b);
16
- function __() {
17
- this.constructor = d;
18
- }
19
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3
+ var __extends = void 0 && (void 0).__extends || function () {
4
+ var _extendStatics = function extendStatics(d, b) {
5
+ _extendStatics = Object.setPrototypeOf || {
6
+ __proto__: []
7
+ } instanceof Array && function (d, b) {
8
+ d.__proto__ = b;
9
+ } || function (d, b) {
10
+ for (var p in b) {
11
+ if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
12
+ }
20
13
  };
14
+
15
+ return _extendStatics(d, b);
16
+ };
17
+
18
+ return function (d, b) {
19
+ _extendStatics(d, b);
20
+
21
+ function __() {
22
+ this.constructor = d;
23
+ }
24
+
25
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
26
+ };
21
27
  }();
22
- var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
23
- function adopt(value) {
24
- return value instanceof P ? value : new P(function (resolve) {
25
- resolve(value);
26
- });
28
+
29
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
30
+ function adopt(value) {
31
+ return value instanceof P ? value : new P(function (resolve) {
32
+ resolve(value);
33
+ });
34
+ }
35
+
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
27
43
  }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) {
30
- try {
31
- step(generator.next(value));
32
- } catch (e) {
33
- reject(e);
44
+
45
+ function rejected(value) {
46
+ try {
47
+ step(generator["throw"](value));
48
+ } catch (e) {
49
+ reject(e);
50
+ }
51
+ }
52
+
53
+ function step(result) {
54
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
55
+ }
56
+
57
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
58
+ });
59
+ };
60
+
61
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
62
+ var _ = {
63
+ label: 0,
64
+ sent: function sent() {
65
+ if (t[0] & 1) throw t[1];
66
+ return t[1];
67
+ },
68
+ trys: [],
69
+ ops: []
70
+ },
71
+ f,
72
+ y,
73
+ t,
74
+ g;
75
+ return g = {
76
+ next: verb(0),
77
+ "throw": verb(1),
78
+ "return": verb(2)
79
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
80
+ return this;
81
+ }), g;
82
+
83
+ function verb(n) {
84
+ return function (v) {
85
+ return step([n, v]);
86
+ };
87
+ }
88
+
89
+ function step(op) {
90
+ if (f) throw new TypeError("Generator is already executing.");
91
+
92
+ while (_) {
93
+ try {
94
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
95
+ if (y = 0, t) op = [op[0] & 2, t.value];
96
+
97
+ switch (op[0]) {
98
+ case 0:
99
+ case 1:
100
+ t = op;
101
+ break;
102
+
103
+ case 4:
104
+ _.label++;
105
+ return {
106
+ value: op[1],
107
+ done: false
108
+ };
109
+
110
+ case 5:
111
+ _.label++;
112
+ y = op[1];
113
+ op = [0];
114
+ continue;
115
+
116
+ case 7:
117
+ op = _.ops.pop();
118
+
119
+ _.trys.pop();
120
+
121
+ continue;
122
+
123
+ default:
124
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
125
+ _ = 0;
126
+ continue;
34
127
  }
35
- }
36
- function rejected(value) {
37
- try {
38
- step(generator["throw"](value));
39
- } catch (e) {
40
- reject(e);
128
+
129
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
130
+ _.label = op[1];
131
+ break;
41
132
  }
42
- }
43
- function step(result) {
44
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
45
- }
46
- step((generator = generator.apply(thisArg, _arguments || [])).next());
47
- });
48
- };
49
- var __generator = undefined && undefined.__generator || function (thisArg, body) {
50
- var _ = { label: 0, sent: function sent() {
51
- if (t[0] & 1) throw t[1];return t[1];
52
- }, trys: [], ops: [] },
53
- f,
54
- y,
55
- t,
56
- g;
57
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
58
- return this;
59
- }), g;
60
- function verb(n) {
61
- return function (v) {
62
- return step([n, v]);
63
- };
64
- }
65
- function step(op) {
66
- if (f) throw new TypeError("Generator is already executing.");
67
- while (_) {
68
- try {
69
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
- if (y = 0, t) op = [op[0] & 2, t.value];
71
- switch (op[0]) {
72
- case 0:case 1:
73
- t = op;break;
74
- case 4:
75
- _.label++;return { value: op[1], done: false };
76
- case 5:
77
- _.label++;y = op[1];op = [0];continue;
78
- case 7:
79
- op = _.ops.pop();_.trys.pop();continue;
80
- default:
81
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
82
- _ = 0;continue;
83
- }
84
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
- _.label = op[1];break;
86
- }
87
- if (op[0] === 6 && _.label < t[1]) {
88
- _.label = t[1];t = op;break;
89
- }
90
- if (t && _.label < t[2]) {
91
- _.label = t[2];_.ops.push(op);break;
92
- }
93
- if (t[2]) _.ops.pop();
94
- _.trys.pop();continue;
95
- }
96
- op = body.call(thisArg, _);
97
- } catch (e) {
98
- op = [6, e];y = 0;
99
- } finally {
100
- f = t = 0;
133
+
134
+ if (op[0] === 6 && _.label < t[1]) {
135
+ _.label = t[1];
136
+ t = op;
137
+ break;
138
+ }
139
+
140
+ if (t && _.label < t[2]) {
141
+ _.label = t[2];
142
+
143
+ _.ops.push(op);
144
+
145
+ break;
101
146
  }
102
- }if (op[0] & 5) throw op[1];return { value: op[0] ? op[1] : void 0, done: true };
147
+
148
+ if (t[2]) _.ops.pop();
149
+
150
+ _.trys.pop();
151
+
152
+ continue;
153
+ }
154
+
155
+ op = body.call(thisArg, _);
156
+ } catch (e) {
157
+ op = [6, e];
158
+ y = 0;
159
+ } finally {
160
+ f = t = 0;
161
+ }
103
162
  }
163
+
164
+ if (op[0] & 5) throw op[1];
165
+ return {
166
+ value: op[0] ? op[1] : void 0,
167
+ done: true
168
+ };
169
+ }
104
170
  };
105
- var __importDefault = undefined && undefined.__importDefault || function (mod) {
106
- return mod && mod.__esModule ? mod : { "default": mod };
171
+
172
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
173
+ return mod && mod.__esModule ? mod : {
174
+ "default": mod
175
+ };
107
176
  };
108
- Object.defineProperty(exports, "__esModule", { value: true });
177
+
178
+ Object.defineProperty(exports, "__esModule", {
179
+ value: true
180
+ });
109
181
  exports.OpentokMultiparty = void 0;
182
+
110
183
  var MultiParty_1 = require("./MultiParty");
184
+
111
185
  var MediaConstants_1 = require("../MediaConstants");
186
+
112
187
  var MediaTracer_1 = require("../MediaUtils/MediaTracer");
188
+
113
189
  var get_1 = __importDefault(require("lodash/get"));
190
+
114
191
  var filter_1 = __importDefault(require("lodash/filter"));
192
+
115
193
  var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
116
- var MediaCapabilitiesHelper_1 = require("./MediaCapabilitiesHelper");
117
- // eslint-disable-next-line @typescript-eslint/no-var-requires
194
+
195
+ var MediaCapabilitiesHelper_1 = require("./MediaCapabilitiesHelper"); // eslint-disable-next-line @typescript-eslint/no-var-requires
196
+
197
+
118
198
  var OT = require('@opentok/client');
119
- var trace = MediaTracer_1.getMediaTracer('Multiparty');
120
- // The preferred camera position to use for the video source
199
+
200
+ var trace = MediaTracer_1.getMediaTracer('Multiparty'); // The preferred camera position to use for the video source
201
+
121
202
  var OpentokFacingMode;
203
+
122
204
  (function (OpentokFacingMode) {
123
- OpentokFacingMode["USER"] = "user";
124
- OpentokFacingMode["ENVIRONMENT"] = "environment";
205
+ OpentokFacingMode["USER"] = "user";
206
+ OpentokFacingMode["ENVIRONMENT"] = "environment";
125
207
  })(OpentokFacingMode || (OpentokFacingMode = {}));
126
- var OpentokMultiparty = /** @class */function (_super) {
127
- __extends(OpentokMultiparty, _super);
128
- function OpentokMultiparty() {
129
- var _this = _super !== null && _super.apply(this, arguments) || this;
130
- _this.subscribers = [];
131
- _this.connect = function (credentials) {
132
- _this.credentials = credentials;
133
- try {
134
- _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
135
- } catch (err) {
136
- trace.error(JSON.stringify(err));
137
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectFailed, { meta: { err: JSON.stringify(err) } });
138
- return;
139
- }
140
- _this.session.on('connectionCreated', _this.connectionCreatedHandler);
141
- _this.session.on('connectionDestroyed', _this.connectionDestroyedHandler);
142
- _this.session.on('streamCreated', _this.streamCreatedHandler);
143
- _this.session.on('streamDestroyed', _this.streamDestroyedHandler);
144
- _this.session.connect(_this.credentials.token, function (error) {
145
- return __awaiter(_this, void 0, void 0, function () {
146
- return __generator(this, function (_a) {
147
- switch (_a.label) {
148
- case 0:
149
- if (error) {
150
- this.session.off();
151
- this.session = null;
152
- this.traceError(error);
153
- this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectFailed, { meta: { err: JSON.stringify(error) } });
154
- return [2 /*return*/];
155
- }
156
- if (this.settings.defaultCamera === MediaConstants_1.CameraTypes.NONE && this.settings.startWithAudioMuted) {
157
- trace.info('camera is none, no need to create publisher');
158
- return [2 /*return*/];
159
- }
160
- return [4 /*yield*/, this.createPublisher(this.settings)];
161
- case 1:
162
- _a.sent();
163
- return [2 /*return*/];
164
- }
165
- });
166
- });
167
- });
168
- };
169
- _this.disconnect = function () {
170
- try {
171
- trace.info('Disconnecting from session');
172
- if (_this.session) {
173
- _this.session.disconnect();
174
- trace.info('Disconnection from session completed');
175
- }
176
- } catch (err) {
177
- trace.error(JSON.stringify(err));
178
- }
179
- };
180
- _this.couldStartPublishVideo = function (settings) {
181
- return __awaiter(_this, void 0, void 0, function () {
182
- var mediaCapabilitiesHelper, err_1;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0:
186
- _a.trys.push([0, 2,, 3]);
187
- return [4 /*yield*/, MediaCapabilitiesHelper_1.MediaCapabilitiesHelper.init()];
188
- case 1:
189
- mediaCapabilitiesHelper = _a.sent();
190
- return [2 /*return*/, settings.defaultCamera !== MediaConstants_1.CameraTypes.NONE ? mediaCapabilitiesHelper.hasCamera() : false];
191
- case 2:
192
- err_1 = _a.sent();
193
- trace.error(JSON.stringify(err_1));
194
- throw err_1;
195
- case 3:
196
- return [2 /*return*/];
197
- }
198
- });
199
- });
200
- };
201
- _this.couldStartPublishAudio = function (settings) {
202
- return __awaiter(_this, void 0, void 0, function () {
203
- var mediaCapabilitiesHelper, err_2;
204
- return __generator(this, function (_a) {
205
- switch (_a.label) {
206
- case 0:
207
- _a.trys.push([0, 2,, 3]);
208
- return [4 /*yield*/, MediaCapabilitiesHelper_1.MediaCapabilitiesHelper.init()];
209
- case 1:
210
- mediaCapabilitiesHelper = _a.sent();
211
- return [2 /*return*/, !settings.startWithAudioMuted && mediaCapabilitiesHelper.hasMicrophone()];
212
- case 2:
213
- err_2 = _a.sent();
214
- trace.error(JSON.stringify(err_2));
215
- throw err_2;
216
- case 3:
217
- return [2 /*return*/];
218
- }
219
- });
220
- });
221
- };
222
- _this.createPublisher = function (settingsForPublisher) {
223
- return __awaiter(_this, void 0, void 0, function () {
224
- var settings, couldStartPublishVideo, couldStartPublishAudio;
225
- return __generator(this, function (_a) {
226
- switch (_a.label) {
227
- case 0:
228
- settings = cloneDeep_1.default(settingsForPublisher);
229
- return [4 /*yield*/, this.couldStartPublishVideo(settings)];
230
- case 1:
231
- couldStartPublishVideo = _a.sent();
232
- return [4 /*yield*/, this.couldStartPublishAudio(settings)];
233
- case 2:
234
- couldStartPublishAudio = _a.sent();
235
- if (!couldStartPublishVideo && !couldStartPublishAudio) {
236
- // FIXME: use emitter
237
- trace.error('could not create a publisher, due to lack of media capabilities or settings');
238
- return [2 /*return*/];
239
- }
240
- if (!couldStartPublishVideo) {
241
- settings.defaultCamera = MediaConstants_1.CameraTypes.NONE;
242
- }
243
- if (!couldStartPublishAudio) {
244
- settings.startWithAudioMuted = true;
245
- }
246
- if (!this.currentPublisher) {
247
- this.initPublisher(settings);
248
- this.session.publish(this.currentPublisher, this.traceError);
249
- }
250
- return [2 /*return*/];
251
- }
252
- });
253
- });
254
- };
255
- _this.publishAudio = function (value) {
256
- return __awaiter(_this, void 0, void 0, function () {
257
- var settings, _a;
258
- return __generator(this, function (_b) {
259
- switch (_b.label) {
260
- case 0:
261
- settings = cloneDeep_1.default(this.settings);
262
- settings.startWithAudioMuted = !value;
263
- _a = value;
264
- if (!_a) return [3 /*break*/, 2];
265
- return [4 /*yield*/, this.couldStartPublishAudio(settings)];
266
- case 1:
267
- _a = !_b.sent();
268
- _b.label = 2;
269
- case 2:
270
- if (_a) {
271
- trace.error('could not publish audio');
272
- return [2 /*return*/];
273
- }
274
- if (!this.currentPublisher) {
275
- this.createPublisher(settings);
276
- } else {
277
- this.currentPublisher.publishAudio(value);
278
- }
279
- return [2 /*return*/];
280
- }
281
- });
282
- });
283
- };
284
- _this.publishVideo = function (value) {
285
- return __awaiter(_this, void 0, void 0, function () {
286
- var settings, _a;
287
- return __generator(this, function (_b) {
288
- switch (_b.label) {
289
- case 0:
290
- settings = cloneDeep_1.default(this.settings);
291
- settings.defaultCamera = value ? this.settings.defaultCamera : MediaConstants_1.CameraTypes.NONE;
292
- _a = value;
293
- if (!_a) return [3 /*break*/, 2];
294
- return [4 /*yield*/, this.couldStartPublishVideo(settings)];
295
- case 1:
296
- _a = !_b.sent();
297
- _b.label = 2;
298
- case 2:
299
- if (_a) {
300
- trace.error('could not publish video');
301
- return [2 /*return*/];
302
- }
303
- if (!this.currentPublisher) {
304
- this.createPublisher(settings);
305
- } else {
306
- this.currentPublisher.publishVideo(value);
307
- }
308
- return [2 /*return*/];
208
+
209
+ var OpentokMultiparty =
210
+ /** @class */
211
+ function (_super) {
212
+ __extends(OpentokMultiparty, _super);
213
+
214
+ function OpentokMultiparty() {
215
+ var _this = _super !== null && _super.apply(this, arguments) || this;
216
+
217
+ _this.subscribers = [];
218
+
219
+ _this.connect = function (credentials) {
220
+ _this.credentials = credentials;
221
+
222
+ try {
223
+ _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
224
+ } catch (err) {
225
+ trace.error(JSON.stringify(err));
226
+
227
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectFailed, {
228
+ meta: {
229
+ err: JSON.stringify(err)
230
+ }
231
+ });
232
+
233
+ return;
234
+ }
235
+
236
+ _this.session.on('connectionCreated', _this.connectionCreatedHandler);
237
+
238
+ _this.session.on('connectionDestroyed', _this.connectionDestroyedHandler);
239
+
240
+ _this.session.on('streamCreated', _this.streamCreatedHandler);
241
+
242
+ _this.session.on('streamDestroyed', _this.streamDestroyedHandler);
243
+
244
+ _this.session.connect(_this.credentials.token, function (error) {
245
+ return __awaiter(_this, void 0, void 0, function () {
246
+ return __generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0:
249
+ if (error) {
250
+ this.session.off();
251
+ this.session = null;
252
+ this.traceError(error);
253
+ this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectFailed, {
254
+ meta: {
255
+ err: JSON.stringify(error)
309
256
  }
310
- });
311
- });
312
- };
313
- _this.initPublisher = function (settings) {
314
- var properties = {
315
- insertMode: 'append',
316
- width: '200',
317
- height: '200',
318
- publishAudio: !settings.startWithAudioMuted,
319
- publishVideo: settings.defaultCamera !== MediaConstants_1.CameraTypes.NONE,
320
- facingMode: settings.defaultCamera === MediaConstants_1.CameraTypes.FRONT ? OpentokFacingMode.USER : OpentokFacingMode.ENVIRONMENT
321
- };
322
- _this.currentPublisher = OT.initPublisher(MultiParty_1.participateDomId + "1", properties, _this.traceError);
323
- if (!_this.currentPublisher) {
324
- trace.error('failed to init publisher');
325
- } else {
326
- _this.currentPublisher.on('videoElementCreated', function (event) {
327
- trace.info('videoElementCreated', event);
328
- });
329
- _this.currentPublisher.on('streamDestroyed', function (event) {
330
- trace.info('Publisher stream destroyed', event);
331
- });
332
- _this.currentPublisher.on('streamCreated', function (event) {
333
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamCreated, event);
334
- trace.info('publisher stream created', event, get_1.default(_this.currentPublisher, 'stream.hasAudio'));
335
- });
336
- }
337
- };
338
- _this.streamCreatedHandler = function (event) {
339
- trace.info('streamCreatedHandler', event.stream);
340
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamCreated, event);
341
- var stream = event.stream;
342
- var connection = (stream || { connection: null }).connection;
343
- if (!_this.ownConnectionId || !stream || connection.connectionId === _this.ownConnectionId) {
344
- return;
345
- }
346
- if (_this.subscribers.length >= MultiParty_1.maxParticipantsNumber - 1) {
347
- trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiParty_1.maxParticipantsNumber);
348
- } else {
349
- //fixme: use width and height passed in settings
350
- var properties = {
351
- insertMode: 'append',
352
- width: '200',
353
- height: '200'
354
- };
355
- var subscriber_1 = _this.session.subscribe(event.stream, "" + MultiParty_1.participateDomId + _this.subscribers.length, properties, function (err) {
356
- _this.traceError(err);
357
- subscriber_1.on('videoElementCreated', function (event) {
358
- trace.info('videoElementCreated', event);
359
- });
360
- });
361
- _this.subscribers.push({
362
- subscriber: subscriber_1,
363
- connectionId: connection.connectionId,
364
- clientRole: (connection === null || connection === void 0 ? void 0 : connection.data) ? JSON.parse(connection.data).clientRole : 'default' //fixme temp workaround for BE
365
- });
366
- }
367
- };
368
- _this.streamDestroyedHandler = function (event) {
369
- trace.info('streamDestroyedHandler', event);
370
- var stream = event.stream;
371
- var destroyedConnectionId = stream && stream.connection && stream.connection.connectionId;
372
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamDestroyed, { meta: { event: JSON.stringify(event) } });
373
- _this.subscribers = filter_1.default(_this.subscribers, function (subscriber) {
374
- return subscriber.connectionId !== destroyedConnectionId;
375
- });
376
- };
377
- _this.connectionCreatedHandler = function (event) {
378
- trace.info('connectionCreatedHandler', event);
379
- var connection = event.connection;
380
- if (!_this.ownConnectionId || !connection) {
381
- return;
382
- }
383
- var clientRole = connection.data ? JSON.parse(connection.data).clientRole : 'default'; //fixme temp workaround for BE
384
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectionCreated, { meta: { clientRole: clientRole, event: JSON.stringify(event) } });
385
- };
386
- _this.connectionDestroyedHandler = function (event) {
387
- var connection = event.connection;
388
- if (!_this.ownConnectionId || !connection || connection.connectionId !== _this.ownConnectionId) {
389
- return;
257
+ });
258
+ return [2
259
+ /*return*/
260
+ ];
261
+ }
262
+
263
+ if (this.settings.defaultCamera === MediaConstants_1.CameraTypes.NONE && this.settings.startWithAudioMuted) {
264
+ trace.info('camera is none, no need to create publisher');
265
+ return [2
266
+ /*return*/
267
+ ];
268
+ }
269
+
270
+ return [4
271
+ /*yield*/
272
+ , this.createPublisher(this.settings)];
273
+
274
+ case 1:
275
+ _a.sent();
276
+
277
+ return [2
278
+ /*return*/
279
+ ];
390
280
  }
391
- _this.session = null;
392
- trace.info('connectionDestroyedHandler', event);
393
- _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectionDestroyed, { meta: { event: JSON.stringify(event) } });
394
- };
395
- _this.traceError = function (error) {
396
- trace.error(error);
281
+ });
282
+ });
283
+ });
284
+ };
285
+
286
+ _this.disconnect = function () {
287
+ try {
288
+ trace.info('Disconnecting from session');
289
+
290
+ if (_this.session) {
291
+ _this.session.disconnect();
292
+
293
+ trace.info('Disconnection from session completed');
294
+ }
295
+ } catch (err) {
296
+ trace.error(JSON.stringify(err));
297
+ }
298
+ };
299
+
300
+ _this.couldStartPublishVideo = function (settings) {
301
+ return __awaiter(_this, void 0, void 0, function () {
302
+ var mediaCapabilitiesHelper, err_1;
303
+ return __generator(this, function (_a) {
304
+ switch (_a.label) {
305
+ case 0:
306
+ _a.trys.push([0, 2,, 3]);
307
+
308
+ return [4
309
+ /*yield*/
310
+ , MediaCapabilitiesHelper_1.MediaCapabilitiesHelper.init()];
311
+
312
+ case 1:
313
+ mediaCapabilitiesHelper = _a.sent();
314
+ return [2
315
+ /*return*/
316
+ , settings.defaultCamera !== MediaConstants_1.CameraTypes.NONE ? mediaCapabilitiesHelper.hasCamera() : false];
317
+
318
+ case 2:
319
+ err_1 = _a.sent();
320
+ trace.error(JSON.stringify(err_1));
321
+ throw err_1;
322
+
323
+ case 3:
324
+ return [2
325
+ /*return*/
326
+ ];
327
+ }
328
+ });
329
+ });
330
+ };
331
+
332
+ _this.couldStartPublishAudio = function (settings) {
333
+ return __awaiter(_this, void 0, void 0, function () {
334
+ var mediaCapabilitiesHelper, err_2;
335
+ return __generator(this, function (_a) {
336
+ switch (_a.label) {
337
+ case 0:
338
+ _a.trys.push([0, 2,, 3]);
339
+
340
+ return [4
341
+ /*yield*/
342
+ , MediaCapabilitiesHelper_1.MediaCapabilitiesHelper.init()];
343
+
344
+ case 1:
345
+ mediaCapabilitiesHelper = _a.sent();
346
+ return [2
347
+ /*return*/
348
+ , !settings.startWithAudioMuted && mediaCapabilitiesHelper.hasMicrophone()];
349
+
350
+ case 2:
351
+ err_2 = _a.sent();
352
+ trace.error(JSON.stringify(err_2));
353
+ throw err_2;
354
+
355
+ case 3:
356
+ return [2
357
+ /*return*/
358
+ ];
359
+ }
360
+ });
361
+ });
362
+ };
363
+
364
+ _this.createPublisher = function (settingsForPublisher) {
365
+ return __awaiter(_this, void 0, void 0, function () {
366
+ var settings, couldStartPublishVideo, couldStartPublishAudio;
367
+ return __generator(this, function (_a) {
368
+ switch (_a.label) {
369
+ case 0:
370
+ settings = cloneDeep_1["default"](settingsForPublisher);
371
+ return [4
372
+ /*yield*/
373
+ , this.couldStartPublishVideo(settings)];
374
+
375
+ case 1:
376
+ couldStartPublishVideo = _a.sent();
377
+ return [4
378
+ /*yield*/
379
+ , this.couldStartPublishAudio(settings)];
380
+
381
+ case 2:
382
+ couldStartPublishAudio = _a.sent();
383
+
384
+ if (!couldStartPublishVideo && !couldStartPublishAudio) {
385
+ // FIXME: use emitter
386
+ trace.error('could not create a publisher, due to lack of media capabilities or settings');
387
+ return [2
388
+ /*return*/
389
+ ];
390
+ }
391
+
392
+ if (!couldStartPublishVideo) {
393
+ settings.defaultCamera = MediaConstants_1.CameraTypes.NONE;
394
+ }
395
+
396
+ if (!couldStartPublishAudio) {
397
+ settings.startWithAudioMuted = true;
398
+ }
399
+
400
+ if (!this.currentPublisher) {
401
+ this.initPublisher(settings);
402
+ this.session.publish(this.currentPublisher, this.traceError);
403
+ }
404
+
405
+ return [2
406
+ /*return*/
407
+ ];
408
+ }
409
+ });
410
+ });
411
+ };
412
+
413
+ _this.publishAudio = function (value) {
414
+ return __awaiter(_this, void 0, void 0, function () {
415
+ var settings, _a;
416
+
417
+ return __generator(this, function (_b) {
418
+ switch (_b.label) {
419
+ case 0:
420
+ settings = cloneDeep_1["default"](this.settings);
421
+ settings.startWithAudioMuted = !value;
422
+ _a = value;
423
+ if (!_a) return [3
424
+ /*break*/
425
+ , 2];
426
+ return [4
427
+ /*yield*/
428
+ , this.couldStartPublishAudio(settings)];
429
+
430
+ case 1:
431
+ _a = !_b.sent();
432
+ _b.label = 2;
433
+
434
+ case 2:
435
+ if (_a) {
436
+ trace.error('could not publish audio');
437
+ return [2
438
+ /*return*/
439
+ ];
440
+ }
441
+
442
+ if (!this.currentPublisher) {
443
+ this.createPublisher(settings);
444
+ } else {
445
+ this.currentPublisher.publishAudio(value);
446
+ }
447
+
448
+ return [2
449
+ /*return*/
450
+ ];
451
+ }
452
+ });
453
+ });
454
+ };
455
+
456
+ _this.publishVideo = function (value) {
457
+ return __awaiter(_this, void 0, void 0, function () {
458
+ var settings, _a;
459
+
460
+ return __generator(this, function (_b) {
461
+ switch (_b.label) {
462
+ case 0:
463
+ settings = cloneDeep_1["default"](this.settings);
464
+ settings.defaultCamera = value ? this.settings.defaultCamera : MediaConstants_1.CameraTypes.NONE;
465
+ _a = value;
466
+ if (!_a) return [3
467
+ /*break*/
468
+ , 2];
469
+ return [4
470
+ /*yield*/
471
+ , this.couldStartPublishVideo(settings)];
472
+
473
+ case 1:
474
+ _a = !_b.sent();
475
+ _b.label = 2;
476
+
477
+ case 2:
478
+ if (_a) {
479
+ trace.error('could not publish video');
480
+ return [2
481
+ /*return*/
482
+ ];
483
+ }
484
+
485
+ if (!this.currentPublisher) {
486
+ this.createPublisher(settings);
487
+ } else {
488
+ this.currentPublisher.publishVideo(value);
489
+ }
490
+
491
+ return [2
492
+ /*return*/
493
+ ];
494
+ }
495
+ });
496
+ });
497
+ };
498
+
499
+ _this.initPublisher = function (settings) {
500
+ var properties = {
501
+ insertMode: 'append',
502
+ width: '200',
503
+ height: '200',
504
+ publishAudio: !settings.startWithAudioMuted,
505
+ publishVideo: settings.defaultCamera !== MediaConstants_1.CameraTypes.NONE,
506
+ facingMode: settings.defaultCamera === MediaConstants_1.CameraTypes.FRONT ? OpentokFacingMode.USER : OpentokFacingMode.ENVIRONMENT
507
+ };
508
+ _this.currentPublisher = OT.initPublisher(MultiParty_1.participateDomId + "1", properties, _this.traceError);
509
+
510
+ if (!_this.currentPublisher) {
511
+ trace.error('failed to init publisher');
512
+ } else {
513
+ _this.currentPublisher.on('videoElementCreated', function (event) {
514
+ trace.info('videoElementCreated', event);
515
+ });
516
+
517
+ _this.currentPublisher.on('streamDestroyed', function (event) {
518
+ trace.info('Publisher stream destroyed', event);
519
+ });
520
+
521
+ _this.currentPublisher.on('streamCreated', function (event) {
522
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamCreated, event);
523
+
524
+ trace.info('publisher stream created', event, get_1["default"](_this.currentPublisher, 'stream.hasAudio'));
525
+ });
526
+ }
527
+ };
528
+
529
+ _this.streamCreatedHandler = function (event) {
530
+ trace.info('streamCreatedHandler', event.stream);
531
+
532
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamCreated, event);
533
+
534
+ var stream = event.stream;
535
+ var connection = (stream || {
536
+ connection: null
537
+ }).connection;
538
+
539
+ if (!_this.ownConnectionId || !stream || connection.connectionId === _this.ownConnectionId) {
540
+ return;
541
+ }
542
+
543
+ if (_this.subscribers.length >= MultiParty_1.maxParticipantsNumber - 1) {
544
+ trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiParty_1.maxParticipantsNumber);
545
+ } else {
546
+ //fixme: use width and height passed in settings
547
+ var properties = {
548
+ insertMode: 'append',
549
+ width: '200',
550
+ height: '200'
397
551
  };
398
- return _this;
399
- }
400
- Object.defineProperty(OpentokMultiparty.prototype, "ownConnectionId", {
401
- get: function get() {
402
- return this.session && this.session.connection && this.session.connection.connectionId;
403
- },
404
- enumerable: false,
405
- configurable: true
406
- });
407
- return OpentokMultiparty;
552
+
553
+ var subscriber_1 = _this.session.subscribe(event.stream, "" + MultiParty_1.participateDomId + _this.subscribers.length, properties, function (err) {
554
+ _this.traceError(err);
555
+
556
+ subscriber_1.on('videoElementCreated', function (event) {
557
+ trace.info('videoElementCreated', event);
558
+ });
559
+ });
560
+
561
+ _this.subscribers.push({
562
+ subscriber: subscriber_1,
563
+ connectionId: connection.connectionId,
564
+ clientRole: (connection === null || connection === void 0 ? void 0 : connection.data) ? JSON.parse(connection.data).clientRole : 'default' //fixme temp workaround for BE
565
+
566
+ });
567
+ }
568
+ };
569
+
570
+ _this.streamDestroyedHandler = function (event) {
571
+ trace.info('streamDestroyedHandler', event);
572
+ var stream = event.stream;
573
+ var destroyedConnectionId = stream && stream.connection && stream.connection.connectionId;
574
+
575
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.streamDestroyed, {
576
+ meta: {
577
+ event: JSON.stringify(event)
578
+ }
579
+ });
580
+
581
+ _this.subscribers = filter_1["default"](_this.subscribers, function (subscriber) {
582
+ return subscriber.connectionId !== destroyedConnectionId;
583
+ });
584
+ };
585
+
586
+ _this.connectionCreatedHandler = function (event) {
587
+ trace.info('connectionCreatedHandler', event);
588
+ var connection = event.connection;
589
+
590
+ if (!_this.ownConnectionId || !connection) {
591
+ return;
592
+ }
593
+
594
+ var clientRole = connection.data ? JSON.parse(connection.data).clientRole : 'default'; //fixme temp workaround for BE
595
+
596
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectionCreated, {
597
+ meta: {
598
+ clientRole: clientRole,
599
+ event: JSON.stringify(event)
600
+ }
601
+ });
602
+ };
603
+
604
+ _this.connectionDestroyedHandler = function (event) {
605
+ var connection = event.connection;
606
+
607
+ if (!_this.ownConnectionId || !connection || connection.connectionId !== _this.ownConnectionId) {
608
+ return;
609
+ }
610
+
611
+ _this.session = null;
612
+ trace.info('connectionDestroyedHandler', event);
613
+
614
+ _this.emit(MultiParty_1.MULTI_PARTY_EVENTS.connectionDestroyed, {
615
+ meta: {
616
+ event: JSON.stringify(event)
617
+ }
618
+ });
619
+ };
620
+
621
+ _this.traceError = function (error) {
622
+ trace.error(error);
623
+ };
624
+
625
+ return _this;
626
+ }
627
+
628
+ Object.defineProperty(OpentokMultiparty.prototype, "ownConnectionId", {
629
+ get: function get() {
630
+ return this.session && this.session.connection && this.session.connection.connectionId;
631
+ },
632
+ enumerable: false,
633
+ configurable: true
634
+ });
635
+ return OpentokMultiparty;
408
636
  }(MultiParty_1.MultiParty);
409
- exports.OpentokMultiparty = OpentokMultiparty;
410
637
 
411
- //# sourceMappingURL=OpentokMultiparty.js.map
638
+ exports.OpentokMultiparty = OpentokMultiparty;
412
639
  //# sourceMappingURL=OpentokMultiparty.js.map