@techsee/techsee-media-service 18.6.1 → 19.1.0

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 (141) hide show
  1. package/lib/LocalStreamManager.d.ts +1 -0
  2. package/lib/LocalStreamManager.d.ts.map +1 -1
  3. package/lib/LocalStreamManager.js +320 -441
  4. package/lib/LocalStreamManager.js.map +1 -1
  5. package/lib/MediaConstants.d.ts +1 -0
  6. package/lib/MediaConstants.d.ts.map +1 -1
  7. package/lib/MediaConstants.js +53 -95
  8. package/lib/MediaConstants.js.map +1 -1
  9. package/lib/MediaContracts.d.ts +1 -0
  10. package/lib/MediaContracts.d.ts.map +1 -1
  11. package/lib/MediaContracts.js +2 -5
  12. package/lib/MediaContracts.js.map +1 -1
  13. package/lib/MediaPublisher.d.ts +1 -0
  14. package/lib/MediaPublisher.d.ts.map +1 -1
  15. package/lib/MediaPublisher.js +36 -49
  16. package/lib/MediaPublisher.js.map +1 -1
  17. package/lib/MediaServiceBase.d.ts +1 -0
  18. package/lib/MediaServiceBase.d.ts.map +1 -1
  19. package/lib/MediaServiceBase.js +687 -937
  20. package/lib/MediaServiceBase.js.map +1 -1
  21. package/lib/MediaSession/MediaServer.d.ts +1 -0
  22. package/lib/MediaSession/MediaServer.d.ts.map +1 -1
  23. package/lib/MediaSession/MediaServer.js +372 -517
  24. package/lib/MediaSession/MediaServer.js.map +1 -1
  25. package/lib/MediaSession/MediaSessionBase.d.ts +1 -0
  26. package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
  27. package/lib/MediaSession/MediaSessionBase.js +88 -127
  28. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  29. package/lib/MediaSession/SessionOpentok.d.ts +1 -0
  30. package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
  31. package/lib/MediaSession/SessionOpentok.js +357 -503
  32. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  33. package/lib/MediaSession/SessionTurn.d.ts +1 -0
  34. package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
  35. package/lib/MediaSession/SessionTurn.js +431 -613
  36. package/lib/MediaSession/SessionTurn.js.map +1 -1
  37. package/lib/MediaSession/TurnConstants.d.ts +1 -0
  38. package/lib/MediaSession/TurnConstants.d.ts.map +1 -1
  39. package/lib/MediaSession/TurnConstants.js +17 -32
  40. package/lib/MediaSession/TurnConstants.js.map +1 -1
  41. package/lib/MediaSubscriber.d.ts +1 -0
  42. package/lib/MediaSubscriber.d.ts.map +1 -1
  43. package/lib/MediaSubscriber.js +189 -245
  44. package/lib/MediaSubscriber.js.map +1 -1
  45. package/lib/MediaUtils/Compatibility.d.ts +1 -0
  46. package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
  47. package/lib/MediaUtils/Compatibility.js +129 -283
  48. package/lib/MediaUtils/Compatibility.js.map +1 -1
  49. package/lib/MediaUtils/MediaDomUtils.d.ts +1 -0
  50. package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
  51. package/lib/MediaUtils/MediaDomUtils.js +184 -252
  52. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  53. package/lib/MediaUtils/MediaTracer.d.ts +1 -0
  54. package/lib/MediaUtils/MediaTracer.d.ts.map +1 -1
  55. package/lib/MediaUtils/MediaTracer.js +3 -10
  56. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  57. package/lib/MediaUtils/index.d.ts +1 -0
  58. package/lib/MediaUtils/index.d.ts.map +1 -1
  59. package/lib/MediaUtils/index.js +3 -13
  60. package/lib/MediaUtils/index.js.map +1 -1
  61. package/lib/MultiParty/DetectWebRtcService.d.ts +1 -0
  62. package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -1
  63. package/lib/MultiParty/DetectWebRtcService.js +92 -241
  64. package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
  65. package/lib/MultiParty/MediaCapabilitiesService.d.ts +1 -0
  66. package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -1
  67. package/lib/MultiParty/MediaCapabilitiesService.js +143 -312
  68. package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -1
  69. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +1 -0
  70. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -1
  71. package/lib/MultiParty/MediaCapabilitiesUtils.js +95 -277
  72. package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -1
  73. package/lib/MultiParty/MediaTracer.d.ts +1 -0
  74. package/lib/MultiParty/MediaTracer.d.ts.map +1 -1
  75. package/lib/MultiParty/MediaTracer.js +3 -10
  76. package/lib/MultiParty/MediaTracer.js.map +1 -1
  77. package/lib/MultiParty/MultiPartyService.d.ts +1 -0
  78. package/lib/MultiParty/MultiPartyService.d.ts.map +1 -1
  79. package/lib/MultiParty/MultiPartyService.js +24 -47
  80. package/lib/MultiParty/MultiPartyService.js.map +1 -1
  81. package/lib/MultiParty/MultiPartyServiceFactory.d.ts +2 -1
  82. package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -1
  83. package/lib/MultiParty/MultiPartyServiceFactory.js +7 -15
  84. package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -1
  85. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +1 -0
  86. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -1
  87. package/lib/MultiParty/MultipartyServiceEventTypes.js +11 -15
  88. package/lib/MultiParty/MultipartyServiceEventTypes.js.map +1 -1
  89. package/lib/MultiParty/index.d.ts +1 -0
  90. package/lib/MultiParty/index.d.ts.map +1 -1
  91. package/lib/MultiParty/index.js +15 -35
  92. package/lib/MultiParty/index.js.map +1 -1
  93. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts +2 -1
  94. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -1
  95. package/lib/MultiParty/opentok/OpentokMultiPartyService.js +457 -839
  96. package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -1
  97. package/lib/MultiParty/opentok/OpentokPublisher.d.ts +1 -0
  98. package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -1
  99. package/lib/MultiParty/opentok/OpentokPublisher.js +107 -269
  100. package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -1
  101. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts +1 -0
  102. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts.map +1 -1
  103. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js +34 -54
  104. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -1
  105. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts +1 -0
  106. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts.map +1 -1
  107. package/lib/MultiParty/opentok/OpentokScreenPublisher.js +40 -77
  108. package/lib/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -1
  109. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +1 -0
  110. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +1 -1
  111. package/lib/MultiParty/opentok/OpentokSubscriber.js +20 -28
  112. package/lib/MultiParty/opentok/OpentokSubscriber.js.map +1 -1
  113. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts +1 -0
  114. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts.map +1 -1
  115. package/lib/MultiParty/opentok/OpentokVideoPublisher.js +150 -355
  116. package/lib/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -1
  117. package/lib/MultiParty/opentok/trace.d.ts +1 -0
  118. package/lib/MultiParty/opentok/trace.d.ts.map +1 -1
  119. package/lib/MultiParty/opentok/trace.js +11 -24
  120. package/lib/MultiParty/opentok/trace.js.map +1 -1
  121. package/lib/MultiParty/types.d.ts +1 -0
  122. package/lib/MultiParty/types.d.ts.map +1 -1
  123. package/lib/MultiParty/types.js +2 -5
  124. package/lib/MultiParty/types.js.map +1 -1
  125. package/lib/MultiParty/utils.d.ts +1 -0
  126. package/lib/MultiParty/utils.d.ts.map +1 -1
  127. package/lib/MultiParty/utils.js +5 -15
  128. package/lib/MultiParty/utils.js.map +1 -1
  129. package/lib/TechseeMediaStream.d.ts +1 -0
  130. package/lib/TechseeMediaStream.d.ts.map +1 -1
  131. package/lib/TechseeMediaStream.js +53 -61
  132. package/lib/TechseeMediaStream.js.map +1 -1
  133. package/lib/qos/raw-qos.d.ts +29 -0
  134. package/lib/qos/raw-qos.d.ts.map +1 -0
  135. package/lib/qos/raw-qos.js +247 -382
  136. package/lib/qos/raw-qos.js.map +1 -1
  137. package/lib/webrtc-ie-shim.d.ts +4 -0
  138. package/lib/webrtc-ie-shim.d.ts.map +1 -0
  139. package/lib/webrtc-ie-shim.js +1999 -3454
  140. package/lib/webrtc-ie-shim.js.map +1 -1
  141. package/package.json +42 -46
