You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IceFailedHandling.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { getLogger } from '@jitsi/logger';
  2. import * as JitsiConferenceErrors from '../../JitsiConferenceErrors';
  3. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  4. const logger = getLogger(__filename);
  5. /**
  6. * This class deals with shenanigans around JVB media session's ICE failed status handling.
  7. *
  8. * If ICE restarts are NOT explicitly enabled by the {@code enableIceRestart} config option, then the conference will
  9. * delay emitting the {@JitsiConferenceErrors.ICE_FAILED} event by 15 seconds. If the network info module reports
  10. * the internet offline status then the time will start counting after the internet comes back online.
  11. *
  12. * If ICE restart are enabled, then a delayed ICE failed notification to Jicofo will be sent, only if the ICE connection
  13. * does not recover soon after or before the XMPP connection is restored (if it was ever broken). If ICE fails while
  14. * the XMPP connection is not broken then the notifications will be sent after 2 seconds delay.
  15. */
  16. export default class IceFailedHandling {
  17. /**
  18. * Creates new {@code DelayedIceFailed} task.
  19. * @param {JitsiConference} conference
  20. */
  21. constructor(conference) {
  22. this._conference = conference;
  23. }
  24. /**
  25. * After making sure there's no way for the ICE connection to recover this method either sends ICE failed
  26. * notification to Jicofo or emits the ice failed conference event.
  27. * @private
  28. * @returns {void}
  29. */
  30. _actOnIceFailed() {
  31. const { enableForcedReload, enableIceRestart } = this._conference.options.config;
  32. const explicitlyDisabled = typeof enableIceRestart !== 'undefined' && !enableIceRestart;
  33. const supportsRestartByTerminate = this._conference.room.supportsRestartByTerminate();
  34. const useTerminateForRestart = supportsRestartByTerminate && !enableIceRestart;
  35. logger.info('ICE failed,'
  36. + ` enableForcedReload: ${enableForcedReload},`
  37. + ` enableIceRestart: ${enableIceRestart},`
  38. + ` supports restart by terminate: ${supportsRestartByTerminate}`);
  39. if (explicitlyDisabled || (!enableIceRestart && !supportsRestartByTerminate) || enableForcedReload) {
  40. logger.info('ICE failed, but ICE restarts are disabled');
  41. const reason = enableForcedReload
  42. ? JitsiConferenceErrors.CONFERENCE_RESTARTED
  43. : JitsiConferenceErrors.ICE_FAILED;
  44. this._conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, reason);
  45. return;
  46. }
  47. const jvbConnection = this._conference.jvbJingleSession;
  48. const jvbConnIceState = jvbConnection && jvbConnection.getIceConnectionState();
  49. if (!jvbConnection) {
  50. logger.warn('Not sending ICE failed - no JVB connection');
  51. } else if (jvbConnIceState === 'connected') {
  52. logger.info('ICE connection restored - not sending ICE failed');
  53. } else {
  54. logger.info('Sending ICE failed - the connection did not recover, '
  55. + `ICE state: ${jvbConnIceState}, `
  56. + `use 'session-terminate': ${useTerminateForRestart}`);
  57. if (useTerminateForRestart) {
  58. this._conference.jvbJingleSession.terminate(
  59. () => {
  60. logger.info('session-terminate for ice restart - done');
  61. },
  62. error => {
  63. logger.error(`session-terminate for ice restart - error: ${error.message}`);
  64. }, {
  65. reason: 'connectivity-error',
  66. reasonDescription: 'ICE FAILED',
  67. requestRestart: true,
  68. sendSessionTerminate: true
  69. });
  70. } else {
  71. this._conference.jvbJingleSession.sendIceFailedNotification();
  72. }
  73. }
  74. }
  75. /**
  76. * Starts the task.
  77. */
  78. start() {
  79. // Using xmpp.ping allows to handle both XMPP being disconnected and internet offline cases. The ping function
  80. // uses sendIQ2 method which is resilient to XMPP connection disconnected state and will patiently wait until it
  81. // gets reconnected.
  82. // This also handles the case about waiting for the internet to come back online, because ping
  83. // will only succeed when the internet is online and then there's a chance for the ICE to recover from FAILED to
  84. // CONNECTED which is the extra 2 second timeout after ping.
  85. // The 65 second timeout is given on purpose as there's no chance for XMPP to recover after 65 seconds of no
  86. // communication with the server. Such resume attempt will result in unrecoverable conference failed event due
  87. // to 'item-not-found' error returned by the server.
  88. this._conference.xmpp.ping(65000).then(
  89. () => {
  90. if (!this._canceled) {
  91. this._iceFailedTimeout = window.setTimeout(() => {
  92. this._iceFailedTimeout = undefined;
  93. this._actOnIceFailed();
  94. }, 2000);
  95. }
  96. },
  97. error => {
  98. logger.error('PING error/timeout - not sending ICE failed', error);
  99. });
  100. }
  101. /**
  102. * Cancels the task.
  103. */
  104. cancel() {
  105. this._canceled = true;
  106. window.clearTimeout(this._iceFailedTimeout);
  107. }
  108. }