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