Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

IceFailedHandling.js 5.2KB

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