@techsee/techsee-media-service 999.20.0-nodejs.lite.2 → 999.20.1-alpha

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 (205) hide show
  1. package/README.md +28 -27
  2. package/lib/LocalStreamManager.d.ts +0 -1
  3. package/lib/LocalStreamManager.d.ts.map +1 -1
  4. package/lib/LocalStreamManager.js +84 -82
  5. package/lib/LocalStreamManager.js.map +1 -1
  6. package/lib/MediaConstants.d.ts +3 -21
  7. package/lib/MediaConstants.d.ts.map +1 -1
  8. package/lib/MediaConstants.js +13 -32
  9. package/lib/MediaConstants.js.map +1 -1
  10. package/lib/MediaContracts.d.ts +3 -9
  11. package/lib/MediaContracts.d.ts.map +1 -1
  12. package/lib/MediaContracts.js +4 -1
  13. package/lib/MediaContracts.js.map +1 -1
  14. package/lib/MediaPublisher.d.ts +0 -1
  15. package/lib/MediaPublisher.d.ts.map +1 -1
  16. package/lib/MediaPublisher.js +10 -7
  17. package/lib/MediaPublisher.js.map +1 -1
  18. package/lib/MediaServiceBase.d.ts +0 -1
  19. package/lib/MediaServiceBase.d.ts.map +1 -1
  20. package/lib/MediaServiceBase.js +199 -170
  21. package/lib/MediaServiceBase.js.map +1 -1
  22. package/lib/MediaSession/MediaServer.d.ts +0 -1
  23. package/lib/MediaSession/MediaServer.d.ts.map +1 -1
  24. package/lib/MediaSession/MediaServer.js +74 -62
  25. package/lib/MediaSession/MediaServer.js.map +1 -1
  26. package/lib/MediaSession/MediaSessionBase.d.ts +0 -1
  27. package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
  28. package/lib/MediaSession/MediaSessionBase.js +23 -19
  29. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  30. package/lib/MediaSession/SessionOpentok.d.ts +2 -3
  31. package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
  32. package/lib/MediaSession/SessionOpentok.js +80 -51
  33. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  34. package/lib/MediaSession/SessionTurn.d.ts +0 -1
  35. package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
  36. package/lib/MediaSession/SessionTurn.js +151 -109
  37. package/lib/MediaSession/SessionTurn.js.map +1 -1
  38. package/lib/MediaSession/TurnConstants.d.ts +0 -1
  39. package/lib/MediaSession/TurnConstants.d.ts.map +1 -1
  40. package/lib/MediaSession/TurnConstants.js +16 -1
  41. package/lib/MediaSession/TurnConstants.js.map +1 -1
  42. package/lib/MediaSubscriber.d.ts +0 -1
  43. package/lib/MediaSubscriber.d.ts.map +1 -1
  44. package/lib/MediaSubscriber.js +43 -37
  45. package/lib/MediaSubscriber.js.map +1 -1
  46. package/lib/MediaUtils/Compatibility.d.ts +0 -3
  47. package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
  48. package/lib/MediaUtils/Compatibility.js +34 -76
  49. package/lib/MediaUtils/Compatibility.js.map +1 -1
  50. package/lib/MediaUtils/MediaDomUtils.d.ts +3 -6
  51. package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
  52. package/lib/MediaUtils/MediaDomUtils.js +65 -70
  53. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  54. package/lib/MediaUtils/MediaTracer.d.ts +0 -1
  55. package/lib/MediaUtils/MediaTracer.d.ts.map +1 -1
  56. package/lib/MediaUtils/MediaTracer.js +5 -2
  57. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  58. package/lib/MultiParty/DetectWebRtcService.d.ts +14 -17
  59. package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -1
  60. package/lib/MultiParty/DetectWebRtcService.js +54 -98
  61. package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
  62. package/lib/MultiParty/MediaCapabilitiesHelper.d.ts +10 -0
  63. package/lib/MultiParty/MediaCapabilitiesHelper.d.ts.map +1 -0
  64. package/lib/MultiParty/MediaCapabilitiesHelper.js +140 -0
  65. package/lib/MultiParty/MediaCapabilitiesHelper.js.map +1 -0
  66. package/lib/MultiParty/MultiParty.d.ts +21 -0
  67. package/lib/MultiParty/MultiParty.d.ts.map +1 -0
  68. package/lib/MultiParty/MultiParty.js +160 -0
  69. package/lib/MultiParty/MultiParty.js.map +1 -0
  70. package/lib/MultiParty/OpentokMultiparty.d.ts +32 -0
  71. package/lib/MultiParty/OpentokMultiparty.d.ts.map +1 -0
  72. package/lib/MultiParty/OpentokMultiparty.js +184 -0
  73. package/lib/MultiParty/OpentokMultiparty.js.map +1 -0
  74. package/lib/TechseeMediaStream.d.ts +0 -1
  75. package/lib/TechseeMediaStream.d.ts.map +1 -1
  76. package/lib/TechseeMediaStream.js +12 -9
  77. package/lib/TechseeMediaStream.js.map +1 -1
  78. package/lib/oldCode/constants.js +20 -0
  79. package/lib/oldCode/constants.js.map +1 -0
  80. package/lib/oldCode/event-emitter.js +39 -0
  81. package/lib/oldCode/event-emitter.js.map +1 -0
  82. package/lib/oldCode/index.js +64 -0
  83. package/lib/oldCode/index.js.map +1 -0
  84. package/lib/oldCode/opentok/session.js +310 -0
  85. package/lib/oldCode/opentok/session.js.map +1 -0
  86. package/lib/oldCode/opentok/stream.js +310 -0
  87. package/lib/oldCode/opentok/stream.js.map +1 -0
  88. package/lib/oldCode/publisher.js +143 -0
  89. package/lib/oldCode/publisher.js.map +1 -0
  90. package/lib/oldCode/service.js +395 -0
  91. package/lib/oldCode/service.js.map +1 -0
  92. package/lib/oldCode/session.js +110 -0
  93. package/lib/oldCode/session.js.map +1 -0
  94. package/lib/oldCode/stream.js +195 -0
  95. package/lib/oldCode/stream.js.map +1 -0
  96. package/lib/oldCode/subscriber.js +90 -0
  97. package/lib/oldCode/subscriber.js.map +1 -0
  98. package/lib/oldCode/tracer.d.ts +36 -0
  99. package/lib/oldCode/tracer.d.ts.map +1 -0
  100. package/lib/oldCode/tracer.js +161 -0
  101. package/lib/oldCode/tracer.js.map +1 -0
  102. package/lib/oldCode/utils/ImageFixer.d.ts +1 -0
  103. package/lib/oldCode/utils/ImageFixer.d.ts.map +1 -0
  104. package/lib/oldCode/utils/ImageFixer.js +59 -0
  105. package/lib/oldCode/utils/ImageFixer.js.map +1 -0
  106. package/lib/oldCode/webrtc/constants.js +114 -0
  107. package/lib/oldCode/webrtc/constants.js.map +1 -0
  108. package/lib/oldCode/webrtc/helper.js +173 -0
  109. package/lib/oldCode/webrtc/helper.js.map +1 -0
  110. package/lib/oldCode/webrtc/session-kms.js +558 -0
  111. package/lib/oldCode/webrtc/session-kms.js.map +1 -0
  112. package/lib/oldCode/webrtc/session-loopback.js +336 -0
  113. package/lib/oldCode/webrtc/session-loopback.js.map +1 -0
  114. package/lib/oldCode/webrtc/session-turn.js +880 -0
  115. package/lib/oldCode/webrtc/session-turn.js.map +1 -0
  116. package/lib/oldCode/webrtc/session-turn.v2.js +583 -0
  117. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -0
  118. package/lib/oldCode/webrtc/session.js +52 -0
  119. package/lib/oldCode/webrtc/session.js.map +1 -0
  120. package/lib/oldCode/webrtc/stream.js +674 -0
  121. package/lib/oldCode/webrtc/stream.js.map +1 -0
  122. package/lib/oldCode/webrtc/temasys/adapter-loader.js +12 -0
  123. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -0
  124. package/lib/oldCode/webrtc/temasys/adapter.js +5861 -0
  125. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -0
  126. package/lib/oldCode/webrtc/webrtc-ie-shim.js +3007 -0
  127. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -0
  128. package/lib/qos/raw-qos.js +145 -84
  129. package/lib/qos/raw-qos.js.map +1 -1
  130. package/lib/webrtc-ie-shim.js +2950 -1896
  131. package/lib/webrtc-ie-shim.js.map +1 -1
  132. package/package.json +59 -65
  133. package/lib/MediaUtils/index.d.ts +0 -2
  134. package/lib/MediaUtils/index.d.ts.map +0 -1
  135. package/lib/MediaUtils/index.js +0 -6
  136. package/lib/MediaUtils/index.js.map +0 -1
  137. package/lib/MultiParty/MediaCapabilitiesService.d.ts +0 -18
  138. package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +0 -1
  139. package/lib/MultiParty/MediaCapabilitiesService.js +0 -158
  140. package/lib/MultiParty/MediaCapabilitiesService.js.map +0 -1
  141. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +0 -6
  142. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +0 -1
  143. package/lib/MultiParty/MediaCapabilitiesUtils.js +0 -123
  144. package/lib/MultiParty/MediaCapabilitiesUtils.js.map +0 -1
  145. package/lib/MultiParty/MediaTracer.d.ts +0 -4
  146. package/lib/MultiParty/MediaTracer.d.ts.map +0 -1
  147. package/lib/MultiParty/MediaTracer.js +0 -10
  148. package/lib/MultiParty/MediaTracer.js.map +0 -1
  149. package/lib/MultiParty/MultiPartyService.d.ts +0 -49
  150. package/lib/MultiParty/MultiPartyService.d.ts.map +0 -1
  151. package/lib/MultiParty/MultiPartyService.js +0 -30
  152. package/lib/MultiParty/MultiPartyService.js.map +0 -1
  153. package/lib/MultiParty/MultiPartyServiceFactory.d.ts +0 -4
  154. package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +0 -1
  155. package/lib/MultiParty/MultiPartyServiceFactory.js +0 -13
  156. package/lib/MultiParty/MultiPartyServiceFactory.js.map +0 -1
  157. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +0 -89
  158. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +0 -1
  159. package/lib/MultiParty/MultipartyServiceEventTypes.js +0 -16
  160. package/lib/MultiParty/MultipartyServiceEventTypes.js.map +0 -1
  161. package/lib/MultiParty/index.d.ts +0 -7
  162. package/lib/MultiParty/index.d.ts.map +0 -1
  163. package/lib/MultiParty/index.js +0 -25
  164. package/lib/MultiParty/index.js.map +0 -1
  165. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts +0 -38
  166. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +0 -1
  167. package/lib/MultiParty/opentok/OpentokMultiPartyService.js +0 -492
  168. package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +0 -1
  169. package/lib/MultiParty/opentok/OpentokPublisher.d.ts +0 -34
  170. package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +0 -1
  171. package/lib/MultiParty/opentok/OpentokPublisher.js +0 -121
  172. package/lib/MultiParty/opentok/OpentokPublisher.js.map +0 -1
  173. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts +0 -20
  174. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts.map +0 -1
  175. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js +0 -49
  176. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js.map +0 -1
  177. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts +0 -6
  178. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts.map +0 -1
  179. package/lib/MultiParty/opentok/OpentokScreenPublisher.js +0 -48
  180. package/lib/MultiParty/opentok/OpentokScreenPublisher.js.map +0 -1
  181. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +0 -2
  182. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +0 -1
  183. package/lib/MultiParty/opentok/OpentokSubscriber.js +0 -26
  184. package/lib/MultiParty/opentok/OpentokSubscriber.js.map +0 -1
  185. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts +0 -19
  186. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts.map +0 -1
  187. package/lib/MultiParty/opentok/OpentokVideoPublisher.js +0 -182
  188. package/lib/MultiParty/opentok/OpentokVideoPublisher.js.map +0 -1
  189. package/lib/MultiParty/opentok/trace.d.ts +0 -3
  190. package/lib/MultiParty/opentok/trace.d.ts.map +0 -1
  191. package/lib/MultiParty/opentok/trace.js +0 -18
  192. package/lib/MultiParty/opentok/trace.js.map +0 -1
  193. package/lib/MultiParty/opentok.d.ts +0 -463
  194. package/lib/MultiParty/types.d.ts +0 -33
  195. package/lib/MultiParty/types.d.ts.map +0 -1
  196. package/lib/MultiParty/types.js +0 -3
  197. package/lib/MultiParty/types.js.map +0 -1
  198. package/lib/MultiParty/utils.d.ts +0 -10
  199. package/lib/MultiParty/utils.d.ts.map +0 -1
  200. package/lib/MultiParty/utils.js +0 -17
  201. package/lib/MultiParty/utils.js.map +0 -1
  202. package/lib/qos/raw-qos.d.ts +0 -29
  203. package/lib/qos/raw-qos.d.ts.map +0 -1
  204. package/lib/webrtc-ie-shim.d.ts +0 -4
  205. package/lib/webrtc-ie-shim.d.ts.map +0 -1