@@ -1,872 +1,490 @@
1
1
  "use strict";
2
-
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
- }
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
13
8
  };
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
- };
27
- }();
28
-
29
- var __assign = void 0 && (void 0).__assign || function () {
30
- __assign = Object.assign || function (t) {
31
- for (var s, i = 1, n = arguments.length; i < n; i++) {
32
- s = arguments[i];
33
-
34
- for (var p in s) {
35
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
- }
37
- }
38
-
39
- return t;
40
- };
41
-
42
- return __assign.apply(this, arguments);
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
43
27
  };
44
-
45
- var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
46
- function adopt(value) {
47
- return value instanceof P ? value : new P(function (resolve) {
48
- resolve(value);
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
49
35
  });
50
- }
51
-
52
- return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) {
54
- try {
55
- step(generator.next(value));
56
- } catch (e) {
57
- reject(e);
58
- }
59
- }
60
-
61
- function rejected(value) {
62
- try {
63
- step(generator["throw"](value));
64
- } catch (e) {
65
- reject(e);
66
- }
67
- }
68
-
69
- function step(result) {
70
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
71
- }
72
-
73
- step((generator = generator.apply(thisArg, _arguments || [])).next());
74
- });
75
36
  };
76
-
77
- var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
78
- var _ = {
79
- label: 0,
80
- sent: function sent() {
81
- if (t[0] & 1) throw t[1];
82
- return t[1];
83
- },
84
- trys: [],
85
- ops: []
86
- },
87
- f,
88
- y,
89
- t,
90
- g;
91
- return g = {
92
- next: verb(0),
93
- "throw": verb(1),
94
- "return": verb(2)
95
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
96
- return this;
97
- }), g;
98
-
99
- function verb(n) {
100
- return function (v) {
101
- return step([n, v]);
102
- };
103
- }
104
-
105
- function step(op) {
106
- if (f) throw new TypeError("Generator is already executing.");
107
-
108
- while (_) {
109
- try {
110
- 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;
111
- if (y = 0, t) op = [op[0] & 2, t.value];
112
-
113
- switch (op[0]) {
114
- case 0:
115
- case 1:
116
- t = op;
117
- break;
118
-
119
- case 4:
120
- _.label++;
121
- return {
122
- value: op[1],
123
- done: false
124
- };
125
-
126
- case 5:
127
- _.label++;
128
- y = op[1];
129
- op = [0];
130
- continue;
131
-
132
- case 7:
133
- op = _.ops.pop();
134
-
135
- _.trys.pop();
136
-
137
- continue;
138
-
139
- default:
140
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
141
- _ = 0;
142
- continue;
143
- }
144
-
145
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
146
- _.label = op[1];
147
- break;
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
148
58
  }
149
-
150
- if (op[0] === 6 && _.label < t[1]) {
151
- _.label = t[1];
152
- t = op;
153
- break;
154
- }
155
-
156
- if (t && _.label < t[2]) {
157
- _.label = t[2];
158
-
159
- _.ops.push(op);
160
-
161
- break;
162
- }
163
-
164
- if (t[2]) _.ops.pop();
165
-
166
- _.trys.pop();
167
-
168
- continue;
169
- }
170
-
171
- op = body.call(thisArg, _);
172
- } catch (e) {
173
- op = [6, e];
174
- y = 0;
175
- } finally {
176
- f = t = 0;
177
- }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
178
62
  }
179
-
180
- if (op[0] & 5) throw op[1];
181
- return {
182
- value: op[0] ? op[1] : void 0,
183
- done: true
184
- };
185
- }
186
63
  };
187
-
188
- var __spreadArrays = void 0 && (void 0).__spreadArrays || function () {
189
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
190
- s += arguments[i].length;
191
- }
192
-
193
- for (var r = Array(s), k = 0, i = 0; i < il; i++) {
194
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
195
- r[k] = a[j];
64
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
+ if (ar || !(i in from)) {
67
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
+ ar[i] = from[i];
69
+ }
196
70
  }
197
- }
198
-
199
- return r;
71
+ return to.concat(ar || Array.prototype.slice.call(from));
200
72
  };
201
-
202
- Object.defineProperty(exports, "__esModule", {
203
- value: true
204
- });
73
+ Object.defineProperty(exports, "__esModule", { value: true });
205
74
  exports.OpentokMultiPartyService = void 0;
206
-
207
75
  var MediaTracer_1 = require("../MediaTracer");
208
-
209
76
  var MediaCapabilitiesService_1 = require("../MediaCapabilitiesService");
210
-
211
77
  var MediaCapabilitiesUtils_1 = require("../MediaCapabilitiesUtils");
212
-
213
78
  var MultiPartyService_1 = require("../MultiPartyService");
214
-
215
79
  var MultipartyServiceEventTypes_1 = require("../MultipartyServiceEventTypes");
216
-
217
80
  var OpentokVideoPublisher_1 = require("./OpentokVideoPublisher");
218
-
219
81
  var OpentokScreenPublisher_1 = require("./OpentokScreenPublisher");
220
-
221
82
  var OpentokSubscriber_1 = require("./OpentokSubscriber");
222
-
223
83
  var utils_1 = require("../utils");
224
-
225
84
  var trace_1 = require("./trace");
