@techsee/techsee-media-service 18.6.1 → 19.0.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 -45
@@ -1,538 +1,393 @@
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 __importDefault = void 0 && (void 0).__importDefault || function (mod) {
30
- return mod && mod.__esModule ? mod : {
31
- "default": mod
32
- };
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 __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
19
  };
34
-
35
- Object.defineProperty(exports, "__esModule", {
36
- value: true
37
- });
20
+ Object.defineProperty(exports, "__esModule", { value: true });
38
21
  exports.MediaServerSession = void 0;
39
-
40
22
  var MediaSessionBase_1 = require("./MediaSessionBase");
41
-
42
23
  var MediaConstants_1 = require("../MediaConstants");
43
-
44
24
  var openvidu_browser_1 = require("@techsee/openvidu-browser");
45
-
46
25
  var MediaTracer_1 = require("../MediaUtils/MediaTracer");
47
-
48
26
  var guards_1 = require("@techsee/techsee-common/lib/core/guards");
49
-
50
27
  var bluebird_1 = require("bluebird");
51
-
52
28
  var get_1 = __importDefault(require("lodash/get"));
53
-
54
- var trace = MediaTracer_1.getMediaTracer('MediaServerSession');
55
-
56
- var MediaServerSession =
57
- /** @class */
58
- function (_super) {
59
- __extends(MediaServerSession, _super);
60
-
61
- function MediaServerSession(sessionParams, streamFactory) {
62
- var _this = _super.call(this, sessionParams, streamFactory) || this;
63
-
64
- _this.OV = null;
65
- _this._session = null;
66
- _this._lastStreamEvents = [];
67
- _this._credentials = sessionParams.credentials;
68
- _this.connect = _this.connect.bind(_this);
69
- _this.disconnect = _this.disconnect.bind(_this);
70
- _this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
71
- _this.onPublisherDestroyed = _this.onPublisherDestroyed.bind(_this);
72
- _this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
73
- _this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
74
- _this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
75
- _this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
76
- _this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
77
- _this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
78
- _this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
79
- return _this;
80
- }
81
-
82
- Object.defineProperty(MediaServerSession.prototype, "ownPeerId", {
83
- get: function get() {
84
- return this._session && this._session.connection ? this._session.connection.connectionId : '';
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
-
90
- MediaServerSession.prototype.connect = function (connectOnly) {
91
- trace.info('Connect to session', this._credentials);
92
-
93
- if (this._session) {
94
- trace.error('Session already exists');
95
- return bluebird_1.Promise.reject('Cannot connect to session while another session is active');
96
- } // const iceServers = this._credentials.ice.map((item: any) => ({
97
- // urls: item.url,
98
- // username: item.login,
99
- // credential: item.password
100
- // }));
101
-
102
-
103
- this.OV = new openvidu_browser_1.OpenVidu(); // this.OV.setAdvancedConfiguration({ iceServers });
104
-
105
- this._session = this.OV.initSession();
106
- this.initSessionEvents();
107
- return this._session.connect(this._credentials.token, {
108
- clientRole: this._sessionParams.clientRole
109
- })["catch"](function (err) {
110
- trace.error('Error to connect to session Media Server: ', err);
111
- throw err;
112
- });
113
- };
114
-
115
- MediaServerSession.prototype.sessionDisconnect = function () {
116
- if (this._session) {
117
- return this._session.disconnect(true);
118
- }
119
- };
120
-
121
- MediaServerSession.prototype.disconnect = function () {
122
- var _this = this;
123
-
124
- return new bluebird_1.Promise(function (resolve) {
125
- trace.info('Disconnecting from session');
126
- var promiseDisconnect = [];
127
-
128
- _this._peerConnections.forEach(function (peerConnection) {
129
- promiseDisconnect.push(_this.destroyPeerConnection(peerConnection));
130
- });
131
-
132
- return bluebird_1.Promise.all(promiseDisconnect).then(function () {
133
- if (!_this._session) {
134
- trace.info('No active session - resolving');
135
- resolve();
136
- return;
137
- }
138
-
139
- _this.removeSessionEvent();
140
-
141
- _this._session.disconnect();
142
-
143
- _this._lastStreamEvents = []; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
144
- // @ts-ignore
145
-
146
- delete _this._session; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
147
- // @ts-ignore
148
-
149
- delete _this.OV;
150
- resolve();
151
- });
152
- });
153
- };
154
-
155
- MediaServerSession.prototype.removeSessionEvent = function () {
156
- if (!this._session) {
157
- return;
158
- }
159
-
160
- this._session.off('connectionCreated');
161
-
162
- this._session.off('streamCreated');
163
-
164
- this._session.off('streamDestroyed');
165
-
166
- this._session.off('connectionDestroyed');
167
-
168
- this._session.off('sessionDisconnected');
169
-
170
- this._session.off('recordingStarted');
171
-
172
- this._session.off('recordingStopped');
173
-
174
- this._sessionParams.removeHandlers && this._sessionParams.removeHandlers();
175
- trace.info('Remove Events Listener');
176
- };
177
-
178
- MediaServerSession.prototype.getRemoteTrackStats = function (mediaTrack) {
179
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
180
- // @ts-ignore// @ts-ignore
181
- return bluebird_1.Promise.resolve(undefined);
182
- };
183
-
184
- MediaServerSession.prototype.onMediaStreamDestroyed = function (clientRole) {
185
- var _this = this;
186
-
187
- trace.info('onMediaStreamDestroyed');
188
- var promises = [];
189
-
190
- this._peerConnections.forEach(function (peerConnection) {
191
- if (peerConnection.peerRole === clientRole) {
192
- promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
193
- }
194
- });
195
-
196
- return bluebird_1.Promise.all(promises).then(function () {
197
- return trace.info('onMediaStreamDestroyed: Success');
198
- });
199
- };
200
-
201
- MediaServerSession.prototype.onPublisherDestroyed = function (connectionId) {
202
- trace.info('onPublisherDestroyed');
203
-
204
- var peerConnection = this._peerConnections.get(connectionId);
205
-
206
- if (!peerConnection) {
207
- return bluebird_1.Promise.resolve();
208
- }
209
-
210
- return this.destroyPublisherOnPeerConnection(peerConnection);
211
- };
212
-
213
- MediaServerSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
214
- return bluebird_1.Promise.resolve(undefined);
215
- };
216
-
217
- MediaServerSession.prototype.replaceStreamTracks = function (mediaStream) {
218
- return bluebird_1.Promise.reject(new Error('Not implemented'));
219
- };
220
-
221
- MediaServerSession.prototype.initSessionEvents = function () {
222
- var _this = this;
223
-
224
- if (!this._session) {
225
- return;
226
- }
227
-
228
- this._sessionParams.initHandlers && this._sessionParams.initHandlers();
229
- this._lastStreamEvents = [];
230
-
231
- this._session.on('connectionCreated', this.connectionCreatedHandler);
232
-
233
- this._session.on('streamCreated', this.streamCreatedHandler);
234
-
235
- this._session.on('streamDestroyed', this.streamDestroyedHandler);
236
-
237
- this._session.on('connectionDestroyed', this.connectionDestroyedHandler);
238
-
239
- this._session.on('recordingStarted', function (event) {
240
- trace.info('recordingStarted event', event);
241
-
242
- _this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
243
- });
244
-
245
- this._session.on('recordingStopped', function (event) {
246
- trace.info('recordingStopped event', event);
247
-
248
- _this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
249
- });
250
-
251
- this._session.on('reconnecting', function () {
252
- trace.info('reconnecting event');
253
-
254
- _this.emitEvent(MediaSessionBase_1.recordingEvents.RECONNECTING);
255
- });
256
-
257
- this._session.on('sessionDisconnected', this.disconnect);
258
- };
259
-
260
- MediaServerSession.prototype.streamDestroyedHandler = function (event) {
261
- trace.info('streamDestroyedHandler', event);
262
- var stream = event.stream;
263
-
264
- if (!this.sessionExistsGuard(false) || !stream) {
265
- return;
266
- }
267
-
268
- var peerConnection = this._peerConnections.get(stream.connection.connectionId);
269
-
270
- if (!peerConnection) {
271
- trace.warn('Peer connection for remote stream not found');
272
- return;
273
- }
274
-
275
- this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
276
- return undefined;
277
- });
278
- };
279
-
280
- MediaServerSession.prototype.connectionDestroyedHandler = function (event) {
281
- trace.info('connectionDestroyedHandler', event);
282
- var connection = event.connection;
283
-
284
- if (!this.sessionExistsGuard(false) || !connection) {
285
- return;
286
- }
287
-
288
- if (this._peerConnections.has(connection.connectionId)) {
289
- var peerConnection = this._peerConnections.get(connection.connectionId);
290
-
291
- this.destroySubscriberOnPeerConnection(peerConnection)["catch"](function () {
292
- return undefined;
293
- });
294
- }
295
- };
296
-
297
- MediaServerSession.prototype.destroyPeerConnection = function (peerConnection) {
298
- trace.info('destroyPeerConnection');
299
-
300
- this._peerConnections["delete"](peerConnection.peerId);
301
-
302
- return bluebird_1.Promise.all([this.destroyPublisherOnPeerConnection(peerConnection), this.destroySubscriberOnPeerConnection(peerConnection)]).then(function () {
303
- return undefined;
304
- })["catch"](function () {
305
- trace.warn('destroyPeerConnection - something wrong with destroy');
306
- });
307
- };
308
-
309
- MediaServerSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
310
- trace.info('destroySubscriberOnPeerConnection', peerConnection);
311
-
312
- if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
313
- this._session.unsubscribe(peerConnection.subscriber);
29
+ var trace = (0, MediaTracer_1.getMediaTracer)('MediaServerSession');
30
+ var MediaServerSession = (function (_super) {
31
+ __extends(MediaServerSession, _super);
32
+ function MediaServerSession(sessionParams, streamFactory) {
33
+ var _this = _super.call(this, sessionParams, streamFactory) || this;
34
+ _this.OV = null;
35
+ _this._session = null;
36
+ _this._lastStreamEvents = [];
37
+ _this._credentials = sessionParams.credentials;
38
+ _this.connect = _this.connect.bind(_this);
39
+ _this.disconnect = _this.disconnect.bind(_this);
40
+ _this.onMediaStreamDestroyed = _this.onMediaStreamDestroyed.bind(_this);
41
+ _this.onPublisherDestroyed = _this.onPublisherDestroyed.bind(_this);
42
+ _this.onMediaStreamRenewed = _this.onMediaStreamRenewed.bind(_this);
43
+ _this.createStreamForPublishing = _this.createStreamForPublishing.bind(_this);
44
+ _this.createMediaPublisher = _this.createMediaPublisher.bind(_this);
45
+ _this.connectionCreatedHandler = _this.connectionCreatedHandler.bind(_this);
46
+ _this.connectionDestroyedHandler = _this.connectionDestroyedHandler.bind(_this);
47
+ _this.streamCreatedHandler = _this.streamCreatedHandler.bind(_this);
48
+ _this.streamDestroyedHandler = _this.streamDestroyedHandler.bind(_this);
49
+ return _this;
314
50
  }
315
-
316
- trace.info('destroySubscriberOnPeerConnection- before unregisterPeersRemoteMediaTracks');
317
- return this.unregisterPeersRemoteMediaTracks(peerConnection)["catch"](function () {
318
- return trace.warn('Error removing remote streams from peerConnection');
319
- }).then(function () {
320
- trace.info('destroySubscriberOnPeerConnection- unregisterPeersRemoteMediaTracks successfully');
321
- peerConnection.subscriber = null;
51
+ Object.defineProperty(MediaServerSession.prototype, "ownPeerId", {
52
+ get: function () {
53
+ return this._session && this._session.connection ? this._session.connection.connectionId : '';
54
+ },
55
+ enumerable: false,
56
+ configurable: true
322
57
  });
323
- };
324
-
325
- MediaServerSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
326
- trace.info('destroyPublisherOnPeerConnection');
327
-
328
- if (this.sessionExistsGuard(false) && peerConnection.publisher) {
329
- trace.info('destroyPublisherOnPeerConnection- unpublish!');
330
-
331
- this._session.unpublish(peerConnection.publisher);
332
- }
333
-
334
- peerConnection.publisher = null;
335
- peerConnection.localStream = null;
336
- return bluebird_1.Promise.resolve();
337
- };
338
-
339
- MediaServerSession.prototype.createMediaSubscriber = function (remoteStream) {
340
- var _this = this;
341
-
342
- trace.info('createMediaSubscriber');
343
- return new bluebird_1.Promise(function (resolve, reject) {
344
- if (!_this.sessionExistsGuard(false)) {
345
- return reject('Session not exists');
346
- }
347
-
348
- trace.info('Before create subscriber');
349
-
350
- var subscriber = _this._session.subscribe(remoteStream, '', {}, function (err) {
351
- if (err) {
352
- trace.warn('Error creating subscriber', err);
353
- return reject(err);
58
+ MediaServerSession.prototype.connect = function (connectOnly) {
59
+ trace.info('Connect to session', this._credentials);
60
+ if (this._session) {
61
+ trace.error('Session already exists');
62
+ return bluebird_1.Promise.reject('Cannot connect to session while another session is active');
354
63
  }
355
-
356
- trace.info('create subscriber successfully', subscriber);
357
- return resolve(subscriber);
358
- });
359
- });
360
- };
361
-
362
- MediaServerSession.prototype.streamCreatedHandler = function (event) {
363
- var _this = this;
364
-
365
- if (!event) {
366
- return bluebird_1.Promise.resolve();
367
- }
368
-
369
- trace.info('streamCreatedHandler', event.stream);
370
- var stream = event.stream;
371
- var connection = (stream || {
372
- connection: null
373
- }).connection;
374
-
375
- if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
376
- return bluebird_1.Promise.resolve();
377
- }
378
-
379
- if (!this._peerConnections.has(connection.connectionId)) {
380
- trace.warn('Unexpected case, connection should exist, add to streams to subscribe list', event);
381
-
382
- this._lastStreamEvents.push(event);
383
-
384
- return bluebird_1.Promise.resolve();
385
- }
386
-
387
- var peerConnection = this._peerConnections.get(connection.connectionId);
388
-
389
- trace.info('Subscribing the stream');
390
- return this.createMediaSubscriber(stream).then(function (subscriber) {
391
- peerConnection.subscriber = subscriber;
392
- trace.info('Registering remote media tracks', peerConnection.subscriber);
393
- subscriber.stream.getMediaStream().getTracks().forEach(function (mediaTrack) {
394
- _this.addRemoteTrackToPeer(peerConnection, mediaTrack);
395
- });
396
- return _this.registerPeersRemoteTracks(peerConnection);
397
- });
398
- };
399
-
400
- MediaServerSession.prototype.createStreamForPublishing = function (destinationRole) {
401
- var _this = this;
402
-
403
- trace.info('createStreamForPublishing');
404
- return this._sessionStreamsManager.getMediaStreamForRole(destinationRole).then(function (mediaStream) {
405
- var stream = {
406
- videoSource: null,
407
- audioSource: null
408
- };
409
-
410
- if (mediaStream) {
411
- trace.info('Media stream found for publishing', mediaStream);
412
- mediaStream.getTracks().forEach(function (track) {
413
- if (track.kind === 'video') {
414
- stream.videoSource = track;
415
- } else if (track.kind === 'audio') {
416
- stream.audioSource = track;
417
- }
64
+ this.OV = new openvidu_browser_1.OpenVidu();
65
+ this._session = this.OV.initSession();
66
+ this.initSessionEvents();
67
+ return this._session
68
+ .connect(this._credentials.token, { clientRole: this._sessionParams.clientRole })
69
+ .catch(function (err) {
70
+ trace.error('Error to connect to session Media Server: ', err);
71
+ throw err;
72
+ });
73
+ };
74
+ MediaServerSession.prototype.sessionDisconnect = function () {
75
+ if (this._session) {
76
+ return this._session.disconnect(true);
77
+ }
78
+ };
79
+ MediaServerSession.prototype.disconnect = function () {
80
+ var _this = this;
81
+ return new bluebird_1.Promise(function (resolve) {
82
+ trace.info('Disconnecting from session');
83
+ var promiseDisconnect = [];
84
+ _this._peerConnections.forEach(function (peerConnection) {
85
+ promiseDisconnect.push(_this.destroyPeerConnection(peerConnection));
86
+ });
87
+ return bluebird_1.Promise.all(promiseDisconnect).then(function () {
88
+ if (!_this._session) {
89
+ trace.info('No active session - resolving');
90
+ resolve();
91
+ return;
92
+ }
93
+ _this.removeSessionEvent();
94
+ _this._session.disconnect();
95
+ _this._lastStreamEvents = [];
96
+ delete _this._session;
97
+ delete _this.OV;
98
+ resolve();
99
+ });
418
100
  });
419
- } else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
420
- trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
421
- }
422
-
423
- return stream;
424
- });
425
- };
426
-
427
- MediaServerSession.prototype.createMediaPublisher = function (stream) {
428
- var _this = this;
429
-
430
- var ovParams = {
431
- videoSource: stream.videoSource ? stream.videoSource : false,
432
- audioSource: stream.audioSource ? stream.audioSource : false,
433
- publishAudio: !!stream.audioSource,
434
- publishVideo: !!stream.videoSource
435
101
  };
436
- return new bluebird_1.Promise(function (resolve, reject) {
437
- var ovPublisher = _this.OV.initPublisher('', ovParams, function (error) {
438
- if (error) {
439
- reject(error);
440
- return;
102
+ MediaServerSession.prototype.removeSessionEvent = function () {
103
+ if (!this._session) {
104
+ return;
441
105
  }
442
-
443
- ovPublisher.on('streamDestroyed', function (event) {
444
- trace.info('Publisher stream destroyed', event);
445
- var connectionId = get_1["default"](event, 'stream.connection.connectionId');
446
-
447
- _this.onPublisherDestroyed(connectionId); //We preventing the default, in order to prevent stop the stream by OV.
448
- //We managing streams by ourselves and if we allow OV to close the stream, it cannot be reused.
449
-
450
-
451
- event.preventDefault();
106
+ this._session.off('connectionCreated');
107
+ this._session.off('streamCreated');
108
+ this._session.off('streamDestroyed');
109
+ this._session.off('connectionDestroyed');
110
+ this._session.off('sessionDisconnected');
111
+ this._session.off('recordingStarted');
112
+ this._session.off('recordingStopped');
113
+ this._sessionParams.removeHandlers && this._sessionParams.removeHandlers();
114
+ trace.info('Remove Events Listener');
115
+ };
116
+ MediaServerSession.prototype.getRemoteTrackStats = function (mediaTrack) {
117
+ return bluebird_1.Promise.resolve(undefined);
118
+ };
119
+ MediaServerSession.prototype.onMediaStreamDestroyed = function (clientRole) {
120
+ var _this = this;
121
+ trace.info('onMediaStreamDestroyed');
122
+ var promises = [];
123
+ this._peerConnections.forEach(function (peerConnection) {
124
+ if (peerConnection.peerRole === clientRole) {
125
+ promises.push(_this.destroyPublisherOnPeerConnection(peerConnection));
126
+ }
452
127
  });
453
- resolve(ovPublisher);
454
- });
455
- });
456
- };
457
-
458
- MediaServerSession.prototype.connectionCreatedHandler = function (event) {
459
- var _this = this;
460
-
461
- trace.info('connectionCreatedHandler', event);
462
- var connection = event.connection;
463
-
464
- if (!this.sessionExistsGuard(false) || !connection) {
465
- return;
466
- }
467
-
468
- var destinationRole = JSON.parse(connection.data).clientRole;
469
- this.createStreamForPublishing(destinationRole).then(function (streams) {
470
- var peerConnection = {
471
- peerId: connection.connectionId,
472
- peerRole: destinationRole,
473
- peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR ? MediaConstants_1.SessionClientType.GUEST : MediaConstants_1.SessionClientType.INITIATOR,
474
- connection: connection,
475
- publisher: null,
476
- subscriber: null,
477
- remoteMediaTracks: [],
478
- localStream: streams,
479
- connectionTimoutPrt: null
480
- };
481
-
482
- if (connection.connectionId !== _this.ownPeerId || !streams.videoSource && !streams.audioSource) {
483
- trace.info('Peer connection without publisher was created', peerConnection);
484
- return peerConnection;
485
- }
486
-
487
- return _this.createMediaPublisher(streams).then(function (publisher) {
488
- peerConnection.publisher = publisher;
489
- trace.info('Peer connection with publisher was created', peerConnection);
490
- return peerConnection;
491
- });
492
- }).then(function (peerConnection) {
493
- _this._peerConnections.set(peerConnection.peerId, peerConnection);
494
-
495
- if (connection.connectionId === _this.ownPeerId) {
496
- trace.info('Before subscribe the event streams');
497
- return _this._lastStreamEvents.reduce(function (promiseChain, streamEvent) {
498
- return promiseChain.then(function () {
499
- return _this.streamCreatedHandler(streamEvent);
500
- });
501
- }, bluebird_1.Promise.resolve()).then(function () {
502
- if (peerConnection.publisher) {
503
- trace.info('Starting publish to peerConnection.publisher');
504
- return _this._session.publish(peerConnection.publisher)["catch"](function (err) {
505
- trace.info('Error during publish', peerConnection.publisher);
506
-
507
- if (peerConnection.publisher) {
508
- trace.info('Error during publish- unpublish');
509
-
510
- _this._session.unpublish(peerConnection.publisher);
511
- }
512
-
513
- throw err;
128
+ return bluebird_1.Promise.all(promises).then(function () { return trace.info('onMediaStreamDestroyed: Success'); });
129
+ };
130
+ MediaServerSession.prototype.onPublisherDestroyed = function (connectionId) {
131
+ trace.info('onPublisherDestroyed');
132
+ var peerConnection = this._peerConnections.get(connectionId);
133
+ if (!peerConnection) {
134
+ return bluebird_1.Promise.resolve();
135
+ }
136
+ return this.destroyPublisherOnPeerConnection(peerConnection);
137
+ };
138
+ MediaServerSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
139
+ return bluebird_1.Promise.resolve(undefined);
140
+ };
141
+ MediaServerSession.prototype.replaceStreamTracks = function (mediaStream) {
142
+ return bluebird_1.Promise.reject(new Error('Not implemented'));
143
+ };
144
+ MediaServerSession.prototype.initSessionEvents = function () {
145
+ var _this = this;
146
+ if (!this._session) {
147
+ return;
148
+ }
149
+ this._sessionParams.initHandlers && this._sessionParams.initHandlers();
150
+ this._lastStreamEvents = [];
151
+ this._session.on('connectionCreated', this.connectionCreatedHandler);
152
+ this._session.on('streamCreated', this.streamCreatedHandler);
153
+ this._session.on('streamDestroyed', this.streamDestroyedHandler);
154
+ this._session.on('connectionDestroyed', this.connectionDestroyedHandler);
155
+ this._session.on('recordingStarted', function (event) {
156
+ trace.info('recordingStarted event', event);
157
+ _this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STARTED, event);
158
+ });
159
+ this._session.on('recordingStopped', function (event) {
160
+ trace.info('recordingStopped event', event);
161
+ _this.emitEvent(MediaSessionBase_1.recordingEvents.RECORD_STOPPED, event);
162
+ });
163
+ this._session.on('reconnecting', function () {
164
+ trace.info('reconnecting event');
165
+ _this.emitEvent(MediaSessionBase_1.recordingEvents.RECONNECTING);
166
+ });
167
+ this._session.on('sessionDisconnected', this.disconnect);
168
+ };
169
+ MediaServerSession.prototype.streamDestroyedHandler = function (event) {
170
+ trace.info('streamDestroyedHandler', event);
171
+ var stream = event.stream;
172
+ if (!this.sessionExistsGuard(false) || !stream) {
173
+ return;
174
+ }
175
+ var peerConnection = this._peerConnections.get(stream.connection.connectionId);
176
+ if (!peerConnection) {
177
+ trace.warn('Peer connection for remote stream not found');
178
+ return;
179
+ }
180
+ this.destroySubscriberOnPeerConnection(peerConnection).catch(function () { return undefined; });
181
+ };
182
+ MediaServerSession.prototype.connectionDestroyedHandler = function (event) {
183
+ trace.info('connectionDestroyedHandler', event);
184
+ var connection = event.connection;
185
+ if (!this.sessionExistsGuard(false) || !connection) {
186
+ return;
187
+ }
188
+ if (this._peerConnections.has(connection.connectionId)) {
189
+ var peerConnection = this._peerConnections.get(connection.connectionId);
190
+ this.destroySubscriberOnPeerConnection(peerConnection).catch(function () { return undefined; });
191
+ }
192
+ };
193
+ MediaServerSession.prototype.destroyPeerConnection = function (peerConnection) {
194
+ trace.info('destroyPeerConnection');
195
+ this._peerConnections.delete(peerConnection.peerId);
196
+ return bluebird_1.Promise.all([
197
+ this.destroyPublisherOnPeerConnection(peerConnection),
198
+ this.destroySubscriberOnPeerConnection(peerConnection)
199
+ ])
200
+ .then(function () { return undefined; })
201
+ .catch(function () {
202
+ trace.warn('destroyPeerConnection - something wrong with destroy');
203
+ });
204
+ };
205
+ MediaServerSession.prototype.destroySubscriberOnPeerConnection = function (peerConnection) {
206
+ trace.info('destroySubscriberOnPeerConnection', peerConnection);
207
+ if (this.sessionExistsGuard(false) && peerConnection.subscriber) {
208
+ this._session.unsubscribe(peerConnection.subscriber);
209
+ }
210
+ trace.info('destroySubscriberOnPeerConnection- before unregisterPeersRemoteMediaTracks');
211
+ return this.unregisterPeersRemoteMediaTracks(peerConnection)
212
+ .catch(function () { return trace.warn('Error removing remote streams from peerConnection'); })
213
+ .then(function () {
214
+ trace.info('destroySubscriberOnPeerConnection- unregisterPeersRemoteMediaTracks successfully');
215
+ peerConnection.subscriber = null;
216
+ });
217
+ };
218
+ MediaServerSession.prototype.destroyPublisherOnPeerConnection = function (peerConnection) {
219
+ trace.info('destroyPublisherOnPeerConnection');
220
+ if (this.sessionExistsGuard(false) && peerConnection.publisher) {
221
+ trace.info('destroyPublisherOnPeerConnection- unpublish!');
222
+ this._session.unpublish(peerConnection.publisher);
223
+ }
224
+ peerConnection.publisher = null;
225
+ peerConnection.localStream = null;
226
+ return bluebird_1.Promise.resolve();
227
+ };
228
+ MediaServerSession.prototype.createMediaSubscriber = function (remoteStream) {
229
+ var _this = this;
230
+ trace.info('createMediaSubscriber');
231
+ return new bluebird_1.Promise(function (resolve, reject) {
232
+ if (!_this.sessionExistsGuard(false)) {
233
+ return reject('Session not exists');
234
+ }
235
+ trace.info('Before create subscriber');
236
+ var subscriber = _this._session.subscribe(remoteStream, '', {}, function (err) {
237
+ if (err) {
238
+ trace.warn('Error creating subscriber', err);
239
+ return reject(err);
240
+ }
241
+ trace.info('create subscriber successfully', subscriber);
242
+ return resolve(subscriber);
514
243
  });
515
- }
516
-
517
- return bluebird_1.Promise.resolve();
518
244
  });
519
- }
520
- })["catch"](function (error) {
521
- trace.error('Error handling new peer connection', error);
522
- });
523
- };
524
-
525
- MediaServerSession.prototype.sessionExistsGuard = function (shouldThrow) {
526
- if (shouldThrow === void 0) {
527
- shouldThrow = true;
528
- }
529
-
530
- var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
531
- return guards_1.throwableGuard(connected, 'There no MediaServer session exists', shouldThrow);
532
- };
533
-
534
- return MediaServerSession;
535
- }(MediaSessionBase_1.MediaSessionBase);
536
-
245
+ };
246
+ MediaServerSession.prototype.streamCreatedHandler = function (event) {
247
+ var _this = this;
248
+ if (!event) {
249
+ return bluebird_1.Promise.resolve();
250
+ }
251
+ trace.info('streamCreatedHandler', event.stream);
252
+ var stream = event.stream;
253
+ var connection = (stream || { connection: null }).connection;
254
+ if (!this.sessionExistsGuard(false) || !stream || connection.connectionId === this.ownPeerId) {
255
+ return bluebird_1.Promise.resolve();
256
+ }
257
+ if (!this._peerConnections.has(connection.connectionId)) {
258
+ trace.warn('Unexpected case, connection should exist, add to streams to subscribe list', event);
259
+ this._lastStreamEvents.push(event);
260
+ return bluebird_1.Promise.resolve();
261
+ }
262
+ var peerConnection = this._peerConnections.get(connection.connectionId);
263
+ trace.info('Subscribing the stream');
264
+ return this.createMediaSubscriber(stream).then(function (subscriber) {
265
+ peerConnection.subscriber = subscriber;
266
+ trace.info('Registering remote media tracks', peerConnection.subscriber);
267
+ subscriber.stream
268
+ .getMediaStream()
269
+ .getTracks()
270
+ .forEach(function (mediaTrack) {
271
+ _this.addRemoteTrackToPeer(peerConnection, mediaTrack);
272
+ });
273
+ return _this.registerPeersRemoteTracks(peerConnection);
274
+ });
275
+ };
276
+ MediaServerSession.prototype.createStreamForPublishing = function (destinationRole) {
277
+ var _this = this;
278
+ trace.info('createStreamForPublishing');
279
+ return this._sessionStreamsManager
280
+ .getMediaStreamForRole(destinationRole)
281
+ .then(function (mediaStream) {
282
+ var stream = { videoSource: null, audioSource: null };
283
+ if (mediaStream) {
284
+ trace.info('Media stream found for publishing', mediaStream);
285
+ mediaStream.getTracks().forEach(function (track) {
286
+ if (track.kind === 'video') {
287
+ stream.videoSource = track;
288
+ }
289
+ else if (track.kind === 'audio') {
290
+ stream.audioSource = track;
291
+ }
292
+ });
293
+ }
294
+ else if (_this._sessionParams.clientRole === MediaConstants_1.SessionClientRole.USER) {
295
+ trace.warn('No local media was found for publishing to destinationRole:', destinationRole);
296
+ }
297
+ return stream;
298
+ });
299
+ };
300
+ MediaServerSession.prototype.createMediaPublisher = function (stream) {
301
+ var _this = this;
302
+ var ovParams = {
303
+ videoSource: stream.videoSource ? stream.videoSource : false,
304
+ audioSource: stream.audioSource ? stream.audioSource : false,
305
+ publishAudio: !!stream.audioSource,
306
+ publishVideo: !!stream.videoSource
307
+ };
308
+ return new bluebird_1.Promise(function (resolve, reject) {
309
+ var ovPublisher = _this.OV.initPublisher('', ovParams, function (error) {
310
+ if (error) {
311
+ reject(error);
312
+ return;
313
+ }
314
+ ovPublisher.on('streamDestroyed', function (event) {
315
+ trace.info('Publisher stream destroyed', event);
316
+ var connectionId = (0, get_1.default)(event, 'stream.connection.connectionId');
317
+ _this.onPublisherDestroyed(connectionId);
318
+ event.preventDefault();
319
+ });
320
+ resolve(ovPublisher);
321
+ });
322
+ });
323
+ };
324
+ MediaServerSession.prototype.connectionCreatedHandler = function (event) {
325
+ var _this = this;
326
+ trace.info('connectionCreatedHandler', event);
327
+ var connection = event.connection;
328
+ if (!this.sessionExistsGuard(false) || !connection) {
329
+ return;
330
+ }
331
+ var destinationRole = JSON.parse(connection.data).clientRole;
332
+ this.createStreamForPublishing(destinationRole)
333
+ .then(function (streams) {
334
+ var peerConnection = {
335
+ peerId: connection.connectionId,
336
+ peerRole: destinationRole,
337
+ peerType: _this._sessionParams.clientType === MediaConstants_1.SessionClientType.INITIATOR
338
+ ? MediaConstants_1.SessionClientType.GUEST
339
+ : MediaConstants_1.SessionClientType.INITIATOR,
340
+ connection: connection,
341
+ publisher: null,
342
+ subscriber: null,
343
+ remoteMediaTracks: [],
344
+ localStream: streams,
345
+ connectionTimoutPrt: null
346
+ };
347
+ if (connection.connectionId !== _this.ownPeerId || (!streams.videoSource && !streams.audioSource)) {
348
+ trace.info('Peer connection without publisher was created', peerConnection);
349
+ return peerConnection;
350
+ }
351
+ return _this.createMediaPublisher(streams).then(function (publisher) {
352
+ peerConnection.publisher = publisher;
353
+ trace.info('Peer connection with publisher was created', peerConnection);
354
+ return peerConnection;
355
+ });
356
+ })
357
+ .then(function (peerConnection) {
358
+ _this._peerConnections.set(peerConnection.peerId, peerConnection);
359
+ if (connection.connectionId === _this.ownPeerId) {
360
+ trace.info('Before subscribe the event streams');
361
+ return _this._lastStreamEvents
362
+ .reduce(function (promiseChain, streamEvent) {
363
+ return promiseChain.then(function () { return _this.streamCreatedHandler(streamEvent); });
364
+ }, bluebird_1.Promise.resolve())
365
+ .then(function () {
366
+ if (peerConnection.publisher) {
367
+ trace.info('Starting publish to peerConnection.publisher');
368
+ return _this._session.publish(peerConnection.publisher).catch(function (err) {
369
+ trace.info('Error during publish', peerConnection.publisher);
370
+ if (peerConnection.publisher) {
371
+ trace.info('Error during publish- unpublish');
372
+ _this._session.unpublish(peerConnection.publisher);
373
+ }
374
+ throw err;
375
+ });
376
+ }
377
+ return bluebird_1.Promise.resolve();
378
+ });
379
+ }
380
+ })
381
+ .catch(function (error) {
382
+ trace.error('Error handling new peer connection', error);
383
+ });
384
+ };
385
+ MediaServerSession.prototype.sessionExistsGuard = function (shouldThrow) {
386
+ if (shouldThrow === void 0) { shouldThrow = true; }
387
+ var connected = !!(this._session && this._session.connection && this._session.connection.connectionId);
388
+ return (0, guards_1.throwableGuard)(connected, 'There no MediaServer session exists', shouldThrow);
389
+ };
390
+ return MediaServerSession;
391
+ }(MediaSessionBase_1.MediaSessionBase));
537
392
  exports.MediaServerSession = MediaServerSession;
538
- //# sourceMappingURL=MediaServer.js.map
393
+ //# sourceMappingURL=MediaServer.js.map