@@ -1,44 +1,48 @@
1
1
  "use strict";
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);
2
+
3
+ var __extends = undefined && undefined.__extends || function () {
4
+ var _extendStatics = function extendStatics(d, b) {
5
+ _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
6
+ d.__proto__ = b;
7
+ } || function (d, b) {
8
+ for (var p in b) {
9
+ if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
10
+ }
11
+ };
12
+ return _extendStatics(d, b);
8
13
  };
9
14
  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; }
15
+ _extendStatics(d, b);
16
+ function __() {
17
+ this.constructor = d;
18
+ }
14
19
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
20
  };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ }();
22
+ var __createBinding = undefined && undefined.__createBinding || (Object.create ? function (o, m, k, k2) {
18
23
  if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
24
+ Object.defineProperty(o, k2, { enumerable: true, get: function get() {
25
+ return m[k];
26
+ } });
27
+ } : function (o, m, k, k2) {
25
28
  if (k2 === undefined) k2 = k;
26
29
  o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ });
31
+ var __setModuleDefault = undefined && undefined.__setModuleDefault || (Object.create ? function (o, v) {
29
32
  Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
33
+ } : function (o, v) {
31
34
  o["default"] = v;
32
35
  });
33
- var __importStar = (this && this.__importStar) || function (mod) {
36
+ var __importStar = undefined && undefined.__importStar || function (mod) {
34
37
  if (mod && mod.__esModule) return mod;
35
38
  var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
39
+ if (mod != null) for (var k in mod) {
40
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
41
+ }__setModuleDefault(result, mod);
38
42
  return result;
39
43
  };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
44
+ var __importDefault = undefined && undefined.__importDefault || function (mod) {
45
+ return mod && mod.__esModule ? mod : { "default": mod };
42
46
  };
43
47
  Object.defineProperty(exports, "__esModule", { value: true });
44
48
  exports.TurnWebRtcSession = void 0;
@@ -48,19 +52,22 @@ var MediaConstants_1 = require("../MediaConstants");
48
52
  var TurnConstants_1 = require("./TurnConstants");
49
53
  var MediaTracer_1 = require("../MediaUtils/MediaTracer");
50
54
  var MediaSessionBase_1 = require("./MediaSessionBase");
51
- var trace = (0, MediaTracer_1.getMediaTracer)('TurnWebRtcSession');
52
- var TurnWebRtcSession = (function (_super) {
55
+ var trace = MediaTracer_1.getMediaTracer('TurnWebRtcSession');
56
+ //Currently this version supports subscribing only. Publishing will be implemented as needed.
57
+ var TurnWebRtcSession = /** @class */function (_super) {
53
58
  __extends(TurnWebRtcSession, _super);
54
59
  function TurnWebRtcSession(sessionParams, sessionHandlers, streamFactory) {
55
60
  var _this = _super.call(this, sessionParams, streamFactory) || this;
56
61
  _this._sessionHandlers = sessionHandlers;
57
62
  _this._socket = null;
58
63
  _this._pendingPeersIce = {};
59
- var iceServers = sessionParams.credentials.ice.map(function (item) { return ({
60
- urls: item.url,
61
- username: item.login,
62
- credential: item.password
63
- }); });
64
+ var iceServers = sessionParams.credentials.ice.map(function (item) {
65
+ return {
66
+ urls: item.url,
67
+ username: item.login,
68
+ credential: item.password
69
+ };
70
+ });
64
71
  _this._configuration = {
65
72
  iceServers: iceServers,
66
73
  iceTransportPolicy: 'relay'
@@ -75,25 +82,26 @@ var TurnWebRtcSession = (function (_super) {
75
82
  return _this;
76
83
  }
77
84
  Object.defineProperty(TurnWebRtcSession.prototype, "id", {
78
- get: function () {
85
+ get: function get() {
79
86
  return this._sessionParams.sessionId;
80
87
  },
81
88
  enumerable: false,
82
89
  configurable: true
83
90
  });
91
+ //#region Socket Connectivity
84
92
  TurnWebRtcSession.prototype.connect = function (connectOnly) {
85
93
  var _this = this;
86
- if (connectOnly === void 0) { connectOnly = false; }
94
+ if (connectOnly === void 0) {
95
+ connectOnly = false;
96
+ }
87
97
  trace.info('Connect to session');
88
- return this._connectSocket(this._sessionParams.credentials.url, connectOnly)
89
- .then(function () {
98
+ return this._connectSocket(this._sessionParams.credentials.url, connectOnly).then(function () {
90
99
  trace.info('Joining SessionId: ' + _this._sessionParams.sessionId);
91
100
  _this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
92
101
  clientType: _this._sessionParams.clientType,
93
102
  sessionId: _this._sessionParams.sessionId
94
103
  });
95
- })
96
- .catch(function (error) {
104
+ }).catch(function (error) {
97
105
  throw error;
98
106
  });
99
107
  };
@@ -104,17 +112,19 @@ var TurnWebRtcSession = (function (_super) {
104
112
  TurnWebRtcSession.prototype._connectSocket = function (url, connectOnly) {
105
113
  var _this = this;
106
114
  return new Promise(function (resolve, reject) {
107
- var socket = (_this._socket = io.connect(url, {
108
- forceNew: true,
109
- reconnectionDelay: TurnConstants_1.SOCKET_RECONNECTION_DELAY,
110
- reconnectionDelayMax: TurnConstants_1.SOCKET_RECONNECTION_DELAY_MAX,
111
- reconnectionAttempts: TurnConstants_1.SOCKET_RECONNECTION_ATTEMPTS,
112
- path: TurnConstants_1.SOCKET_PATH
113
- }));
114
- var done = (0, once_1.default)(function (err) {
115
+ var socket = _this._socket = io.connect(url, {
116
+ 'forceNew': true,
117
+ 'reconnectionDelay': TurnConstants_1.SOCKET_RECONNECTION_DELAY,
118
+ 'reconnectionDelayMax': TurnConstants_1.SOCKET_RECONNECTION_DELAY_MAX,
119
+ 'reconnectionAttempts': TurnConstants_1.SOCKET_RECONNECTION_ATTEMPTS,
120
+ 'path': TurnConstants_1.SOCKET_PATH
121
+ });
122
+ var done = once_1.default(function (err) {
115
123
  err ? reject(err) : resolve();
116
124
  });
117
- socket.once('connect', function () { return done(); });
125
+ socket.once('connect', function () {
126
+ return done();
127
+ });
118
128
  socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ERROR, done);
119
129
  socket.on('connect_error', done);
120
130
  socket.on('connect_timeout', done);
@@ -132,9 +142,14 @@ var TurnWebRtcSession = (function (_super) {
132
142
  };
133
143
  TurnWebRtcSession.prototype._onSocketDisconnectedHandler = function (reason) {
134
144
  if (this._socket) {
145
+ // The initial example of differentiating between "forced" disconnect and "network" disconnect is taken from:
146
+ // https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
135
147
  if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
136
148
  trace.info('_onSocketDisconnectedHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect);
137
- this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect).catch(function () { return undefined; });
149
+ // the disconnection was initiated by the server or by client, you need to call (connect) manually
150
+ this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect).catch(function () {
151
+ return undefined;
152
+ });
138
153
  }
139
154
  }
140
155
  };
@@ -144,12 +159,12 @@ var TurnWebRtcSession = (function (_super) {
144
159
  trace.info('replaceStreamTracks - Replace local tracks to peer connection');
145
160
  this._peerConnections.forEach(function (peerConnection) {
146
161
  mediaStream.getTracks().forEach(function (track) {
147
- var sender = peerConnection.getSenders().find(function (s) { return s.track.kind === track.kind; });
162
+ var sender = peerConnection.getSenders().find(function (s) {
163
+ return s.track.kind === track.kind;
164
+ });
148
165
  if (sender) {
149
- promises.push(sender
150
- .replaceTrack(track)
151
- .then(function () {
152
- return trace.info("replaceStreamTracks - Local ".concat(track.kind, " ").concat(track.id, " track replace to peer connection"));
166
+ promises.push(sender.replaceTrack(track).then(function () {
167
+ return trace.info("replaceStreamTracks - Local " + track.kind + " " + track.id + " track replace to peer connection");
153
168
  }));
154
169
  }
155
170
  });
@@ -160,29 +175,33 @@ var TurnWebRtcSession = (function (_super) {
160
175
  trace.info('replaceStreamTracks: replace stream tracks - Success');
161
176
  });
162
177
  };
178
+ //#endregion
179
+ //#region WebRTC Initiator - session Initiator (User on mobile device)
180
+ // Received by Initiator, causing him to emit SDP_OFFER
163
181
  TurnWebRtcSession.prototype._sendOfferHandler = function (sendOfferEventData) {
164
182
  var _this = this;
165
- var uid = sendOfferEventData.uid, peerId = sendOfferEventData.peerId;
183
+ var uid = sendOfferEventData.uid,
184
+ peerId = sendOfferEventData.peerId;
166
185
  trace.info('_sendOfferHandler');
186
+ //Currently we not support of passing role through signaling, so we assume every connection is "AGENT" like
167
187
  var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.GUEST, MediaConstants_1.SessionClientRole.AGENT);
168
188
  var offerParams = { offerToReceiveAudio: true, offerToReceiveVideo: true };
169
- this._sessionStreamsManager
170
- .getMediaStreamForRole(MediaConstants_1.SessionClientRole.AGENT)
171
- .then(function (mediaStream) {
189
+ //TODO - Alex: Currently we not sending "role" through signaling, and by default we assume that the one who asks fot offer, is agent.
190
+ //On later stages we can send or the client "role" or the list of "streams" that peer is interested in.
191
+ this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.AGENT).then(function (mediaStream) {
172
192
  trace.info('_sendOfferHandler stream and peer created');
173
193
  if (mediaStream) {
174
194
  trace.info('Adding local tracks to peer connection for sending offer');
175
195
  mediaStream.getTracks().forEach(function (track) {
176
196
  peerConnection.addTrack(track, mediaStream);
177
- trace.info("Local ".concat(track.kind, " ").concat(track.id, " track added to peer connection"));
197
+ trace.info("Local " + track.kind + " " + track.id + " track added to peer connection");
178
198
  });
179
- }
180
- else {
199
+ } else {
181
200
  trace.info('No media stream was found for publishing');
182
201
  }
183
- })
184
- .then(function () { return peerConnection.createOffer(offerParams); })
185
- .then(function (offerDesc) {
202
+ }).then(function () {
203
+ return peerConnection.createOffer(offerParams);
204
+ }).then(function (offerDesc) {
186
205
  trace.info('Initiator has created sdp offer', { offerDesc: offerDesc });
187
206
  _this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
188
207
  uid: uid,
@@ -193,65 +212,68 @@ var TurnWebRtcSession = (function (_super) {
193
212
  return peerConnection.setLocalDescription(offerDesc).then(function () {
194
213
  trace.info('Local description was set on peerConnection', peerConnection);
195
214
  _this._setPeerConnectionMonitor(peerConnection);
215
+ // make sure using the tracks of the last stream that used
196
216
  if (window.latestUserMediaStream && window.mediaStreamAlreadyReplaced) {
197
217
  _this.replaceStreamTracks(window.latestUserMediaStream.mediaStream).catch(function (e) {
198
218
  return trace.warn('_sendOfferHandler - Failed to replaceStreamTrace', e);
199
219
  });
200
220
  }
201
221
  });
202
- })
203
- .catch(function (e) {
222
+ }).catch(function (e) {
204
223
  trace.warn('Error', e);
205
224
  });
206
225
  };
226
+ // Received by the Initiator: Indicates that publish should be started
207
227
  TurnWebRtcSession.prototype._joinResponseHandler = function (joinResponseData) {
208
228
  var _this = this;
209
- var sdpAnswer = joinResponseData.sdpAnswer, uid = joinResponseData.uid, peerId = joinResponseData.peerId;
229
+ var sdpAnswer = joinResponseData.sdpAnswer,
230
+ uid = joinResponseData.uid,
231
+ peerId = joinResponseData.peerId;
210
232
  trace.info('joinResponse Received', { sdpAnswer: sdpAnswer });
211
233
  this._withPeerConnection(peerId, function (peerConnection) {
212
234
  var answer = new RTCSessionDescription({
213
235
  type: 'answer',
214
236
  sdp: sdpAnswer
215
237
  });
216
- peerConnection
217
- .setRemoteDescription(answer)
218
- .then(function () {
238
+ peerConnection.setRemoteDescription(answer).then(function () {
219
239
  trace.info('Remote description was set', answer);
220
240
  _this._processQueuedIceCandidates(peerId);
221
- })
222
- .catch(function (e) {
241
+ }).catch(function (e) {
223
242
  trace.warn('Error', e);
224
243
  });
225
244
  });
226
245
  };
246
+ // Received by Initiator after a guests socket has been disconnected
227
247
  TurnWebRtcSession.prototype._peerDisconnectedHandler = function (peerDisconnectedEvent) {
228
248
  var _this = this;
229
249
  var peerId = peerDisconnectedEvent.peerId;
230
250
  trace.info('_peerDisconnectedHandler');
231
251
  this._withPeerConnection(peerId, function (peerConnection) {
232
252
  _this._destroyPeerConnection(peerConnection);
253
+ //this._disconnectInternal(MediaSessionDisconnectReason.PeerDisconnected).catch(() => undefined);
233
254
  });
234
255
  };
256
+ //#endregion WebRTC Initiator - session Initiator (User on mobile device)
257
+ //#region WebRTC Guest - session Guest (Agent on dashboard platform)
258
+ // Received by Guest, causing him to emit SDP_ANSWER
235
259
  TurnWebRtcSession.prototype._sdpOfferHandler = function (sdpOfferEvent) {
236
260
  var _this = this;
237
- var sdpOffer = sdpOfferEvent.sdpOffer, peerId = sdpOfferEvent.peerId, uid = sdpOfferEvent.uid;
261
+ var sdpOffer = sdpOfferEvent.sdpOffer,
262
+ peerId = sdpOfferEvent.peerId,
263
+ uid = sdpOfferEvent.uid;
238
264
  trace.info('sdpOffer Received', { sdpOffer: sdpOffer });
239
265
  var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.INITIATOR, MediaConstants_1.SessionClientRole.USER);
240
- this._sessionStreamsManager
241
- .getMediaStreamForRole(MediaConstants_1.SessionClientRole.USER)
242
- .then(function (mediaStream) {
266
+ this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.USER).then(function (mediaStream) {
243
267
  if (mediaStream) {
244
268
  trace.info('Adding local tracks to peer connection offer handler');
245
269
  mediaStream.getTracks().forEach(function (track) {
246
270
  peerConnection.addTrack(track, mediaStream);
247
- trace.info("Local ".concat(track.kind, " track added to peer connection"));
271
+ trace.info("Local " + track.kind + " track added to peer connection");
248
272
  });
249
- }
250
- else {
273
+ } else {
251
274
  trace.info('No media stream was found for publishing');
252
275
  }
253
- })
254
- .then(function () {
276
+ }).then(function () {
255
277
  var remoteDesc = new RTCSessionDescription({ type: 'offer', sdp: sdpOffer });
256
278
  return peerConnection.setRemoteDescription(remoteDesc).then(function () {
257
279
  trace.info('Remote description was set', remoteDesc);
@@ -270,27 +292,34 @@ var TurnWebRtcSession = (function (_super) {
270
292
  });
271
293
  });
272
294
  });
273
- })
274
- .catch(function (e) {
295
+ }).catch(function (e) {
275
296
  trace.error('Error in _sdpOfferHandler', e);
276
297
  throw e;
277
298
  });
278
299
  };
300
+ // Received by Guest after an Initiator reconnects to room
279
301
  TurnWebRtcSession.prototype._initiatorPeerReconnectHandler = function () {
280
302
  trace.info('_initiatorPeerReconnectHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.InitiatorPeerReconnected);
281
303
  this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.InitiatorPeerReconnected).catch(function (error) {
282
304
  trace.warn('Error while disconnecting during userPeerReconnectHandler.', error);
283
305
  });
284
306
  };
307
+ //#endregion WebRTC Guest - session Guest (Agent on dashboard platform)
308
+ //#region Peer Connection
309
+ //#region Streams Handling
285
310
  TurnWebRtcSession.prototype.onMediaStreamDestroyed = function (clientRole) {
286
311
  var _this = this;
312
+ //TODO - Alex: need to implement adding new tracks to peer connection and forcing negotiation
287
313
  trace.info('onMediaStreamDestroyed disconnect all peer connections from session', MediaConstants_1.MediaSessionDisconnectReason.PublishedStreamDestroyed);
288
314
  this._peerConnections.forEach(function (peerConnection) {
289
- _this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PublishedStreamDestroyed).catch(function () { return undefined; });
315
+ _this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PublishedStreamDestroyed).catch(function () {
316
+ return undefined;
317
+ });
290
318
  });
291
319
  return Promise.resolve();
292
320
  };
293
321
  TurnWebRtcSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
322
+ //TODO - Alex: need to implement adding new tracks to peer connection and forcing negotiation
294
323
  return Promise.resolve();
295
324
  };
296
325
  TurnWebRtcSession.prototype.getRemoteTrackStats = function (mediaTrack) {
@@ -300,6 +329,7 @@ var TurnWebRtcSession = (function (_super) {
300
329
  }
301
330
  return Promise.reject(new Error('Provided track is not remote track'));
302
331
  };
332
+ //#endregion
303
333
  TurnWebRtcSession.prototype._disconnectInternal = function (reason) {
304
334
  var _this = this;
305
335
  this._peerConnections.forEach(function (peerConnection) {
@@ -309,14 +339,16 @@ var TurnWebRtcSession = (function (_super) {
309
339
  trace.info('Disconnecting from session', reason);
310
340
  this.sessionDisconnect();
311
341
  this._socket = null;
312
- setTimeout(function () { return _this._sessionHandlers.onDisconnectedHandler(reason); });
342
+ setTimeout(function () {
343
+ return _this._sessionHandlers.onDisconnectedHandler(reason);
344
+ });
313
345
  }
314
346
  return Promise.resolve();
315
347
  };
316
348
  TurnWebRtcSession.prototype._createPeerConnection = function (peerId, peerConnectionType, peerConnectionRole) {
317
349
  var _this = this;
318
350
  if (this._peerConnections.get(peerId)) {
319
- throw new Error("".concat(this._sessionParams.clientType, " peer connection for ").concat(peerId, " already exists"));
351
+ throw new Error(this._sessionParams.clientType + " peer connection for " + peerId + " already exists");
320
352
  }
321
353
  var peerConnection = new RTCPeerConnection(this._configuration);
322
354
  peerConnection.peerId = peerId;
@@ -328,40 +360,38 @@ var TurnWebRtcSession = (function (_super) {
328
360
  trace.info('onconnectionstatechange', peerConnection);
329
361
  };
330
362
  peerConnection.oniceconnectionstatechange = function (state) {
331
- trace.info("ICE Connection state for peer ".concat(peerId, " was changed to: ").concat(state.currentTarget.iceConnectionState), state);
363
+ trace.info("ICE Connection state for peer " + peerId + " was changed to: " + state.currentTarget.iceConnectionState, state);
332
364
  var cnState = state.currentTarget.iceConnectionState;
333
365
  clearTimeout(peerConnection.connectionTimoutPrt);
334
366
  if (['closed', 'disconnected', 'failed'].indexOf(cnState) > -1) {
335
367
  _this._iceStateDisconnected(peerConnection);
336
- }
337
- else if (cnState === 'connected') {
368
+ } else if (cnState === 'connected') {
338
369
  _this.registerPeersRemoteTracks(peerConnection);
339
370
  }
340
371
  };
341
372
  peerConnection.onicecandidate = function (event) {
342
373
  if (event.candidate) {
343
- trace.info("".concat(_this._sessionParams.clientType, " peerConn.onicecandidate"), event.candidate);
374
+ trace.info(_this._sessionParams.clientType + " peerConn.onicecandidate", event.candidate);
344
375
  _this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
345
376
  sessionId: _this._sessionParams.sessionId,
346
377
  peerId: peerId,
347
378
  candidate: event.candidate,
348
379
  clientType: _this._sessionParams.clientType
349
380
  });
350
- }
351
- else {
381
+ } else {
352
382
  trace.info('ICE Candidate is null in peerConnection', event);
353
383
  }
354
384
  };
355
385
  peerConnection.ontrack = function (trackEvent) {
356
386
  var track = trackEvent.track;
357
- trace.info("MediaStreamTrack arrived from peerConnection: ".concat(track.kind), track);
387
+ trace.info("MediaStreamTrack arrived from peerConnection: " + track.kind, track);
358
388
  _this.addRemoteTrackToPeer(peerConnection, track);
359
389
  if (peerConnection.connectionState === 'connected') {
360
390
  _this.registerPeersRemoteTracks(peerConnection);
361
391
  }
362
392
  };
363
393
  this._peerConnections.set(peerId, peerConnection);
364
- trace.info("".concat(peerConnectionType, " peerConnection created"));
394
+ trace.info(peerConnectionType + " peerConnection created");
365
395
  return peerConnection;
366
396
  };
367
397
  TurnWebRtcSession.prototype._setPeerConnectionMonitor = function (peerConnection) {
@@ -375,7 +405,9 @@ var TurnWebRtcSession = (function (_super) {
375
405
  TurnWebRtcSession.prototype._handlePeerConnectionTimeout = function (peerConnection) {
376
406
  trace.info('_handlePeerConnectionTimeout disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout);
377
407
  if (peerConnection.peerRole === MediaConstants_1.SessionClientRole.USER) {
378
- this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout).catch(function () { return undefined; });
408
+ this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout).catch(function () {
409
+ return undefined;
410
+ });
379
411
  }
380
412
  };
381
413
  TurnWebRtcSession.prototype._destroyPeerConnection = function (peerConnection) {
@@ -386,7 +418,9 @@ var TurnWebRtcSession = (function (_super) {
386
418
  peerConnection.oniceconnectionstatechange = null;
387
419
  peerConnection.onicegatheringstatechange = null;
388
420
  clearTimeout(peerConnection.connectionTimoutPrt);
389
- this.unregisterPeersRemoteMediaTracks(peerConnection).catch(function () { return undefined; });
421
+ this.unregisterPeersRemoteMediaTracks(peerConnection).catch(function () {
422
+ return undefined;
423
+ });
390
424
  this._peerConnections.delete(peerConnection.peerId);
391
425
  peerConnection.close();
392
426
  };
@@ -396,8 +430,11 @@ var TurnWebRtcSession = (function (_super) {
396
430
  }
397
431
  return undefined;
398
432
  };
433
+ //#endregion
434
+ //#region ICE Candidates
399
435
  TurnWebRtcSession.prototype._iceCandidateReceivedHandler = function (iceCandidateData) {
400
- var candidate = iceCandidateData.candidate, peerId = iceCandidateData.peerId;
436
+ var candidate = iceCandidateData.candidate,
437
+ peerId = iceCandidateData.peerId;
401
438
  trace.info('_iceCandidateReceivedHandler', candidate);
402
439
  if (!candidate) {
403
440
  trace.info('Unexpected case, iceCandidate message arrived without candidate');
@@ -410,15 +447,14 @@ var TurnWebRtcSession = (function (_super) {
410
447
  return;
411
448
  }
412
449
  trace.info('Going to add iceCandidate', candidate);
413
- this._addIceCandidateToPeer(candidate, peerConnection).catch(function () { return undefined; });
450
+ this._addIceCandidateToPeer(candidate, peerConnection).catch(function () {
451
+ return undefined;
452
+ });
414
453
  };
415
454
  TurnWebRtcSession.prototype._addIceCandidateToPeer = function (iceCandidate, peerConnection) {
416
- return peerConnection
417
- .addIceCandidate(iceCandidate)
418
- .then(function () {
455
+ return peerConnection.addIceCandidate(iceCandidate).then(function () {
419
456
  trace.info('ICE Candidate add to peer connection');
420
- })
421
- .catch(function (e) {
457
+ }).catch(function (e) {
422
458
  trace.warn('Error adding ICE Candidate to peer connection', e);
423
459
  throw e;
424
460
  });
@@ -430,10 +466,11 @@ var TurnWebRtcSession = (function (_super) {
430
466
  if (pendingIces) {
431
467
  pendingIces.forEach(function (pendingIce) {
432
468
  trace.info('Adding pending ICE to peer connections');
433
- _this._addIceCandidateToPeer(pendingIce, peerConnection).catch(function () { return undefined; });
469
+ _this._addIceCandidateToPeer(pendingIce, peerConnection).catch(function () {
470
+ return undefined;
471
+ });
434
472
  });
435
- }
436
- else {
473
+ } else {
437
474
  trace.info('No pending ICE found for peer', peerId);
438
475
  }
439
476
  });
@@ -446,8 +483,11 @@ var TurnWebRtcSession = (function (_super) {
446
483
  };
447
484
  TurnWebRtcSession.prototype._iceStateDisconnected = function (peerConnection) {
448
485
  trace.info('_iceStateDisconnected disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted);
449
- this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted).catch(function () { return undefined; });
486
+ this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted).catch(function () {
487
+ return undefined;
488
+ });
450
489
  };
490
+ //#endregion
451
491
  TurnWebRtcSession.prototype.sessionDisconnect = function () {
452
492
  if (this._socket) {
453
493
  this._socket.off();
@@ -455,6 +495,8 @@ var TurnWebRtcSession = (function (_super) {
455
495
  }
456
496
  };
457
497
  return TurnWebRtcSession;
458
- }(MediaSessionBase_1.MediaSessionBase));
498
+ }(MediaSessionBase_1.MediaSessionBase);
459
499
  exports.TurnWebRtcSession = TurnWebRtcSession;
460
- //# sourceMappingURL=SessionTurn.js.map
500
+
501
+ //# sourceMappingURL=SessionTurn.js.map
502
+ //# sourceMappingURL=SessionTurn.js.map