226
-
227
85
  var MediaConstants_1 = require("../../MediaConstants");
228
-
229
- var trace = MediaTracer_1.getMediaTracer('Multiparty');
230
-
231
- var OpentokMultiPartyService =
232
- /** @class */
233
- function (_super) {
234
- __extends(OpentokMultiPartyService, _super);
235
-
236
- function OpentokMultiPartyService(getParticipantId) {
237
- var _this = _super.call(this) || this;
238
-
239
- _this.getParticipantId = getParticipantId;
240
- _this.enableDesktopSharing = false;
241
- _this.backgroundImageURI = MultiPartyService_1.DEFAULT_AVATAR_URI;
242
- _this.subscriberList = [];
243
-
244
- _this.setBackgroundImageURI = function (uri) {
245
- _this.backgroundImageURI = uri || MultiPartyService_1.DEFAULT_AVATAR_URI;
246
- };
247
-
248
- _this.connect = function (sessionSettings, credentials) {
249
- try {
250
- _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
251
-
252
- _this.session.on('connectionCreated', _this.connectionCreatedHandler);
253
-
254
- _this.session.on('connectionDestroyed', _this.connectionDestroyedHandler);
255
-
256
- _this.session.on('streamCreated', _this.streamCreatedHandler);
257
-
258
- _this.session.on('streamDestroyed', _this.streamDestroyedHandler);
259
-
260
- _this.session.on('streamPropertyChanged', _this.streamPropertyChangedHandler);
261
-
262
- _this.session.on('sessionDisconnected', _this.sessionDisconnectedHandler); //best practice
263
-
264
-
265
- _this.prepareVideoPublisherSettings().then(function () {
266
- var _a;
267
-
268
- _this.initVideoPublisher(sessionSettings);
269
-
270
- (_a = _this === null || _this === void 0 ? void 0 : _this.session) === null || _a === void 0 ? void 0 : _a.connect(credentials.token, function (error) {
86
+ var trace = (0, MediaTracer_1.getMediaTracer)('Multiparty');
87
+ var OpentokMultiPartyService = (function (_super) {
88
+ __extends(OpentokMultiPartyService, _super);
89
+ function OpentokMultiPartyService(getParticipantId) {
90
+ var _this = _super.call(this) || this;
91
+ _this.getParticipantId = getParticipantId;
92
+ _this.enableDesktopSharing = false;
93
+ _this.backgroundImageURI = MultiPartyService_1.DEFAULT_AVATAR_URI;
94
+ _this.subscriberList = [];
95
+ _this.setBackgroundImageURI = function (uri) {
96
+ _this.backgroundImageURI = uri || MultiPartyService_1.DEFAULT_AVATAR_URI;
97
+ };
98
+ _this.connect = function (sessionSettings, credentials) {
99
+ try {
100
+ _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
101
+ _this.session.on('connectionCreated', _this.connectionCreatedHandler);
102
+ _this.session.on('connectionDestroyed', _this.connectionDestroyedHandler);
103
+ _this.session.on('streamCreated', _this.streamCreatedHandler);
104
+ _this.session.on('streamDestroyed', _this.streamDestroyedHandler);
105
+ _this.session.on('streamPropertyChanged', _this.streamPropertyChangedHandler);
106
+ _this.session.on('sessionDisconnected', _this.sessionDisconnectedHandler);
107
+ _this.prepareVideoPublisherSettings().then(function () {
108
+ var _a;
109
+ _this.initVideoPublisher(sessionSettings);
110
+ (_a = _this === null || _this === void 0 ? void 0 : _this.session) === null || _a === void 0 ? void 0 : _a.connect(credentials.token, function (error) {
111
+ var _a, _b, _c;
112
+ if (error) {
113
+ (_a = _this === null || _this === void 0 ? void 0 : _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
114
+ (_b = _this.session) === null || _b === void 0 ? void 0 : _b.off();
115
+ _this.session = undefined;
116
+ (0, trace_1.traceError)(error);
117
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectFailed, {
118
+ meta: { err: JSON.stringify(error) }
119
+ });
120
+ return;
121
+ }
122
+ if (_this.videoPublisher) {
123
+ (_c = _this.session) === null || _c === void 0 ? void 0 : _c.publish(_this.videoPublisher.get(), trace_1.traceError);
124
+ }
125
+ _this.isScreenSharingSupported(sessionSettings.isScreenSharingCapabilitiesEnabled).then(function () {
126
+ var _a;
127
+ if (_this.screenPublisher) {
128
+ (_a = _this.session) === null || _a === void 0 ? void 0 : _a.publish(_this.screenPublisher.get(), trace_1.traceError);
129
+ }
130
+ });
131
+ });
132
+ });
133
+ }
134
+ catch (err) {
135
+ trace.error(JSON.stringify(err));
136
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectFailed, {
137
+ meta: { err: JSON.stringify(err) }
138
+ });
139
+ }
140
+ };
141
+ _this.disconnect = function () { return __awaiter(_this, void 0, void 0, function () {
142
+ var err_1;
143
+ var _a, _b;
144
+ return __generator(this, function (_c) {
145
+ switch (_c.label) {
146
+ case 0:
147
+ _c.trys.push([0, 3, , 4]);
148
+ if (!((_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.getVideoFilter)) return [3, 2];
149
+ return [4, ((_b = this.videoPublisher) === null || _b === void 0 ? void 0 : _b.clearVideoFilter())];
150
+ case 1:
151
+ _c.sent();
152
+ _c.label = 2;
153
+ case 2:
154
+ trace.info('Disconnecting from session');
155
+ if (this.session) {
156
+ this.session.disconnect();
157
+ trace.info('Disconnection from session completed');
158
+ }
159
+ return [3, 4];
160
+ case 3:
161
+ err_1 = _c.sent();
162
+ trace.error(JSON.stringify(err_1));
163
+ return [3, 4];
164
+ case 4: return [2];
165
+ }
166
+ });
167
+ }); };
168
+ _this.takeSnapshot = function (connectionId, videoType) {
271
169
  var _a, _b, _c;
272
-
273
- if (error) {
274
- (_a = _this === null || _this === void 0 ? void 0 : _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
275
- (_b = _this.session) === null || _b === void 0 ? void 0 : _b.off();
276
- _this.session = undefined;
277
- trace_1.traceError(error);
278
-
279
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectFailed, {
280
- meta: {
281
- err: JSON.stringify(error)
170
+ if (videoType === void 0) { videoType = MediaConstants_1.VideoTypesEnum.CAMERA; }
171
+ if (!connectionId) {
172
+ return null;
173
+ }
174
+ if (connectionId === _this.ownConnectionId) {
175
+ if (videoType === MediaConstants_1.VideoTypesEnum.CAMERA) {
176
+ return ((_a = _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
282
177
  }
283
- });
284
-
285
- return;
178
+ return ((_b = _this.screenPublisher) === null || _b === void 0 ? void 0 : _b.getImgData()) || null;
179
+ }
180
+ return (((_c = _this.subscribers
181
+ .find(function (s) { return s.connectionId === connectionId && s.videoType === videoType; })) === null || _c === void 0 ? void 0 : _c.subscriber.getImgData()) || null);
182
+ };
183
+ _this.prepareVideoPublisherSettings = function () { return __awaiter(_this, void 0, void 0, function () {
184
+ var canStartWithAudio, canStartWithVideo, capabilitiesService, publisherOptions;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0:
188
+ if (!this.session) {
189
+ return [2];
190
+ }
191
+ return [4, (0, MediaCapabilitiesUtils_1.checkAudioCapabilities)()];
192
+ case 1:
193
+ canStartWithAudio = _a.sent();
194
+ return [4, (0, MediaCapabilitiesUtils_1.checkVideoCapabilities)()];
195
+ case 2:
196
+ canStartWithVideo = _a.sent();
197
+ return [4, MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
198
+ case 3:
199
+ capabilitiesService = _a.sent();
200
+ if (!canStartWithAudio && !canStartWithVideo) {
201
+ throw new Error('Creating session requires initialized publisher');
202
+ }
203
+ publisherOptions = {
204
+ backgroundImageURI: this.backgroundImageURI,
205
+ participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.CAMERA)
206
+ };
207
+ this.videoPublisherOptions = {
208
+ publisherOptions: publisherOptions,
209
+ canStartWithAudio: canStartWithAudio,
210
+ canStartWithVideo: canStartWithVideo,
211
+ capabilitiesService: capabilitiesService
212
+ };
213
+ return [2];
214
+ }
215
+ });
216
+ }); };
217
+ _this.initVideoPublisher = function (settings) {
218
+ var _a, _b;
219
+ if (!(((_a = _this.videoPublisherOptions) === null || _a === void 0 ? void 0 : _a.canStartWithAudio) && ((_b = _this.videoPublisherOptions) === null || _b === void 0 ? void 0 : _b.canStartWithVideo))) {
220
+ throw new Error('could not init publisher');
286
221
  }
287
-
288
- if (_this.videoPublisher) {
289
- (_c = _this.session) === null || _c === void 0 ? void 0 : _c.publish(_this.videoPublisher.get(), trace_1.traceError);
222
+ try {
223
+ _this.videoPublisher = new OpentokVideoPublisher_1.OpentokVideoPublisher(__assign(__assign({}, settings.videoSettings), { cameraEnabled: settings.videoSettings.cameraEnabled && _this.videoPublisherOptions.canStartWithVideo, startWithAudioMuted: settings.videoSettings.startWithAudioMuted && _this.videoPublisherOptions.canStartWithAudio }), _this.videoPublisherOptions.publisherOptions, _this.videoPublisherOptions.capabilitiesService);
224
+ _this.forwardPublisherEvents(_this.videoPublisher);
290
225
  }
291
-
292
- _this.isScreenSharingSupported(sessionSettings.isScreenSharingCapabilitiesEnabled).then(function () {
293
- var _a;
294
-
295
- if (_this.screenPublisher) {
296
- (_a = _this.session) === null || _a === void 0 ? void 0 : _a.publish(_this.screenPublisher.get(), trace_1.traceError);
297
- }
226
+ catch (error) {
227
+ trace.error('could not init publisher');
228
+ }
229
+ };
230
+ _this.isScreenSharingSupported = function (isScreenSharingCapabilitiesEnabled) { return __awaiter(_this, void 0, void 0, function () {
231
+ var _this = this;
232
+ return __generator(this, function (_a) {
233
+ switch (_a.label) {
234
+ case 0:
235
+ if (!(isScreenSharingCapabilitiesEnabled && !(0, MediaCapabilitiesUtils_1.checkIsMobile)())) return [3, 2];
236
+ return [4, OT.checkScreenSharingCapability(function (res) {
237
+ if (!res.supported || res.extensionRegistered === false) {
238
+ trace.error('no screen sharing support found');
239
+ _this.enableDesktopSharing = false;
240
+ }
241
+ else {
242
+ _this.enableDesktopSharing = true;
243
+ }
244
+ })];
245
+ case 1:
246
+ _a.sent();
247
+ return [3, 3];
248
+ case 2:
249
+ this.enableDesktopSharing = false;
250
+ _a.label = 3;
251
+ case 3: return [2, Promise.resolve(this.enableDesktopSharing)];
252
+ }
298
253
  });
299
- });
300
- });
301
- } catch (err) {
302
- trace.error(JSON.stringify(err));
303
-
304
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectFailed, {
305
- meta: {
306
- err: JSON.stringify(err)
307
- }
308
- });
309
- }
310
- };
311
-
312
- _this.disconnect = function () {
313
- return __awaiter(_this, void 0, void 0, function () {
314
- var err_1;
315
-
316
- var _a, _b;
317
-
318
- return __generator(this, function (_c) {
319
- switch (_c.label) {
320
- case 0:
321
- _c.trys.push([0, 3,, 4]);
322
-
323
- if (!((_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.getVideoFilter)) return [3
324
- /*break*/
325
- , 2];
326
- return [4
327
- /*yield*/
328
- , (_b = this.videoPublisher) === null || _b === void 0 ? void 0 : _b.clearVideoFilter()];
329
-
330
- case 1:
331
- _c.sent();
332
-
333
- _c.label = 2;
334
-
335
- case 2:
336
- trace.info('Disconnecting from session');
337
-
338
- if (this.session) {
339
- this.session.disconnect();
340
- trace.info('Disconnection from session completed');
341
- }
342
-
343
- return [3
344
- /*break*/
345
- , 4];
346
-
347
- case 3:
348
- err_1 = _c.sent();
349
- trace.error(JSON.stringify(err_1));
350
- return [3
351
- /*break*/
352
- , 4];
353
-
354
- case 4:
355
- return [2
356
- /*return*/
357
- ];
358
- }
359
- });
360
- });
361
- };
362
-
363
- _this.takeSnapshot = function (connectionId, videoType) {
364
- var _a, _b, _c;
365
-
366
- if (videoType === void 0) {
367
- videoType = MediaConstants_1.VideoTypesEnum.CAMERA;
368
- }
369
-
370
- if (!connectionId) {
371
- return null;
372
- }
373
-
374
- if (connectionId === _this.ownConnectionId) {
375
- if (videoType === MediaConstants_1.VideoTypesEnum.CAMERA) {
376
- return ((_a = _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
377
- }
378
-
379
- return ((_b = _this.screenPublisher) === null || _b === void 0 ? void 0 : _b.getImgData()) || null;
380
- }
381
-
382
- return ((_c = _this.subscribers.find(function (s) {
383
- return s.connectionId === connectionId && s.videoType === videoType;
384
- })) === null || _c === void 0 ? void 0 : _c.subscriber.getImgData()) || null;
385
- };
386
-
387
- _this.prepareVideoPublisherSettings = function () {
388
- return __awaiter(_this, void 0, void 0, function () {
389
- var canStartWithAudio, canStartWithVideo, capabilitiesService, publisherOptions;
390
- return __generator(this, function (_a) {
391
- switch (_a.label) {
392
- case 0:
393
- if (!this.session) {
394
- return [2
395
- /*return*/
396
- ];
397
- }
398
-
399
- return [4
400
- /*yield*/
401
- , MediaCapabilitiesUtils_1.checkAudioCapabilities()];
402
-
403
- case 1:
404
- canStartWithAudio = _a.sent();
405
- return [4
406
- /*yield*/
407
- , MediaCapabilitiesUtils_1.checkVideoCapabilities()];
408
-
409
- case 2:
410
- canStartWithVideo = _a.sent();
411
- return [4
412
- /*yield*/
413
- , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
414
-
415
- case 3:
416
- capabilitiesService = _a.sent();
417
-
418
- if (!canStartWithAudio && !canStartWithVideo) {
419
- throw new Error('Creating session requires initialized publisher');
420
- }
421
-
422
- publisherOptions = {
423
- backgroundImageURI: this.backgroundImageURI,
424
- participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.CAMERA)
425
- };
426
- this.videoPublisherOptions = {
427
- publisherOptions: publisherOptions,
428
- canStartWithAudio: canStartWithAudio,
429
- canStartWithVideo: canStartWithVideo,
430
- capabilitiesService: capabilitiesService
431
- };
432
- return [2
433
- /*return*/
434
- ];
435
- }
436
- });
437
- });
438
- };
439
-
440
- _this.initVideoPublisher = function (settings) {
441
- var _a, _b;
442
-
443
- if (!(((_a = _this.videoPublisherOptions) === null || _a === void 0 ? void 0 : _a.canStartWithAudio) && ((_b = _this.videoPublisherOptions) === null || _b === void 0 ? void 0 : _b.canStartWithVideo))) {
444
- throw new Error('could not init publisher');
445
- }
446
-
447
- try {
448
- _this.videoPublisher = new OpentokVideoPublisher_1.OpentokVideoPublisher(__assign(__assign({}, settings.videoSettings), {
449
- cameraEnabled: settings.videoSettings.cameraEnabled && _this.videoPublisherOptions.canStartWithVideo,
450
- startWithAudioMuted: settings.videoSettings.startWithAudioMuted && _this.videoPublisherOptions.canStartWithAudio
451
- }), _this.videoPublisherOptions.publisherOptions, _this.videoPublisherOptions.capabilitiesService);
452
-
453
- _this.forwardPublisherEvents(_this.videoPublisher);
454
- } catch (error) {
455
- trace.error('could not init publisher');
456
- }
457
- };
458
-
459
- _this.isScreenSharingSupported = function (isScreenSharingCapabilitiesEnabled) {
460
- return __awaiter(_this, void 0, void 0, function () {
461
- var _this = this;
462
-
463
- return __generator(this, function (_a) {
464
- switch (_a.label) {
465
- case 0:
466
- if (!(isScreenSharingCapabilitiesEnabled && !MediaCapabilitiesUtils_1.checkIsMobile())) return [3
467
- /*break*/
468
- , 2];
469
- return [4
470
- /*yield*/
471
- , OT.checkScreenSharingCapability(function (res) {
472
- if (!res.supported || res.extensionRegistered === false) {
473
- // This browser does not support screen sharing.
474
- trace.error('no screen sharing support found');
475
- _this.enableDesktopSharing = false;
476
- } else {
477
- _this.enableDesktopSharing = true;
254
+ }); };
255
+ _this.forwardPublisherEvents = function (publisher) {
256
+ publisher.on('cameraSourceChanged', function (e) { return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.cameraSourceChanged, e); });
257
+ publisher.on('streamCreated', function (e) { return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, e); });
258
+ publisher.on('streamDestroyed', function (e) { return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, e); });
259
+ publisher.on('mediaDeviceAccessDenied', function (e) {
260
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.mediaDeviceAccessDenied, e);
261
+ });
262
+ publisher.on('videoElementCreated', function (e) { return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.videoElementCreated, e); });
263
+ };
264
+ _this.publishAudio = function (shouldMute) { return __awaiter(_this, void 0, void 0, function () {
265
+ var canPublishAudio;
266
+ var _a;
267
+ return __generator(this, function (_b) {
268
+ switch (_b.label) {
269
+ case 0: return [4, (0, MediaCapabilitiesUtils_1.checkAudioCapabilities)()];
270
+ case 1:
271
+ canPublishAudio = _b.sent();
272
+ if (shouldMute && !canPublishAudio) {
273
+ trace.error('could not publish audio');
274
+ return [2];
275
+ }
276
+ (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishAudio(shouldMute);
277
+ return [2];
478
278
  }
479
- })];
480
-
481
- case 1:
482
- _a.sent();
483
-
484
- return [3
485
- /*break*/
486
- , 3];
487
-
488
- case 2:
489
- this.enableDesktopSharing = false;
490
- _a.label = 3;
491
-
492
- case 3:
493
- return [2
494
- /*return*/
495
- , Promise.resolve(this.enableDesktopSharing)];
496
- }
497
- });
498
- });
499
- };
500
-
501
- _this.forwardPublisherEvents = function (publisher) {
502
- publisher.on('cameraSourceChanged', function (e) {
503
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.cameraSourceChanged, e);
504
- });
505
- publisher.on('streamCreated', function (e) {
506
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, e);
507
- });
508
- publisher.on('streamDestroyed', function (e) {
509
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, e);
510
- });
511
- publisher.on('mediaDeviceAccessDenied', function (e) {
512
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.mediaDeviceAccessDenied, e);
513
- });
514
- publisher.on('videoElementCreated', function (e) {
515
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.videoElementCreated, e);
516
- });
517
- };
518
-
519
- _this.publishAudio = function (shouldMute) {
520
- return __awaiter(_this, void 0, void 0, function () {
521
- var canPublishAudio;
522
-
523
- var _a;
524
-
525
- return __generator(this, function (_b) {
526
- switch (_b.label) {
527
- case 0:
528
- return [4
529
- /*yield*/
530
- , MediaCapabilitiesUtils_1.checkAudioCapabilities()];
531
-
532
- case 1:
533
- canPublishAudio = _b.sent();
534
-
535
- if (shouldMute && !canPublishAudio) {
536
- trace.error('could not publish audio');
537
- return [2
538
- /*return*/
539
- ];
540
- }
541
-
542
- (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishAudio(shouldMute);
543
- return [2
544
- /*return*/
545
- ];
546
- }
547
- });
548
- });
549
- };
550
-
551
- _this.publishVideo = function (shouldPublishVideo) {
552
- return __awaiter(_this, void 0, void 0, function () {
553
- var canPublishVideo;
554
-
555
- var _a;
556
-
557
- return __generator(this, function (_b) {
558
- switch (_b.label) {
559
- case 0:
560
- return [4
561
- /*yield*/
562
- , MediaCapabilitiesUtils_1.checkVideoCapabilities()];
563
-
564
- case 1:
565
- canPublishVideo = _b.sent();
566
-
567
- if (shouldPublishVideo && !canPublishVideo) {
568
- trace.error('could not publish video');
569
- return [2
570
- /*return*/
571
- ];
572
- }
573
-
574
- (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishVideo(shouldPublishVideo);
575
- return [2
576
- /*return*/
577
- ];
578
- }
579
- });
580
- });
581
- };
582
-
583
- _this.publishScreen = function () {
584
- return __awaiter(_this, void 0, void 0, function () {
585
- var publisherOptions, capabilitiesService, e_1;
586
-
587
- var _this = this;
588
-
589
- return __generator(this, function (_a) {
590
- switch (_a.label) {
591
- case 0:
592
- if (!this.enableDesktopSharing) return [3
593
- /*break*/
594
- , 5];
595
- publisherOptions = {
596
- backgroundImageURI: this.backgroundImageURI
597
- };
598
- return [4
599
- /*yield*/
600
- , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
601
-
602
- case 1:
603
- capabilitiesService = _a.sent();
604
- _a.label = 2;
605
-
606
- case 2:
607
- _a.trys.push([2, 4,, 5]);
608
-
609
- this.screenPublisher = new OpentokScreenPublisher_1.OpentokScreenPublisher(__assign(__assign({}, publisherOptions), {
610
- participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.SCREEN)
611
- }), capabilitiesService);
612
- this.forwardPublisherEvents(this.screenPublisher);
613
- return [4
614
- /*yield*/
615
- , new Promise(function (resolve, reject) {
616
- var _a, _b;
617
-
618
- _this.screenPublisher && ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.connection) && ((_b = _this.session) === null || _b === void 0 ? void 0 : _b.publish(_this.screenPublisher.get(), function (err) {
619
- if (err) {
620
- trace.error('Failed to publish screen', err);
621
- return reject(err);
622
- }
623
-
624
- return resolve();
625
- }));
626
- })];
627
-
628
- case 3:
629
- return [2
630
- /*return*/
631
- , _a.sent()];
632
-
633
- case 4:
634
- e_1 = _a.sent();
635
- trace.error('Failed to publish screen', e_1);
636
- return [2
637
- /*return*/
638
- , Promise.reject(e_1)];
639
-
640
- case 5:
641
- return [2
642
- /*return*/
643
- ];
644
- }
645
- });
646
- });
647
- };
648
-
649
- _this.switchCamera = function () {
650
- return __awaiter(_this, void 0, void 0, function () {
651
- var _a;
652
-
653
- return __generator(this, function (_b) {
654
- return [2
655
- /*return*/
656
- , (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.switchCamera()];
657
- });
658
- });
659
- };
660
-
661
- _this.reinitializeStreams = function (settings) {
662
- var _a, _b, _c;
663
-
664
- var promises = [];
665
-
666
- if (!_this.session) {
667
- return Promise.resolve([]);
668
- }
669
-
670
- var shouldPublishScreen = !!_this.screenPublisher;
671
-
672
- _this.subscriberList.map(function (s) {
673
- return s.subscriber;
674
- }).forEach((_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
675
-
676
- _this.subscriberList = [];
677
- (_b = _this.videoPublisher) === null || _b === void 0 ? void 0 : _b.destroy();
678
- (_c = _this.screenPublisher) === null || _c === void 0 ? void 0 : _c.destroy();
679
-
680
- _this.initVideoPublisher(settings);
681
-
682
- if (shouldPublishScreen) {
683
- promises.push(_this.publishScreen());
684
- }
685
-
686
- return Promise.all(promises);
687
- };
688
-
689
- _this.streamCreatedHandler = function (event) {
690
- return __awaiter(_this, void 0, void 0, function () {
691
- var stream, connection, hasAudio, hasVideo, videoDimensions, videoType, connectionId, data, participantId, clientRole, subscriber;
692
- return __generator(this, function (_a) {
693
- trace.info('streamCreatedHandler', event.stream);
694
- stream = event.stream;
695
- connection = stream.connection, hasAudio = stream.hasAudio, hasVideo = stream.hasVideo, videoDimensions = stream.videoDimensions, videoType = stream.videoType;
696
- connectionId = connection.connectionId, data = connection.data;
697
- participantId = this.getParticipantId(connectionId, videoType);
698
- clientRole = utils_1.decodeClientRole(data);
699
-
700
- if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
701
- if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
702
- subscriber = OpentokSubscriber_1.createSubscriber(this.session, stream, this.getParticipantId(connectionId, videoType), this.backgroundImageURI);
703
- this.subscriberList.push({
704
- subscriber: subscriber,
279
+ });
280
+ }); };
281
+ _this.publishVideo = function (shouldPublishVideo) { return __awaiter(_this, void 0, void 0, function () {
282
+ var canPublishVideo;
283
+ var _a;
284
+ return __generator(this, function (_b) {
285
+ switch (_b.label) {
286
+ case 0: return [4, (0, MediaCapabilitiesUtils_1.checkVideoCapabilities)()];
287
+ case 1:
288
+ canPublishVideo = _b.sent();
289
+ if (shouldPublishVideo && !canPublishVideo) {
290
+ trace.error('could not publish video');
291
+ return [2];
292
+ }
293
+ (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishVideo(shouldPublishVideo);
294
+ return [2];
295
+ }
296
+ });
297
+ }); };
298
+ _this.publishScreen = function () { return __awaiter(_this, void 0, void 0, function () {
299
+ var publisherOptions, capabilitiesService, e_1;
300
+ var _this = this;
301
+ return __generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0:
304
+ if (!this.enableDesktopSharing) return [3, 5];
305
+ publisherOptions = {
306
+ backgroundImageURI: this.backgroundImageURI
307
+ };
308
+ return [4, MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
309
+ case 1:
310
+ capabilitiesService = _a.sent();
311
+ _a.label = 2;
312
+ case 2:
313
+ _a.trys.push([2, 4, , 5]);
314
+ this.screenPublisher = new OpentokScreenPublisher_1.OpentokScreenPublisher(__assign(__assign({}, publisherOptions), { participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.SCREEN) }), capabilitiesService);
315
+ this.forwardPublisherEvents(this.screenPublisher);
316
+ return [4, new Promise(function (resolve, reject) {
317
+ var _a, _b;
318
+ _this.screenPublisher &&
319
+ ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.connection) &&
320
+ ((_b = _this.session) === null || _b === void 0 ? void 0 : _b.publish(_this.screenPublisher.get(), function (err) {
321
+ if (err) {
322
+ trace.error('Failed to publish screen', err);
323
+ return reject(err);
324
+ }
325
+ return resolve();
326
+ }));
327
+ })];
328
+ case 3: return [2, _a.sent()];
329
+ case 4:
330
+ e_1 = _a.sent();
331
+ trace.error('Failed to publish screen', e_1);
332
+ return [2, Promise.reject(e_1)];
333
+ case 5: return [2];
334
+ }
335
+ });
336
+ }); };
337
+ _this.switchCamera = function () { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
338
+ return [2, (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.switchCamera()];
339
+ }); }); };
340
+ _this.reinitializeStreams = function (settings) {
341
+ var _a, _b, _c;
342
+ var promises = [];
343
+ if (!_this.session) {
344
+ return Promise.resolve([]);
345
+ }
346
+ var shouldPublishScreen = !!_this.screenPublisher;
347
+ _this.subscriberList.map(function (s) { return s.subscriber; }).forEach((_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
348
+ _this.subscriberList = [];
349
+ (_b = _this.videoPublisher) === null || _b === void 0 ? void 0 : _b.destroy();
350
+ (_c = _this.screenPublisher) === null || _c === void 0 ? void 0 : _c.destroy();
351
+ _this.initVideoPublisher(settings);
352
+ if (shouldPublishScreen) {
353
+ promises.push(_this.publishScreen());
354
+ }
355
+ return Promise.all(promises);
356
+ };
357
+ _this.streamCreatedHandler = function (event) { return __awaiter(_this, void 0, void 0, function () {
358
+ var stream, connection, hasAudio, hasVideo, videoDimensions, videoType, connectionId, data, participantId, clientRole, subscriber;
359
+ return __generator(this, function (_a) {
360
+ trace.info('streamCreatedHandler', event.stream);
361
+ stream = event.stream;
362
+ connection = stream.connection, hasAudio = stream.hasAudio, hasVideo = stream.hasVideo, videoDimensions = stream.videoDimensions, videoType = stream.videoType;
363
+ connectionId = connection.connectionId, data = connection.data;
364
+ participantId = this.getParticipantId(connectionId, videoType);
365
+ clientRole = (0, utils_1.decodeClientRole)(data);
366
+ if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
367
+ if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
368
+ subscriber = (0, OpentokSubscriber_1.createSubscriber)(this.session, stream, this.getParticipantId(connectionId, videoType), this.backgroundImageURI);
369
+ this.subscriberList.push({
370
+ subscriber: subscriber,
371
+ connectionId: connectionId,
372
+ clientRole: clientRole,
373
+ videoType: videoType
374
+ });
375
+ }
376
+ else {
377
+ trace.info("a new subscriber cannot be added, as the number of participants reached its limit: ".concat(MultiPartyService_1.maxParticipantsNumber));
378
+ }
379
+ }
380
+ this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, {
381
+ participantId: participantId,
382
+ clientRole: clientRole,
383
+ connectionId: connectionId,
384
+ hasVideo: hasVideo,
385
+ hasAudio: hasAudio,
386
+ isOwnConnection: false,
387
+ mirror: false,
388
+ videoDimensions: videoDimensions,
389
+ videoType: videoType
390
+ });
391
+ return [2];
392
+ });
393
+ }); };
394
+ _this.streamDestroyedHandler = function (event) {
395
+ trace.info('streamDestroyedHandler', event);
396
+ var _a = event.stream, connection = _a.connection, videoType = _a.videoType;
397
+ var connectionId = connection.connectionId;
398
+ _this.subscriberList = _this.subscriberList.filter(function (subscriber) { return !(0, utils_1.isSameStream)(__assign({}, subscriber), { connectionId: connectionId, videoType: videoType }); });
399
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, {
400
+ participantId: _this.getParticipantId(connectionId, videoType),
705
401
  connectionId: connectionId,
706
- clientRole: clientRole,
402
+ isOwnConnection: false,
403
+ clientRole: (0, utils_1.decodeClientRole)(connection.data),
707
404
  videoType: videoType
708
- });
709
- } else {
710
- trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiPartyService_1.maxParticipantsNumber);
405
+ });
406
+ };
407
+ _this.connectionCreatedHandler = function (event) {
408
+ var _a;
409
+ trace.info('connectionCreatedHandler', event);
410
+ var connection = event.connection;
411
+ var connectionId = connection.connectionId;
412
+ var clientRole = (0, utils_1.decodeClientRole)(connection.data);
413
+ if (!_this.ownConnectionId || !connection) {
414
+ return;
711
415
  }
712
- }
713
-
714
- this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, {
715
- participantId: participantId,
716
- clientRole: clientRole,
717
- connectionId: connectionId,
718
- hasVideo: hasVideo,
719
- hasAudio: hasAudio,
720
- isOwnConnection: false,
721
- mirror: false,
722
- videoDimensions: videoDimensions,
723
- videoType: videoType
724
- });
725
- return [2
726
- /*return*/
727
- ];
728
- });
729
- });
730
- };
731
-
732
- _this.streamDestroyedHandler = function (event) {
733
- trace.info('streamDestroyedHandler', event);
734
- var _a = event.stream,
735
- connection = _a.connection,
736
- videoType = _a.videoType;
737
- var connectionId = connection.connectionId;
738
- _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
739
- return !utils_1.isSameStream(__assign({}, subscriber), {
740
- connectionId: connectionId,
741
- videoType: videoType
742
- });
743
- });
744
-
745
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, {
746
- participantId: _this.getParticipantId(connectionId, videoType),
747
- connectionId: connectionId,
748
- isOwnConnection: false,
749
- clientRole: utils_1.decodeClientRole(connection.data),
750
- videoType: videoType
751
- });
752
- };
753
-
754
- _this.connectionCreatedHandler = function (event) {
755
- var _a;
756
-
757
- trace.info('connectionCreatedHandler', event);
758
- var connection = event.connection;
759
- var connectionId = connection.connectionId;
760
- var clientRole = utils_1.decodeClientRole(connection.data);
761
-
762
- if (!_this.ownConnectionId || !connection) {
763
- return;
764
- }
765
- /*
766
- TODO: when we will support few connections with the same clientRole (example- multiple observers)
767
- we should pass as metadata in backend userId that we can distinguish between the connections in techsee-media-service-client
768
- */
769
-
770
-
771
- var sameRole = _this.subscriberList.find(function (subscriber) {
772
- return subscriber.clientRole === clientRole;
773
- });
774
-
775
- if (sameRole) {
776
- _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
777
- return subscriber.clientRole !== clientRole;
778
- });
779
- (_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe(sameRole.subscriber);
780
- }
781
-
782
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectionCreated, {
783
- clientRole: clientRole,
784
- participantId: _this.getParticipantId(connectionId),
785
- connectionId: connectionId,
786
- isOwnConnection: _this.checkOwnConnection(connectionId)
787
- });
788
- };
789
-
790
- _this.connectionDestroyedHandler = function (event) {
791
- var connection = event.connection;
792
- var connectionId = connection.connectionId;
793
- trace.info('connectionDestroyedHandler', event);
794
-
795
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectionDestroyed, {
796
- clientRole: utils_1.decodeClientRole(connection.data),
797
- participantId: _this.getParticipantId(connectionId),
798
- connectionId: connectionId,
799
- isOwnConnection: _this.checkOwnConnection(connectionId)
800
- });
801
-
802
- if (connectionId !== _this.ownConnectionId || !_this.ownConnectionId) {
803
- return;
804
- }
805
-
806
- _this.session = undefined;
807
- };
808
-
809
- _this.streamPropertyChangedHandler = function (event) {
810
- trace.info('streamPropertyChangedHandler', event);
811
- var _a = event.stream,
812
- hasVideo = _a.hasVideo,
813
- hasAudio = _a.hasAudio,
814
- connection = _a.connection,
815
- videoDimensions = _a.videoDimensions,
816
- videoType = _a.videoType;
817
- var connectionId = connection.connectionId;
818
-
819
- _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamPropertyChanged, {
820
- hasVideo: hasVideo,
821
- hasAudio: hasAudio,
822
- participantId: _this.getParticipantId(connectionId, videoType),
823
- connectionId: connectionId,
824
- isOwnConnection: _this.checkOwnConnection(connectionId),
825
- clientRole: utils_1.decodeClientRole(connection.data),
826
- videoDimensions: videoDimensions,
827
- videoType: videoType
828
- });
829
- };
830
-
831
- _this.sessionDisconnectedHandler = function (event) {
832
- var _a;
833
-
834
- (_a = _this.session) === null || _a === void 0 ? void 0 : _a.off();
835
- trace.info('sessionDisconnectedHandler', event);
836
- };
837
-
838
- _this.checkOwnConnection = function (connectionId) {
839
- return _this.ownConnectionId !== undefined && _this.ownConnectionId === connectionId;
416
+ var sameRole = _this.subscriberList.find(function (subscriber) { return subscriber.clientRole === clientRole; });
417
+ if (sameRole) {
418
+ _this.subscriberList = _this.subscriberList.filter(function (subscriber) { return subscriber.clientRole !== clientRole; });
419
+ (_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe(sameRole.subscriber);
420
+ }
421
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectionCreated, {
422
+ clientRole: clientRole,
423
+ participantId: _this.getParticipantId(connectionId),
424
+ connectionId: connectionId,
425
+ isOwnConnection: _this.checkOwnConnection(connectionId)
426
+ });
427
+ };
428
+ _this.connectionDestroyedHandler = function (event) {
429
+ var connection = event.connection;
430
+ var connectionId = connection.connectionId;
431
+ trace.info('connectionDestroyedHandler', event);
432
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.connectionDestroyed, {
433
+ clientRole: (0, utils_1.decodeClientRole)(connection.data),
434
+ participantId: _this.getParticipantId(connectionId),
435
+ connectionId: connectionId,
436
+ isOwnConnection: _this.checkOwnConnection(connectionId)
437
+ });
438
+ if (connectionId !== _this.ownConnectionId || !_this.ownConnectionId) {
439
+ return;
440
+ }
441
+ _this.session = undefined;
442
+ };
443
+ _this.streamPropertyChangedHandler = function (event) {
444
+ trace.info('streamPropertyChangedHandler', event);
445
+ var _a = event.stream, hasVideo = _a.hasVideo, hasAudio = _a.hasAudio, connection = _a.connection, videoDimensions = _a.videoDimensions, videoType = _a.videoType;
446
+ var connectionId = connection.connectionId;
447
+ _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamPropertyChanged, {
448
+ hasVideo: hasVideo,
449
+ hasAudio: hasAudio,
450
+ participantId: _this.getParticipantId(connectionId, videoType),
451
+ connectionId: connectionId,
452
+ isOwnConnection: _this.checkOwnConnection(connectionId),
453
+ clientRole: (0, utils_1.decodeClientRole)(connection.data),
454
+ videoDimensions: videoDimensions,
455
+ videoType: videoType
456
+ });
457
+ };
458
+ _this.sessionDisconnectedHandler = function (event) {
459
+ var _a;
460
+ (_a = _this.session) === null || _a === void 0 ? void 0 : _a.off();
461
+ trace.info('sessionDisconnectedHandler', event);
462
+ };
463
+ _this.checkOwnConnection = function (connectionId) {
464
+ return _this.ownConnectionId !== undefined && _this.ownConnectionId === connectionId;
465
+ };
466
+ return _this;
467
+ }
468
+ Object.defineProperty(OpentokMultiPartyService.prototype, "ownConnectionId", {
469
+ get: function () {
470
+ var _a, _b;
471
+ return ((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b.connectionId) || '';
472
+ },
473
+ enumerable: false,
474
+ configurable: true
475
+ });
476
+ Object.defineProperty(OpentokMultiPartyService.prototype, "subscribers", {
477
+ get: function () {
478
+ return __spreadArray([], this.subscriberList, true);
479
+ },
480
+ enumerable: false,
481
+ configurable: true
482
+ });
483
+ OpentokMultiPartyService.prototype.stopScreenPublisher = function () {
484
+ var _a;
485
+ return (_a = this.screenPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
840
486
  };
841
-
842
- return _this;
843
- }
844
-
845
- Object.defineProperty(OpentokMultiPartyService.prototype, "ownConnectionId", {
846
- get: function get() {
847
- var _a, _b;
848
-
849
- return ((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b.connectionId) || '';
850
- },
851
- enumerable: false,
852
- configurable: true
853
- });
854
- Object.defineProperty(OpentokMultiPartyService.prototype, "subscribers", {
855
- get: function get() {
856
- return __spreadArrays(this.subscriberList);
857
- },
858
- enumerable: false,
859
- configurable: true
860
- });
861
-
862
- OpentokMultiPartyService.prototype.stopScreenPublisher = function () {
863
- var _a;
864
-
865
- return (_a = this.screenPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
866
- };
867
-
868
- return OpentokMultiPartyService;
869
- }(MultiPartyService_1.MultiPartyService);
870
-
487
+ return OpentokMultiPartyService;
488
+ }(MultiPartyService_1.MultiPartyService));
871
489
  exports.OpentokMultiPartyService = OpentokMultiPartyService;
872
- //# sourceMappingURL=OpentokMultiPartyService.js.map
490
+ //# sourceMappingURL=OpentokMultiPartyService.js.map