@webex/plugin-meetings 1.153.1 → 1.153.2

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.
@@ -20,6 +20,10 @@ exports.default = void 0;
20
20
 
21
21
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
22
22
 
23
+ var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
24
+
25
+ var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/parse-int"));
26
+
23
27
  var _window = _interopRequireDefault(require("global/window"));
24
28
 
25
29
  var _sdpTransform = _interopRequireDefault(require("sdp-transform"));
@@ -147,23 +151,14 @@ var isSdpInvalid = function isSdpInvalid(sdp) {
147
151
 
148
152
  try {
149
153
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
154
+ var _mediaLine$candidates;
155
+
150
156
  var mediaLine = _step.value;
151
157
 
152
- if (mediaLine.candidates && mediaLine.candidates.length === 0) {
158
+ if (!mediaLine.candidates || ((_mediaLine$candidates = mediaLine.candidates) === null || _mediaLine$candidates === void 0 ? void 0 : _mediaLine$candidates.length) === 0) {
153
159
  _loggerProxy.default.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candadate never completed');
154
160
 
155
- return 'iceCandidate: Ice candadate never completed';
156
- } // Sometimes the candidates might be there but only IPV6 we need to makes sure we have IPV4
157
-
158
-
159
- var hostCandidate = mediaLine.candidates.filter(function (candidate) {
160
- return !!(candidate.type === _constants.HOST && candidate.ip.match(_constants.IPV4_REGEX));
161
- });
162
-
163
- if (hostCandidate.length === 0) {
164
- _loggerProxy.default.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: no IPV4 candidate present');
165
-
166
- return 'iceCandidate: no IPV4 candidate present';
161
+ return 'iceCandidate: Ice gathering never completed';
167
162
  }
168
163
 
169
164
  if (_constants.SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {
@@ -233,45 +228,56 @@ pc.setContentSlides = function (screenPc) {
233
228
  pc.iceCandidate = function (peerConnection, _ref) {
234
229
  var remoteQualityLevel = _ref.remoteQualityLevel;
235
230
  return new _promise.default(function (resolve, reject) {
236
- // TODO: we dont need timeout as we can check the api state and validate.
237
- var timeout = setTimeout(function () {
231
+ var now = (0, _now.default)();
232
+
233
+ var doneGatheringIceCandidate = function doneGatheringIceCandidate() {
234
+ var miliseconds = (0, _parseInt2.default)(Math.abs((0, _now.default)() - now), 4);
238
235
  peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
239
236
  peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
240
237
  peerConnection.sdp = _util.default.convertCLineToIpv4(peerConnection.sdp);
238
+ var invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
241
239
 
242
- if (isSdpInvalid(peerConnection.sdp)) {
243
- setTimeout(function () {
244
- // peerconnection does gather ice candidate IP but in some cases due to firewall
245
- // or proxy the ice candidate does not get gathered so we need to wait and then retry
246
- // if still not valid then throw an error saying missing ice candidate
247
- // if ice candidate still not present after retry
248
- var invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
249
-
250
- if (!invalidSdpPresent) {
251
- resolve(peerConnection);
252
- } else {
253
- _loggerProxy.default.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');
254
-
255
- reject(new _webexErrors.InvalidSdpError(invalidSdpPresent));
256
- }
257
- }, _constants.RETRY_TIMEOUT);
258
- } else {
259
- resolve(peerConnection);
240
+ if (invalidSdpPresent) {
241
+ _loggerProxy.default.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');
242
+
243
+ reject(new _webexErrors.InvalidSdpError(invalidSdpPresent));
260
244
  }
261
- }, _constants.ICE_TIMEOUT);
245
+
246
+ _loggerProxy.default.logger.log("PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ".concat(miliseconds, " miliseconds"));
247
+
248
+ resolve();
249
+ }; // If ice has already been gathered
250
+
251
+
252
+ if (peerConnection.iceGatheringState === _constants.COMPLETE) {
253
+ doneGatheringIceCandidate();
254
+ }
255
+
256
+ peerConnection.onIceGatheringStateChange = function () {
257
+ if (peerConnection.iceGatheringState === _constants.COMPLETE) {
258
+ doneGatheringIceCandidate(peerConnection);
259
+ }
260
+
261
+ if (peerConnection.iceGatheringState === _constants.GATHERING) {
262
+ _loggerProxy.default.logger.log('PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering');
263
+ }
264
+ };
262
265
 
263
266
  peerConnection.onicecandidate = function (evt) {
264
- if (!evt.candidate && !peerConnection.sdp) {
265
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
266
- peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
267
- peerConnection.sdp = _util.default.convertCLineToIpv4(peerConnection.sdp);
268
-
269
- if (evt.candidate === null && !isSdpInvalid(peerConnection.sdp)) {
270
- clearTimeout(timeout);
271
- resolve(peerConnection);
272
- }
267
+ if (evt.candidate === null) {
268
+ doneGatheringIceCandidate(peerConnection);
269
+ } else {
270
+ var _evt$candidate, _evt$candidate2, _evt$candidate3, _evt$candidate4;
271
+
272
+ _loggerProxy.default.logger.log("PeerConnectionManager:index#onicecandidate --> Candidate ".concat((_evt$candidate = evt.candidate) === null || _evt$candidate === void 0 ? void 0 : _evt$candidate.type, " ").concat((_evt$candidate2 = evt.candidate) === null || _evt$candidate2 === void 0 ? void 0 : _evt$candidate2.protocol, " ").concat((_evt$candidate3 = evt.candidate) === null || _evt$candidate3 === void 0 ? void 0 : _evt$candidate3.address, ":").concat((_evt$candidate4 = evt.candidate) === null || _evt$candidate4 === void 0 ? void 0 : _evt$candidate4.port));
273
273
  }
274
274
  };
275
+
276
+ peerConnection.onicecandidateerror = function (event) {
277
+ _loggerProxy.default.logger.error('PeerConnectionManager:index#onicecandidateerror --> Failed to gather ice candidate.', event);
278
+
279
+ reject(new _webexErrors.IceGatheringFailed());
280
+ };
275
281
  });
276
282
  };
277
283
  /**
@@ -434,10 +440,6 @@ pc.createOffer = function (peerConnection, _ref2) {
434
440
  remoteQualityLevel: remoteQualityLevel
435
441
  });
436
442
  }).then(function () {
437
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
438
- peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
439
- peerConnection.sdp = _util.default.convertCLineToIpv4(peerConnection.sdp);
440
-
441
443
  if (!checkH264Support(peerConnection.sdp)) {
442
444
  throw new _media.default('openH264 is downloading please Wait. Upload logs if not working on second try');
443
445
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"names":["isBrowser","pc","insertBandwidthLimit","sdpLines","index","limit","periodicKeyFrame","search","AUDIO","StaticConfig","meetings","bandwidth","audio","video","SDP","PERIODIC_KEYFRAME","splice","B_LINE","setMaxFs","sdp","level","QUALITY_LEVELS","HIGH","MAX_FRAMESIZES","ParameterError","replaceSdp","maxFsLine","MAX_FS","replace","setStartBitrateOnRemoteSdp","startBitrate","checkH264Support","videoPresent","match","h264Present","isSdpInvalid","parsedSdp","sdpTransform","parse","media","mediaLine","candidates","length","LoggerProxy","logger","error","hostCandidate","filter","candidate","type","HOST","ip","IPV4_REGEX","BAD_MEDIA_PORTS","includes","port","icePwd","iceUfrag","limitBandwidth","offerSdp","split","CARRIAGE_RETURN","i","M_LINE","join","setContentSlides","screenPc","A_CONTENT_SLIDES","iceCandidate","peerConnection","remoteQualityLevel","resolve","reject","timeout","setTimeout","localDescription","PeerConnectionUtils","convertCLineToIpv4","invalidSdpPresent","InvalidSdpError","RETRY_TIMEOUT","ICE_TIMEOUT","onicecandidate","evt","clearTimeout","replaceTrack","track","senders","getSenders","forEach","sender","kind","err","addStream","stream","tracksPresent","find","getTracks","addTrack","setRemoteSessionDetails","typeStr","remoteSdp","meetingId","log","signalingState","Metrics","postEvent","event","eventType","REMOTE_SDP_RECEIVED","data","canProceed","errors","generateErrorPayload","name","MEDIA_ENGINE","HAVE_LOCAL_OFFER","STABLE","OFFER","setRemoteDescription","window","RTCSessionDescription","then","catch","metricName","METRICS_OPERATIONAL_MEASURES","PEERCONNECTION_FAILURE","correlation_id","reason","message","stack","metadata","sendOperationalMetric","MediaError","createOffer","enableRtx","enableExtmap","description","setLocalDescription","LOCAL_SDP_GENERATED","INVALID_ICE_CANDIDATE","code","close","rollBackLocalDescription","ROLLBACK","updatePeerConnection","params","createAnswer","peerconnection","HAVE_REMOTE_OFFER","sdpConstraints","answer","connectionState","PEER_CONNECTION_STATE","CLOSED","setPeerConnectionEvents","meeting","mediaProperties","connectionFailed","reconnectionManager","iceState","reconnect","networkDisconnect","ICE_END","uploadLogs","file","function","CONNECTION_FAILURE","correlationId","locus_id","locusId","oniceconnectionstatechange","info","iceConnectionState","ICE_STATE","CHECKING","ICE_START","COMPLETED","CONNECTED","setNetworkStatus","NETWORK_STATUS","iceReconnected","DISCONNECTED","waitForIceReconnect","FAILED","onconnectionstatechange","CONNECTION_STATE","NEW","CONNECTING"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAgBA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,wBAAoB,gCAApB;AAAA,IAAOA,SAAP,qBAAOA,SAAP;AAEA;AACA;AACA;AACA;;;AACA,IAAMC,EAAE,GAAG,EAAX;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,QAAD,EAAWC,KAAX,EAAqB;AAChD;AACA;AACA,MAAIC,KAAJ;AACA,MAAIC,gBAAgB,GAAG,EAAvB;;AAEA,MAAIH,QAAQ,CAACC,KAAD,CAAR,CAAgBG,MAAhB,CAAuBC,gBAAvB,MAAkC,CAAC,CAAvC,EAA0C;AACxCH,IAAAA,KAAK,GAAGI,gBAAaC,QAAb,CAAsBC,SAAtB,CAAgCC,KAAxC;AACD,GAFD,MAGK;AACHP,IAAAA,KAAK,GAAGI,gBAAaC,QAAb,CAAsBC,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E;AACA;;;AAEAd,QAAAA,gBAAgB;AAChB;;AACF;AACE;AAxBJ;AA0BD,GA5BD;AA6BD,CA9GD;;eAgHe7J,E","sourcesContent":["\n// We need to figure out how to pass a webex logger instance to these util files\n\n/* globals RTCSessionDescription */\n\nimport window from 'global/window';\nimport sdpTransform from 'sdp-transform'; // https://github.com/clux/sdp-transform\n\nimport Metrics from '../metrics';\nimport LoggerProxy from '../common/logs/logger-proxy';\nimport StaticConfig from '../common/config';\nimport {\n RETRY_TIMEOUT,\n ICE_TIMEOUT,\n HOST,\n AUDIO,\n SDP,\n ICE_STATE,\n CONNECTION_STATE,\n NETWORK_STATUS,\n PEER_CONNECTION_STATE,\n OFFER,\n QUALITY_LEVELS,\n MAX_FRAMESIZES,\n METRICS_OPERATIONAL_MEASURES,\n IPV4_REGEX\n} from '../constants';\nimport {error, eventType} from '../metrics/config';\nimport MediaError from '../common/errors/media';\nimport ParameterError from '../common/errors/parameter';\nimport {InvalidSdpError} from '../common/errors/webex-errors';\nimport BrowserDetection from '../common/browser-detection';\n\nimport PeerConnectionUtils from './util';\n\nconst {isBrowser} = BrowserDetection();\n\n/**\n * @export\n * @public\n */\nconst pc = {};\n\n/**\n * munges the bandwidth limit into the sdp\n * @param {String} sdpLines\n * @param {Number} index\n * @returns {String}\n */\nconst insertBandwidthLimit = (sdpLines, index) => {\n // eslint-disable-next-line no-warning-comments\n // TODO convert to sdp parser\n let limit;\n let periodicKeyFrame = '';\n\n if (sdpLines[index].search(AUDIO) !== -1) {\n limit = StaticConfig.meetings.bandwidth.audio;\n }\n else {\n limit = StaticConfig.meetings.bandwidth.video;\n periodicKeyFrame = SDP.PERIODIC_KEYFRAME;\n sdpLines.splice(index + 2, 0, periodicKeyFrame);\n }\n sdpLines.splice(index + 1, 0, `${SDP.B_LINE}:${limit}`);\n\n return sdpLines;\n};\n\n/**\n * needed for calliope max-fs\n * @param {String} sdp\n * @param {String} [level=QUALITY_LEVELS.HIGH] quality level for max-fs\n * @returns {String}\n */\nconst setMaxFs = (sdp, level = QUALITY_LEVELS.HIGH) => {\n if (!MAX_FRAMESIZES[level]) {\n throw new ParameterError(`setMaxFs: unable to set max framesize, value for level \"${level}\" is not defined`);\n }\n // eslint-disable-next-line no-warning-comments\n // TODO convert with sdp parser, no munging\n let replaceSdp = sdp;\n const maxFsLine = `${SDP.MAX_FS}${MAX_FRAMESIZES[level]}`;\n\n replaceSdp = replaceSdp.replace(/(\\na=fmtp:(\\d+).*profile-level-id=.*)/gi, `$1;${maxFsLine}`);\n\n return replaceSdp;\n};\n\n\nconst setStartBitrateOnRemoteSdp = (sdp) => {\n if (StaticConfig.meetings.bandwidth.startBitrate) {\n sdp = sdp.replace(/(\\na=fmtp:(\\d+).*profile-level-id=.*)/gi, `$1;x-google-start-bitrate=${StaticConfig.meetings.bandwidth.startBitrate}`);\n }\n\n return sdp;\n};\n\n/**\n * checks that sdp has h264 codec in it\n * @param {String} sdp\n * @returns {boolean}\n */\nconst checkH264Support = (sdp) => {\n // eslint-disable-next-line no-warning-comments\n // TODO convert to sdp parser to read rtp.codec\n const videoPresent = sdp.match(/\\nm=video.*/g);\n const h264Present = sdp.match(/\\na=rtpmap:\\d+\\sH264.*/g);\n\n if (videoPresent) {\n return !!h264Present;\n }\n\n return true;\n};\n\n/**\n * validates the sdp, checks port, candidates, and ice info\n * @param {String} sdp\n * @returns {String}\n */\nconst isSdpInvalid = (sdp) => {\n const parsedSdp = sdpTransform.parse(sdp);\n\n for (const mediaLine of parsedSdp.media) {\n if (mediaLine.candidates && mediaLine.candidates.length === 0) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candadate never completed');\n\n return 'iceCandidate: Ice candadate never completed';\n }\n // Sometimes the candidates might be there but only IPV6 we need to makes sure we have IPV4\n const hostCandidate = mediaLine.candidates.filter((candidate) => !!(candidate.type === HOST && candidate.ip.match(IPV4_REGEX)));\n\n if (hostCandidate.length === 0) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: no IPV4 candidate present');\n\n return 'iceCandidate: no IPV4 candidate present';\n }\n\n if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Found invalid port number for the ice candidate');\n\n return 'iceCandidate: Found invalid port number for the ice candidate';\n }\n if (!mediaLine.icePwd || !mediaLine.iceUfrag) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: ice ufrag and password not found');\n\n return 'iceCandidate: ice ufrag and password not found';\n }\n }\n\n return '';\n};\n\n/**\n * munges the bandwidth into the sdp\n * @param {String} sdp\n * @returns {String}\n */\nconst limitBandwidth = (sdp) => {\n // TODO convert to sdp parser\n let offerSdp = sdp;\n let sdpLines = offerSdp.split(SDP.CARRIAGE_RETURN);\n\n for (let i = 0; i < sdpLines.length; i += 1) {\n if (sdpLines[i].search(SDP.M_LINE) !== -1) {\n sdpLines = insertBandwidthLimit(sdpLines, i);\n }\n }\n offerSdp = sdpLines.join(SDP.CARRIAGE_RETURN);\n\n return offerSdp;\n};\n\n/**\n * makes sure the screen pc sdp has content:slides for server\n * @param {RTCPeerConnection} screenPc\n * @returns {RTCPeerConnection}\n */\npc.setContentSlides = (screenPc) => {\n if (screenPc && screenPc.sdp) {\n screenPc.sdp += `${SDP.A_CONTENT_SLIDES}${SDP.CARRIAGE_RETURN}`;\n }\n\n return screenPc;\n};\n\n/**\n * handles ice trickling and establishes ICE connection onto peer connection object\n * @param {Object} peerConnection\n * @param {Object} options\n * @param {String} options.remoteQualityLevel\n * @returns {Promise.RTCPeerConnection}\n */\npc.iceCandidate = (peerConnection, {remoteQualityLevel}) =>\n new Promise((resolve, reject) => {\n // TODO: we dont need timeout as we can check the api state and validate.\n const timeout = setTimeout(() => {\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n\n if (isSdpInvalid(peerConnection.sdp)) {\n setTimeout(() => {\n // peerconnection does gather ice candidate IP but in some cases due to firewall\n // or proxy the ice candidate does not get gathered so we need to wait and then retry\n // if still not valid then throw an error saying missing ice candidate\n // if ice candidate still not present after retry\n const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);\n\n if (!invalidSdpPresent) {\n resolve(peerConnection);\n }\n else {\n LoggerProxy.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');\n reject(new InvalidSdpError(invalidSdpPresent));\n }\n }, RETRY_TIMEOUT);\n }\n else {\n resolve(peerConnection);\n }\n }, ICE_TIMEOUT);\n\n peerConnection.onicecandidate = (evt) => {\n if (!evt.candidate && !peerConnection.sdp) {\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n\n if (evt.candidate === null && !isSdpInvalid(peerConnection.sdp)) {\n clearTimeout(timeout);\n resolve(peerConnection);\n }\n }\n };\n });\n\n/**\n * swapping tracks\n * @param {Object} peerConnection\n * @param {Object} track\n * @returns {undefined}\n */\npc.replaceTrack = (peerConnection, track) => {\n try {\n const senders = peerConnection.getSenders();\n\n if (senders.length > 0) {\n senders.forEach((sender) => {\n if (sender.track && sender.track.kind === track.kind) {\n sender.replaceTrack(track);\n }\n });\n }\n }\n catch (err) {\n LoggerProxy.logger.error(`PeerConnectionManager:index#replaceTrack --> Error replacing track, ${err}`);\n }\n};\n\n/**\n * adding streams to peerConnection\n * @param {Object} peerConnection\n * @param {Object} stream\n * @returns {undefined}\n */\npc.addStream = (peerConnection, stream) => {\n try {\n if (stream && !isBrowser('edge')) {\n const tracksPresent = peerConnection.getSenders && peerConnection.getSenders().find((sender) => sender.track != null);\n\n if (tracksPresent) {\n stream.getTracks().forEach((track) => {\n pc.replaceTrack(peerConnection, track);\n });\n\n return;\n }\n stream.getTracks().forEach((track) => {\n peerConnection.addTrack(track, stream);\n });\n // // TODO : may come back disable addTracks for chrome they are moving back to addStream\n // // https://bugs.chromium.org/p/chromium/issues/detail?id=764414\n // // https://bugs.chromium.org/p/chromium/issues/detail?id=738918#c7\n // peerConnection.addStream(stream);\n }\n else if (isBrowser('edge')) {\n peerConnection.addStream(stream);\n }\n }\n catch (err) {\n LoggerProxy.logger.error(`PeerConnectionManager:index#addStream --> Error adding stream, error: ${error}`);\n }\n};\n\n/**\n * setting the remote description\n * @param {Object} peerConnection\n * @param {String} typeStr\n * @param {String} remoteSdp\n * @param {String} meetingId\n * @returns {undefined}\n */\npc.setRemoteSessionDetails = (\n peerConnection,\n typeStr,\n remoteSdp,\n meetingId,\n) => {\n LoggerProxy.logger.log(`PeerConnectionManager:index#setRemoteSessionDetails --> Setting the remote description type: ${typeStr}State: ${peerConnection.signalingState}`);\n let sdp = remoteSdp;\n\n // making sure that the remoteDescription is only set when there is a answer for offer\n // or there is a offer from the server\n\n if (!sdp) {\n Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId,\n data: {\n canProceed: false,\n errors: [Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE, 'missing remoteSdp')]\n }\n });\n }\n if (peerConnection.signalingState === SDP.HAVE_LOCAL_OFFER || (peerConnection.signalingState === SDP.STABLE && typeStr === SDP.OFFER)) {\n sdp = setStartBitrateOnRemoteSdp(sdp);\n\n return peerConnection.setRemoteDescription(\n new window.RTCSessionDescription({\n type: typeStr,\n sdp\n })\n )\n .then(() => {\n if (peerConnection.signalingState === SDP.STABLE) {\n Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId\n });\n }\n })\n .catch((error) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#setRemoteDescription --> ${error} missing remotesdp`);\n\n\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n\n return Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId,\n data: {\n canProceed: false,\n errors: [Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE, 'missing remoteSdp')]\n }\n });\n });\n }\n\n return Promise.reject(new MediaError('PeerConnection in wrong state'));\n};\n\n/**\n * create offer with a valid paramater\n * @param {Object} peerConnection\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @param {string} meetingProperties.enableRtx\n * @param {string} meetingProperties.enableExtmap\n * @returns {RTCPeerConnection}\n */\npc.createOffer = (peerConnection, {\n meetingId,\n remoteQualityLevel,\n enableRtx,\n enableExtmap\n}) => {\n LoggerProxy.logger.log('PeerConnectionManager:index#createOffer --> creating a new offer');\n\n return peerConnection\n .createOffer()\n .then((description) => {\n // bug https://bugs.chromium.org/p/chromium/issues/detail?id=1020642\n // chrome currently generates RTX line irrespective of weither the server side supports it\n // we are removing apt as well because its associated with rtx line\n\n if (!enableRtx) {\n description.sdp = description.sdp.replace(/\\r\\na=rtpmap:\\d+ rtx\\/\\d+/g, '');\n description.sdp = description.sdp.replace(/\\r\\na=fmtp:\\d+ apt=\\d+/g, '');\n }\n\n return peerConnection.setLocalDescription(description);\n })\n .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))\n .then(() => {\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n if (!checkH264Support(peerConnection.sdp)) {\n throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');\n }\n\n if (!enableExtmap) {\n peerConnection.sdp = peerConnection.sdp.replace(/\\na=extmap.*/g, '');\n }\n\n pc.setContentSlides(peerConnection);\n\n Metrics.postEvent({\n event: eventType.LOCAL_SDP_GENERATED,\n meetingId\n });\n\n return peerConnection;\n })\n .catch((error) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#createOffer --> ${error}`);\n if (error instanceof InvalidSdpError) {\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.INVALID_ICE_CANDIDATE,\n {\n correlation_id: meetingId,\n code: error.code,\n reason: error.message\n }\n );\n }\n else {\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n }\n\n Metrics.postEvent({\n event: eventType.LOCAL_SDP_GENERATED,\n meetingId,\n data: {\n canProceed: false,\n errors: [\n Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE)]\n }\n });\n pc.close(peerConnection);\n throw error;\n });\n};\n\n/**\n * rollBack local description in peerconnection\n * @param {Object} peerConnection\n * @returns {Promise.RTCPeerConnection}\n */\npc.rollBackLocalDescription = (peerConnection) => peerConnection\n .setLocalDescription(new RTCSessionDescription({type: SDP.ROLLBACK}))\n .then(() => peerConnection)\n .catch((err) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#setLocalDescription --> ${err} `);\n\n return Promise.error(err);\n });\n\n/**\n * @param {Object} params {\n * @param {Boolean} params.offerToReceiveAudio\n * @param {Boolean} params.offerToReceiveVideo\n * @param {string} params.offerSdp\n * @param {MediaStream} params.stream\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @returns {Promise.<Array>} [MediaSDP, ScreenSDP]\n */\npc.updatePeerConnection = (params, {meetingId, remoteQualityLevel}) => {\n LoggerProxy.logger.log(`PeerConnectionManager:index#updatePeerConnection --> updating the peerConnection with params: ${params}`);\n\n const {peerConnection, offerSdp} = params;\n\n return pc.createAnswer({\n peerConnection,\n offerSdp: offerSdp[0]\n }, {meetingId, remoteQualityLevel}).then((peerconnection) => {\n // The content slides should also be set when we are sending inactive\n pc.setContentSlides(peerconnection);\n\n return Promise.resolve([peerconnection.sdp]);\n });\n};\n\n/**\n * @param {Object} params\n * @param {Object} params.peerConnection\n * @param {Object} params.sdpConstraints\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @returns {RTCPeerConnection} peerConnection\n */\npc.createAnswer = (params, {meetingId, remoteQualityLevel}) => {\n const {peerConnection} = params;\n\n // TODO: Some times to many mercury event comes at the same time\n // Need to maintain state of peerconnection\n if (peerConnection.signalingState === SDP.HAVE_REMOTE_OFFER) {\n return Promise.resolve(peerConnection);\n }\n\n return pc.setRemoteSessionDetails(peerConnection, OFFER, params.offerSdp, meetingId)\n .then(() => peerConnection.createAnswer(params.sdpConstraints))\n .then((answer) =>\n\n peerConnection.setLocalDescription(answer))\n .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))\n .then(() => {\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n if (!checkH264Support(peerConnection.sdp)) {\n throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');\n }\n\n return peerConnection;\n })\n .catch((error) => {\n if (error instanceof InvalidSdpError) {\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.INVALID_ICE_CANDIDATE,\n {\n correlation_id: meetingId\n }\n );\n }\n else {\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n }\n\n LoggerProxy.logger.error(`PeerConnectionManager:index#setRemoteSessionDetails --> Error creating remote session, error: ${error}`);\n });\n};\n\n/**\n * shut down the peer connection\n * @param {Object} peerConnection\n * @returns {undefined}\n */\npc.close = (peerConnection) => {\n // peerConnection.close() fails on firefox on network changes and gives a Dom exception\n // To avoid this we have added a try catch block.\n // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=1274407 for more information\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> attempting to close the peer connection');\n\n if (peerConnection && peerConnection.connectionState === PEER_CONNECTION_STATE.CLOSED) {\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> connection already closed');\n\n return Promise.resolve();\n }\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> closing the mediaPeerConnection');\n\n return Promise.resolve()\n .then(() => {\n if (peerConnection && peerConnection.close) {\n peerConnection.close();\n }\n });\n};\n\n\npc.setPeerConnectionEvents = (meeting) => {\n // In case ICE fail\n const {peerConnection} = meeting.mediaProperties;\n\n const connectionFailed = () => {\n if (meeting.reconnectionManager.iceState.resolve) {\n // DISCONNECTED state triggers first then it goes to FAILED STATE\n // sometimes the failed state can happen before 10 seconds (Which is the timer for the reconnect for ice disconnect)\n meeting.reconnectionManager.iceState.resolve();\n }\n\n meeting.reconnect({networkDisconnect: true});\n Metrics.postEvent({\n event: eventType.ICE_END,\n meeting,\n data: {\n canProceed: false,\n errors: [\n Metrics.generateErrorPayload(\n 2004, false, error.name.MEDIA_ENGINE\n )]\n }\n });\n\n meeting.uploadLogs({\n file: 'peer-connection-manager/index',\n function: 'connectionFailed'\n });\n\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.CONNECTION_FAILURE,\n {\n correlation_id: meeting.correlationId,\n locus_id: meeting.locusId\n }\n );\n };\n\n peerConnection.oniceconnectionstatechange = () => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHANGE.');\n switch (peerConnection.iceConnectionState) {\n case ICE_STATE.CHECKING:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHECKING.');\n Metrics.postEvent({event: eventType.ICE_START, meeting});\n break;\n case ICE_STATE.COMPLETED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE COMPLETED.');\n break;\n case ICE_STATE.CONNECTED:\n // Ice connection state goes to connected when both client and server sends STUN packets and\n // Established connected between them. Firefox does not trigger COMPLETED and only trigger CONNECTED\n Metrics.postEvent({event: eventType.ICE_END, meeting});\n meeting.setNetworkStatus(NETWORK_STATUS.CONNECTED);\n meeting.reconnectionManager.iceReconnected();\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CONNECTED.');\n break;\n case ICE_STATE.CLOSED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CLOSED.');\n break;\n case ICE_STATE.DISCONNECTED:\n meeting.setNetworkStatus(NETWORK_STATUS.DISCONNECTED);\n meeting.reconnectionManager.waitForIceReconnect()\n .catch(() => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED. Automatic Reconnection Timed Out.');\n\n connectionFailed();\n });\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED.');\n break;\n case ICE_STATE.FAILED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE FAILED.');\n // notify of ice failure\n // Ice failure is the only indicator currently for identifying the actual connection drop\n // Firefox takes sometime 10-15 seconds to go to failed state\n connectionFailed();\n break;\n default:\n break;\n }\n };\n\n peerConnection.onconnectionstatechange = () => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CHANGE.');\n switch (peerConnection.connectionState) {\n case CONNECTION_STATE.NEW:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE NEW.');\n break;\n case CONNECTION_STATE.CONNECTING:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTING.');\n break;\n case CONNECTION_STATE.CONNECTED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTED.');\n break;\n case CONNECTION_STATE.CLOSED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CLOSED.');\n break;\n case CONNECTION_STATE.DISCONNECTED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE DISCONNECTED.');\n break;\n case CONNECTION_STATE.FAILED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE FAILED.');\n // Special case happens only on chrome where there is no ICE FAILED event\n // only CONNECTION FAILED event gets triggered\n\n connectionFailed();\n break;\n default:\n break;\n }\n };\n};\n\nexport default pc;\n"]}
1
+ {"version":3,"sources":["index.js"],"names":["isBrowser","pc","insertBandwidthLimit","sdpLines","index","limit","periodicKeyFrame","search","AUDIO","StaticConfig","meetings","bandwidth","audio","video","SDP","PERIODIC_KEYFRAME","splice","B_LINE","setMaxFs","sdp","level","QUALITY_LEVELS","HIGH","MAX_FRAMESIZES","ParameterError","replaceSdp","maxFsLine","MAX_FS","replace","setStartBitrateOnRemoteSdp","startBitrate","checkH264Support","videoPresent","match","h264Present","isSdpInvalid","parsedSdp","sdpTransform","parse","media","mediaLine","candidates","length","LoggerProxy","logger","error","BAD_MEDIA_PORTS","includes","port","icePwd","iceUfrag","limitBandwidth","offerSdp","split","CARRIAGE_RETURN","i","M_LINE","join","setContentSlides","screenPc","A_CONTENT_SLIDES","iceCandidate","peerConnection","remoteQualityLevel","resolve","reject","now","doneGatheringIceCandidate","miliseconds","Math","abs","localDescription","PeerConnectionUtils","convertCLineToIpv4","invalidSdpPresent","InvalidSdpError","log","iceGatheringState","COMPLETE","onIceGatheringStateChange","GATHERING","onicecandidate","evt","candidate","type","protocol","address","onicecandidateerror","event","IceGatheringFailed","replaceTrack","track","senders","getSenders","forEach","sender","kind","err","addStream","stream","tracksPresent","find","getTracks","addTrack","setRemoteSessionDetails","typeStr","remoteSdp","meetingId","signalingState","Metrics","postEvent","eventType","REMOTE_SDP_RECEIVED","data","canProceed","errors","generateErrorPayload","name","MEDIA_ENGINE","HAVE_LOCAL_OFFER","STABLE","OFFER","setRemoteDescription","window","RTCSessionDescription","then","catch","metricName","METRICS_OPERATIONAL_MEASURES","PEERCONNECTION_FAILURE","correlation_id","reason","message","stack","metadata","sendOperationalMetric","MediaError","createOffer","enableRtx","enableExtmap","description","setLocalDescription","LOCAL_SDP_GENERATED","INVALID_ICE_CANDIDATE","code","close","rollBackLocalDescription","ROLLBACK","updatePeerConnection","params","createAnswer","peerconnection","HAVE_REMOTE_OFFER","sdpConstraints","answer","connectionState","PEER_CONNECTION_STATE","CLOSED","setPeerConnectionEvents","meeting","mediaProperties","connectionFailed","reconnectionManager","iceState","reconnect","networkDisconnect","ICE_END","uploadLogs","file","function","CONNECTION_FAILURE","correlationId","locus_id","locusId","oniceconnectionstatechange","info","iceConnectionState","ICE_STATE","CHECKING","ICE_START","COMPLETED","CONNECTED","setNetworkStatus","NETWORK_STATUS","iceReconnected","DISCONNECTED","waitForIceReconnect","FAILED","onconnectionstatechange","CONNECTION_STATE","NEW","CONNECTING"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAcA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,wBAAoB,gCAApB;AAAA,IAAOA,SAAP,qBAAOA,SAAP;AAEA;AACA;AACA;AACA;;;AACA,IAAMC,EAAE,GAAG,EAAX;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,QAAD,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B,kFAAxB,EADF,CAEE;AACA;;;AAEAd,QAAAA,gBAAgB;AAChB;;AACF;AACE;AAxBJ;AA0BD,GA5BD;AA6BD,CA9GD;;eAgHehK,E","sourcesContent":["\n// We need to figure out how to pass a webex logger instance to these util files\n\n/* globals RTCSessionDescription */\n\nimport window from 'global/window';\nimport sdpTransform from 'sdp-transform'; // https://github.com/clux/sdp-transform\n\nimport Metrics from '../metrics';\nimport LoggerProxy from '../common/logs/logger-proxy';\nimport StaticConfig from '../common/config';\nimport {\n COMPLETE,\n GATHERING,\n AUDIO,\n SDP,\n ICE_STATE,\n CONNECTION_STATE,\n NETWORK_STATUS,\n PEER_CONNECTION_STATE,\n OFFER,\n QUALITY_LEVELS,\n MAX_FRAMESIZES,\n METRICS_OPERATIONAL_MEASURES\n} from '../constants';\nimport {error, eventType} from '../metrics/config';\nimport MediaError from '../common/errors/media';\nimport ParameterError from '../common/errors/parameter';\nimport {InvalidSdpError, IceGatheringFailed} from '../common/errors/webex-errors';\nimport BrowserDetection from '../common/browser-detection';\n\nimport PeerConnectionUtils from './util';\n\nconst {isBrowser} = BrowserDetection();\n\n/**\n * @export\n * @public\n */\nconst pc = {};\n\n/**\n * munges the bandwidth limit into the sdp\n * @param {String} sdpLines\n * @param {Number} index\n * @returns {String}\n */\nconst insertBandwidthLimit = (sdpLines, index) => {\n // eslint-disable-next-line no-warning-comments\n // TODO convert to sdp parser\n let limit;\n let periodicKeyFrame = '';\n\n if (sdpLines[index].search(AUDIO) !== -1) {\n limit = StaticConfig.meetings.bandwidth.audio;\n }\n else {\n limit = StaticConfig.meetings.bandwidth.video;\n periodicKeyFrame = SDP.PERIODIC_KEYFRAME;\n sdpLines.splice(index + 2, 0, periodicKeyFrame);\n }\n sdpLines.splice(index + 1, 0, `${SDP.B_LINE}:${limit}`);\n\n return sdpLines;\n};\n\n/**\n * needed for calliope max-fs\n * @param {String} sdp\n * @param {String} [level=QUALITY_LEVELS.HIGH] quality level for max-fs\n * @returns {String}\n */\nconst setMaxFs = (sdp, level = QUALITY_LEVELS.HIGH) => {\n if (!MAX_FRAMESIZES[level]) {\n throw new ParameterError(`setMaxFs: unable to set max framesize, value for level \"${level}\" is not defined`);\n }\n // eslint-disable-next-line no-warning-comments\n // TODO convert with sdp parser, no munging\n let replaceSdp = sdp;\n const maxFsLine = `${SDP.MAX_FS}${MAX_FRAMESIZES[level]}`;\n\n replaceSdp = replaceSdp.replace(/(\\na=fmtp:(\\d+).*profile-level-id=.*)/gi, `$1;${maxFsLine}`);\n\n return replaceSdp;\n};\n\n\nconst setStartBitrateOnRemoteSdp = (sdp) => {\n if (StaticConfig.meetings.bandwidth.startBitrate) {\n sdp = sdp.replace(/(\\na=fmtp:(\\d+).*profile-level-id=.*)/gi, `$1;x-google-start-bitrate=${StaticConfig.meetings.bandwidth.startBitrate}`);\n }\n\n return sdp;\n};\n\n/**\n * checks that sdp has h264 codec in it\n * @param {String} sdp\n * @returns {boolean}\n */\nconst checkH264Support = (sdp) => {\n // eslint-disable-next-line no-warning-comments\n // TODO convert to sdp parser to read rtp.codec\n const videoPresent = sdp.match(/\\nm=video.*/g);\n const h264Present = sdp.match(/\\na=rtpmap:\\d+\\sH264.*/g);\n\n if (videoPresent) {\n return !!h264Present;\n }\n\n return true;\n};\n\n/**\n * validates the sdp, checks port, candidates, and ice info\n * @param {String} sdp\n * @returns {String}\n */\nconst isSdpInvalid = (sdp) => {\n const parsedSdp = sdpTransform.parse(sdp);\n\n for (const mediaLine of parsedSdp.media) {\n if (!mediaLine.candidates || mediaLine.candidates?.length === 0) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candadate never completed');\n\n return 'iceCandidate: Ice gathering never completed';\n }\n\n if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Found invalid port number for the ice candidate');\n\n return 'iceCandidate: Found invalid port number for the ice candidate';\n }\n if (!mediaLine.icePwd || !mediaLine.iceUfrag) {\n LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: ice ufrag and password not found');\n\n return 'iceCandidate: ice ufrag and password not found';\n }\n }\n\n return '';\n};\n\n/**\n * munges the bandwidth into the sdp\n * @param {String} sdp\n * @returns {String}\n */\nconst limitBandwidth = (sdp) => {\n // TODO convert to sdp parser\n let offerSdp = sdp;\n let sdpLines = offerSdp.split(SDP.CARRIAGE_RETURN);\n\n for (let i = 0; i < sdpLines.length; i += 1) {\n if (sdpLines[i].search(SDP.M_LINE) !== -1) {\n sdpLines = insertBandwidthLimit(sdpLines, i);\n }\n }\n offerSdp = sdpLines.join(SDP.CARRIAGE_RETURN);\n\n return offerSdp;\n};\n\n/**\n * makes sure the screen pc sdp has content:slides for server\n * @param {RTCPeerConnection} screenPc\n * @returns {RTCPeerConnection}\n */\npc.setContentSlides = (screenPc) => {\n if (screenPc && screenPc.sdp) {\n screenPc.sdp += `${SDP.A_CONTENT_SLIDES}${SDP.CARRIAGE_RETURN}`;\n }\n\n return screenPc;\n};\n\n/**\n * handles ice trickling and establishes ICE connection onto peer connection object\n * @param {Object} peerConnection\n * @param {Object} options\n * @param {String} options.remoteQualityLevel\n * @returns {Promise.RTCPeerConnection}\n */\npc.iceCandidate = (peerConnection, {remoteQualityLevel}) =>\n new Promise((resolve, reject) => {\n const now = Date.now();\n const doneGatheringIceCandidate = () => {\n const miliseconds = parseInt(Math.abs(Date.now() - now), 4);\n\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n\n const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);\n\n if (invalidSdpPresent) {\n LoggerProxy.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');\n reject(new InvalidSdpError(invalidSdpPresent));\n }\n LoggerProxy.logger.log(`PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ${miliseconds} miliseconds`);\n\n\n resolve();\n };\n\n // If ice has already been gathered\n if (peerConnection.iceGatheringState === COMPLETE) {\n doneGatheringIceCandidate();\n }\n\n peerConnection.onIceGatheringStateChange = () => {\n if (peerConnection.iceGatheringState === COMPLETE) {\n doneGatheringIceCandidate(peerConnection);\n }\n if (peerConnection.iceGatheringState === GATHERING) {\n LoggerProxy.logger.log('PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering');\n }\n };\n\n peerConnection.onicecandidate = (evt) => {\n if (evt.candidate === null) {\n doneGatheringIceCandidate(peerConnection);\n }\n else {\n LoggerProxy.logger.log(`PeerConnectionManager:index#onicecandidate --> Candidate ${evt.candidate?.type} ${evt.candidate?.protocol} ${evt.candidate?.address}:${evt.candidate?.port}`);\n }\n };\n\n peerConnection.onicecandidateerror = (event) => {\n LoggerProxy.logger.error('PeerConnectionManager:index#onicecandidateerror --> Failed to gather ice candidate.', event);\n reject(new IceGatheringFailed());\n };\n });\n\n/**\n * swapping tracks\n * @param {Object} peerConnection\n * @param {Object} track\n * @returns {undefined}\n */\npc.replaceTrack = (peerConnection, track) => {\n try {\n const senders = peerConnection.getSenders();\n\n if (senders.length > 0) {\n senders.forEach((sender) => {\n if (sender.track && sender.track.kind === track.kind) {\n sender.replaceTrack(track);\n }\n });\n }\n }\n catch (err) {\n LoggerProxy.logger.error(`PeerConnectionManager:index#replaceTrack --> Error replacing track, ${err}`);\n }\n};\n\n/**\n * adding streams to peerConnection\n * @param {Object} peerConnection\n * @param {Object} stream\n * @returns {undefined}\n */\npc.addStream = (peerConnection, stream) => {\n try {\n if (stream && !isBrowser('edge')) {\n const tracksPresent = peerConnection.getSenders && peerConnection.getSenders().find((sender) => sender.track != null);\n\n if (tracksPresent) {\n stream.getTracks().forEach((track) => {\n pc.replaceTrack(peerConnection, track);\n });\n\n return;\n }\n stream.getTracks().forEach((track) => {\n peerConnection.addTrack(track, stream);\n });\n // // TODO : may come back disable addTracks for chrome they are moving back to addStream\n // // https://bugs.chromium.org/p/chromium/issues/detail?id=764414\n // // https://bugs.chromium.org/p/chromium/issues/detail?id=738918#c7\n // peerConnection.addStream(stream);\n }\n else if (isBrowser('edge')) {\n peerConnection.addStream(stream);\n }\n }\n catch (err) {\n LoggerProxy.logger.error(`PeerConnectionManager:index#addStream --> Error adding stream, error: ${error}`);\n }\n};\n\n/**\n * setting the remote description\n * @param {Object} peerConnection\n * @param {String} typeStr\n * @param {String} remoteSdp\n * @param {String} meetingId\n * @returns {undefined}\n */\npc.setRemoteSessionDetails = (\n peerConnection,\n typeStr,\n remoteSdp,\n meetingId,\n) => {\n LoggerProxy.logger.log(`PeerConnectionManager:index#setRemoteSessionDetails --> Setting the remote description type: ${typeStr}State: ${peerConnection.signalingState}`);\n let sdp = remoteSdp;\n\n // making sure that the remoteDescription is only set when there is a answer for offer\n // or there is a offer from the server\n\n if (!sdp) {\n Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId,\n data: {\n canProceed: false,\n errors: [Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE, 'missing remoteSdp')]\n }\n });\n }\n if (peerConnection.signalingState === SDP.HAVE_LOCAL_OFFER || (peerConnection.signalingState === SDP.STABLE && typeStr === SDP.OFFER)) {\n sdp = setStartBitrateOnRemoteSdp(sdp);\n\n return peerConnection.setRemoteDescription(\n new window.RTCSessionDescription({\n type: typeStr,\n sdp\n })\n )\n .then(() => {\n if (peerConnection.signalingState === SDP.STABLE) {\n Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId\n });\n }\n })\n .catch((error) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#setRemoteDescription --> ${error} missing remotesdp`);\n\n\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n\n return Metrics.postEvent({\n event: eventType.REMOTE_SDP_RECEIVED,\n meetingId,\n data: {\n canProceed: false,\n errors: [Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE, 'missing remoteSdp')]\n }\n });\n });\n }\n\n return Promise.reject(new MediaError('PeerConnection in wrong state'));\n};\n\n/**\n * create offer with a valid paramater\n * @param {Object} peerConnection\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @param {string} meetingProperties.enableRtx\n * @param {string} meetingProperties.enableExtmap\n * @returns {RTCPeerConnection}\n */\npc.createOffer = (peerConnection, {\n meetingId,\n remoteQualityLevel,\n enableRtx,\n enableExtmap\n}) => {\n LoggerProxy.logger.log('PeerConnectionManager:index#createOffer --> creating a new offer');\n\n return peerConnection\n .createOffer()\n .then((description) => {\n // bug https://bugs.chromium.org/p/chromium/issues/detail?id=1020642\n // chrome currently generates RTX line irrespective of weither the server side supports it\n // we are removing apt as well because its associated with rtx line\n\n if (!enableRtx) {\n description.sdp = description.sdp.replace(/\\r\\na=rtpmap:\\d+ rtx\\/\\d+/g, '');\n description.sdp = description.sdp.replace(/\\r\\na=fmtp:\\d+ apt=\\d+/g, '');\n }\n\n return peerConnection.setLocalDescription(description);\n })\n .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))\n .then(() => {\n if (!checkH264Support(peerConnection.sdp)) {\n throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');\n }\n\n if (!enableExtmap) {\n peerConnection.sdp = peerConnection.sdp.replace(/\\na=extmap.*/g, '');\n }\n\n pc.setContentSlides(peerConnection);\n\n Metrics.postEvent({\n event: eventType.LOCAL_SDP_GENERATED,\n meetingId\n });\n\n return peerConnection;\n })\n .catch((error) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#createOffer --> ${error}`);\n if (error instanceof InvalidSdpError) {\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.INVALID_ICE_CANDIDATE,\n {\n correlation_id: meetingId,\n code: error.code,\n reason: error.message\n }\n );\n }\n else {\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n }\n\n Metrics.postEvent({\n event: eventType.LOCAL_SDP_GENERATED,\n meetingId,\n data: {\n canProceed: false,\n errors: [\n Metrics.generateErrorPayload(2001, true,\n error.name.MEDIA_ENGINE)]\n }\n });\n pc.close(peerConnection);\n throw error;\n });\n};\n\n/**\n * rollBack local description in peerconnection\n * @param {Object} peerConnection\n * @returns {Promise.RTCPeerConnection}\n */\npc.rollBackLocalDescription = (peerConnection) => peerConnection\n .setLocalDescription(new RTCSessionDescription({type: SDP.ROLLBACK}))\n .then(() => peerConnection)\n .catch((err) => {\n LoggerProxy.logger.error(`Peer-connection-manager:index#setLocalDescription --> ${err} `);\n\n return Promise.error(err);\n });\n\n/**\n * @param {Object} params {\n * @param {Boolean} params.offerToReceiveAudio\n * @param {Boolean} params.offerToReceiveVideo\n * @param {string} params.offerSdp\n * @param {MediaStream} params.stream\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @returns {Promise.<Array>} [MediaSDP, ScreenSDP]\n */\npc.updatePeerConnection = (params, {meetingId, remoteQualityLevel}) => {\n LoggerProxy.logger.log(`PeerConnectionManager:index#updatePeerConnection --> updating the peerConnection with params: ${params}`);\n\n const {peerConnection, offerSdp} = params;\n\n return pc.createAnswer({\n peerConnection,\n offerSdp: offerSdp[0]\n }, {meetingId, remoteQualityLevel}).then((peerconnection) => {\n // The content slides should also be set when we are sending inactive\n pc.setContentSlides(peerconnection);\n\n return Promise.resolve([peerconnection.sdp]);\n });\n};\n\n/**\n * @param {Object} params\n * @param {Object} params.peerConnection\n * @param {Object} params.sdpConstraints\n * @param {Object} meetingProperties\n * @param {string} meetingProperties.meetingId\n * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH\n * @returns {RTCPeerConnection} peerConnection\n */\npc.createAnswer = (params, {meetingId, remoteQualityLevel}) => {\n const {peerConnection} = params;\n\n // TODO: Some times to many mercury event comes at the same time\n // Need to maintain state of peerconnection\n if (peerConnection.signalingState === SDP.HAVE_REMOTE_OFFER) {\n return Promise.resolve(peerConnection);\n }\n\n return pc.setRemoteSessionDetails(peerConnection, OFFER, params.offerSdp, meetingId)\n .then(() => peerConnection.createAnswer(params.sdpConstraints))\n .then((answer) =>\n\n peerConnection.setLocalDescription(answer))\n .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))\n .then(() => {\n peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);\n peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);\n peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);\n if (!checkH264Support(peerConnection.sdp)) {\n throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');\n }\n\n return peerConnection;\n })\n .catch((error) => {\n if (error instanceof InvalidSdpError) {\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.INVALID_ICE_CANDIDATE,\n {\n correlation_id: meetingId\n }\n );\n }\n else {\n const metricName = METRICS_OPERATIONAL_MEASURES.PEERCONNECTION_FAILURE;\n const data = {\n correlation_id: meetingId,\n reason: error.message,\n stack: error.stack\n };\n const metadata = {\n type: error.name\n };\n\n Metrics.sendOperationalMetric(metricName, data, metadata);\n }\n\n LoggerProxy.logger.error(`PeerConnectionManager:index#setRemoteSessionDetails --> Error creating remote session, error: ${error}`);\n });\n};\n\n/**\n * shut down the peer connection\n * @param {Object} peerConnection\n * @returns {undefined}\n */\npc.close = (peerConnection) => {\n // peerConnection.close() fails on firefox on network changes and gives a Dom exception\n // To avoid this we have added a try catch block.\n // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=1274407 for more information\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> attempting to close the peer connection');\n\n if (peerConnection && peerConnection.connectionState === PEER_CONNECTION_STATE.CLOSED) {\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> connection already closed');\n\n return Promise.resolve();\n }\n LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> closing the mediaPeerConnection');\n\n return Promise.resolve()\n .then(() => {\n if (peerConnection && peerConnection.close) {\n peerConnection.close();\n }\n });\n};\n\n\npc.setPeerConnectionEvents = (meeting) => {\n // In case ICE fail\n const {peerConnection} = meeting.mediaProperties;\n\n const connectionFailed = () => {\n if (meeting.reconnectionManager.iceState.resolve) {\n // DISCONNECTED state triggers first then it goes to FAILED STATE\n // sometimes the failed state can happen before 10 seconds (Which is the timer for the reconnect for ice disconnect)\n meeting.reconnectionManager.iceState.resolve();\n }\n\n meeting.reconnect({networkDisconnect: true});\n Metrics.postEvent({\n event: eventType.ICE_END,\n meeting,\n data: {\n canProceed: false,\n errors: [\n Metrics.generateErrorPayload(\n 2004, false, error.name.MEDIA_ENGINE\n )]\n }\n });\n\n meeting.uploadLogs({\n file: 'peer-connection-manager/index',\n function: 'connectionFailed'\n });\n\n Metrics.sendOperationalMetric(\n METRICS_OPERATIONAL_MEASURES.CONNECTION_FAILURE,\n {\n correlation_id: meeting.correlationId,\n locus_id: meeting.locusId\n }\n );\n };\n\n peerConnection.oniceconnectionstatechange = () => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHANGE.');\n switch (peerConnection.iceConnectionState) {\n case ICE_STATE.CHECKING:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHECKING.');\n Metrics.postEvent({event: eventType.ICE_START, meeting});\n break;\n case ICE_STATE.COMPLETED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE COMPLETED.');\n break;\n case ICE_STATE.CONNECTED:\n // Ice connection state goes to connected when both client and server sends STUN packets and\n // Established connected between them. Firefox does not trigger COMPLETED and only trigger CONNECTED\n Metrics.postEvent({event: eventType.ICE_END, meeting});\n meeting.setNetworkStatus(NETWORK_STATUS.CONNECTED);\n meeting.reconnectionManager.iceReconnected();\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CONNECTED.');\n break;\n case ICE_STATE.CLOSED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CLOSED.');\n break;\n case ICE_STATE.DISCONNECTED:\n meeting.setNetworkStatus(NETWORK_STATUS.DISCONNECTED);\n meeting.reconnectionManager.waitForIceReconnect()\n .catch(() => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED. Automatic Reconnection Timed Out.');\n\n connectionFailed();\n });\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED.');\n break;\n case ICE_STATE.FAILED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE FAILED.');\n // notify of ice failure\n // Ice failure is the only indicator currently for identifying the actual connection drop\n // Firefox takes sometime 10-15 seconds to go to failed state\n connectionFailed();\n break;\n default:\n break;\n }\n };\n\n peerConnection.onconnectionstatechange = () => {\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CHANGE.');\n switch (peerConnection.connectionState) {\n case CONNECTION_STATE.NEW:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE NEW.');\n break;\n case CONNECTION_STATE.CONNECTING:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTING.');\n break;\n case CONNECTION_STATE.CONNECTED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTED.');\n break;\n case CONNECTION_STATE.CLOSED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CLOSED.');\n break;\n case CONNECTION_STATE.DISCONNECTED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE DISCONNECTED.');\n break;\n case CONNECTION_STATE.FAILED:\n LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE FAILED.');\n // Special case happens only on chrome where there is no ICE FAILED event\n // only CONNECTION FAILED event gets triggered\n\n connectionFailed();\n break;\n default:\n break;\n }\n };\n};\n\nexport default pc;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/plugin-meetings",
3
- "version": "1.153.1",
3
+ "version": "1.153.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -24,18 +24,18 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@babel/runtime-corejs2": "^7.14.8",
27
- "@webex/webex-core": "1.153.1",
28
- "@webex/internal-plugin-mercury": "1.153.1",
27
+ "@webex/webex-core": "1.153.2",
28
+ "@webex/internal-plugin-mercury": "1.153.2",
29
29
  "webrtc-adapter": "^7.7.0",
30
30
  "lodash": "^4.17.21",
31
31
  "uuid": "^3.3.2",
32
32
  "global": "^4.4.0",
33
33
  "ip-anonymize": "^0.1.0",
34
- "@webex/common": "1.153.1",
34
+ "@webex/common": "1.153.2",
35
35
  "bowser": "^2.11.0",
36
36
  "sdp-transform": "^2.12.0",
37
37
  "readable-stream": "^3.6.0",
38
- "@webex/common-timers": "1.153.1",
38
+ "@webex/common-timers": "1.153.2",
39
39
  "btoa": "^1.2.1",
40
40
  "javascript-state-machine": "^3.1.0",
41
41
  "envify": "^4.1.0"
@@ -111,10 +111,29 @@ WebExMeetingsErrors[UserInLobbyError.CODE] = UserInLobbyError;
111
111
  class InvalidSdpError extends WebexMeetingsError {
112
112
  static CODE = 30201;
113
113
 
114
- constructor() {
115
- super(InvalidSdpError.CODE, 'iceConnection: sdp generated is invalid');
114
+ constructor(message) {
115
+ super(InvalidSdpError.CODE, message || 'iceConnection: sdp generated is invalid');
116
116
  }
117
117
  }
118
118
 
119
119
  export {InvalidSdpError};
120
120
  WebExMeetingsErrors[InvalidSdpError.CODE] = InvalidSdpError;
121
+
122
+
123
+ /**
124
+ * @class IceGatheringFailed
125
+ * @classdesc Raised whenever ice gathering fails.
126
+ * @extends WebexMeetingsError
127
+ * @property {number} code - 30202
128
+ * @property {string} message - 'user failed ice gathering check network/firewall'
129
+ */
130
+ class IceGatheringFailed extends WebexMeetingsError {
131
+ static CODE = 30202;
132
+
133
+ constructor() {
134
+ super(IceGatheringFailed.CODE, 'iceConnection: gethering ice candidate failed');
135
+ }
136
+ }
137
+
138
+ export {IceGatheringFailed};
139
+ WebExMeetingsErrors[IceGatheringFailed.CODE] = IceGatheringFailed;
package/src/constants.js CHANGED
@@ -25,8 +25,9 @@ export const CMR_MEETINGS = 'cmrmeetings';
25
25
  export const CLAIM = 'claim';
26
26
  export const CONTROLS = 'controls';
27
27
  export const CONTENT = 'content';
28
+ export const COMPLETE = 'complete';
28
29
  export const WHITEBOARD = 'whiteboard';
29
-
30
+ export const GATHERING = 'gathering';
30
31
  export const DEVELOPMENT = 'development';
31
32
  export const DECLINE = 'decline';
32
33
 
@@ -10,9 +10,8 @@ import Metrics from '../metrics';
10
10
  import LoggerProxy from '../common/logs/logger-proxy';
11
11
  import StaticConfig from '../common/config';
12
12
  import {
13
- RETRY_TIMEOUT,
14
- ICE_TIMEOUT,
15
- HOST,
13
+ COMPLETE,
14
+ GATHERING,
16
15
  AUDIO,
17
16
  SDP,
18
17
  ICE_STATE,
@@ -22,13 +21,12 @@ import {
22
21
  OFFER,
23
22
  QUALITY_LEVELS,
24
23
  MAX_FRAMESIZES,
25
- METRICS_OPERATIONAL_MEASURES,
26
- IPV4_REGEX
24
+ METRICS_OPERATIONAL_MEASURES
27
25
  } from '../constants';
28
26
  import {error, eventType} from '../metrics/config';
29
27
  import MediaError from '../common/errors/media';
30
28
  import ParameterError from '../common/errors/parameter';
31
- import {InvalidSdpError} from '../common/errors/webex-errors';
29
+ import {InvalidSdpError, IceGatheringFailed} from '../common/errors/webex-errors';
32
30
  import BrowserDetection from '../common/browser-detection';
33
31
 
34
32
  import PeerConnectionUtils from './util';
@@ -122,18 +120,10 @@ const isSdpInvalid = (sdp) => {
122
120
  const parsedSdp = sdpTransform.parse(sdp);
123
121
 
124
122
  for (const mediaLine of parsedSdp.media) {
125
- if (mediaLine.candidates && mediaLine.candidates.length === 0) {
123
+ if (!mediaLine.candidates || mediaLine.candidates?.length === 0) {
126
124
  LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candadate never completed');
127
125
 
128
- return 'iceCandidate: Ice candadate never completed';
129
- }
130
- // Sometimes the candidates might be there but only IPV6 we need to makes sure we have IPV4
131
- const hostCandidate = mediaLine.candidates.filter((candidate) => !!(candidate.type === HOST && candidate.ip.match(IPV4_REGEX)));
132
-
133
- if (hostCandidate.length === 0) {
134
- LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: no IPV4 candidate present');
135
-
136
- return 'iceCandidate: no IPV4 candidate present';
126
+ return 'iceCandidate: Ice gathering never completed';
137
127
  }
138
128
 
139
129
  if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {
@@ -193,46 +183,53 @@ pc.setContentSlides = (screenPc) => {
193
183
  */
194
184
  pc.iceCandidate = (peerConnection, {remoteQualityLevel}) =>
195
185
  new Promise((resolve, reject) => {
196
- // TODO: we dont need timeout as we can check the api state and validate.
197
- const timeout = setTimeout(() => {
186
+ const now = Date.now();
187
+ const doneGatheringIceCandidate = () => {
188
+ const miliseconds = parseInt(Math.abs(Date.now() - now), 4);
189
+
198
190
  peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
199
191
  peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
200
192
  peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
201
193
 
202
- if (isSdpInvalid(peerConnection.sdp)) {
203
- setTimeout(() => {
204
- // peerconnection does gather ice candidate IP but in some cases due to firewall
205
- // or proxy the ice candidate does not get gathered so we need to wait and then retry
206
- // if still not valid then throw an error saying missing ice candidate
207
- // if ice candidate still not present after retry
208
- const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
194
+ const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
209
195
 
210
- if (!invalidSdpPresent) {
211
- resolve(peerConnection);
212
- }
213
- else {
214
- LoggerProxy.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');
215
- reject(new InvalidSdpError(invalidSdpPresent));
216
- }
217
- }, RETRY_TIMEOUT);
196
+ if (invalidSdpPresent) {
197
+ LoggerProxy.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');
198
+ reject(new InvalidSdpError(invalidSdpPresent));
218
199
  }
219
- else {
220
- resolve(peerConnection);
200
+ LoggerProxy.logger.log(`PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ${miliseconds} miliseconds`);
201
+
202
+
203
+ resolve();
204
+ };
205
+
206
+ // If ice has already been gathered
207
+ if (peerConnection.iceGatheringState === COMPLETE) {
208
+ doneGatheringIceCandidate();
209
+ }
210
+
211
+ peerConnection.onIceGatheringStateChange = () => {
212
+ if (peerConnection.iceGatheringState === COMPLETE) {
213
+ doneGatheringIceCandidate(peerConnection);
214
+ }
215
+ if (peerConnection.iceGatheringState === GATHERING) {
216
+ LoggerProxy.logger.log('PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering');
221
217
  }
222
- }, ICE_TIMEOUT);
218
+ };
223
219
 
224
220
  peerConnection.onicecandidate = (evt) => {
225
- if (!evt.candidate && !peerConnection.sdp) {
226
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
227
- peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
228
- peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
229
-
230
- if (evt.candidate === null && !isSdpInvalid(peerConnection.sdp)) {
231
- clearTimeout(timeout);
232
- resolve(peerConnection);
233
- }
221
+ if (evt.candidate === null) {
222
+ doneGatheringIceCandidate(peerConnection);
223
+ }
224
+ else {
225
+ LoggerProxy.logger.log(`PeerConnectionManager:index#onicecandidate --> Candidate ${evt.candidate?.type} ${evt.candidate?.protocol} ${evt.candidate?.address}:${evt.candidate?.port}`);
234
226
  }
235
227
  };
228
+
229
+ peerConnection.onicecandidateerror = (event) => {
230
+ LoggerProxy.logger.error('PeerConnectionManager:index#onicecandidateerror --> Failed to gather ice candidate.', event);
231
+ reject(new IceGatheringFailed());
232
+ };
236
233
  });
237
234
 
238
235
  /**
@@ -406,9 +403,6 @@ pc.createOffer = (peerConnection, {
406
403
  })
407
404
  .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
408
405
  .then(() => {
409
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
410
- peerConnection.sdp = setMaxFs(peerConnection.sdp, remoteQualityLevel);
411
- peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
412
406
  if (!checkH264Support(peerConnection.sdp)) {
413
407
  throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');
414
408
  }