您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

IceFailedHandling.js 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (!this._conference.options.config.enableIceRestart) {
  33. logger.info('ICE failed, but ICE restarts are disabled');
  34. this._conference.eventEmitter.emit(
  35. JitsiConferenceEvents.CONFERENCE_FAILED,
  36. JitsiConferenceErrors.ICE_FAILED);
  37. return;
  38. }
  39. const jvbConnection = this._conference.jvbJingleSession;
  40. const jvbConnIceState = jvbConnection && jvbConnection.getIceConnectionState();
  41. if (!jvbConnection) {
  42. logger.warn('Not sending ICE failed - no JVB connection');
  43. } else if (jvbConnIceState === 'connected') {
  44. logger.info('ICE connection restored - not sending ICE failed');
  45. } else {
  46. logger.info(`Sending ICE failed - the connection has not recovered: ${jvbConnIceState}`);
  47. jvbConnection.sendIceFailedNotification();
  48. }
  49. }
  50. /**
  51. * Starts the task.
  52. */
  53. start() {
  54. // Using xmpp.ping allows to handle both XMPP being disconnected and internet offline cases. The ping function
  55. // uses sendIQ2 method which is resilient to XMPP connection disconnected state and will patiently wait until it
  56. // gets reconnected.
  57. // This also handles the case about waiting for the internet to come back online, because ping
  58. // will only succeed when the internet is online and then there's a chance for the ICE to recover from FAILED to
  59. // CONNECTED which is the extra 2 second timeout after ping.
  60. // The 65 second timeout is given on purpose as there's no chance for XMPP to recover after 65 seconds of no
  61. // communication with the server. Such resume attempt will result in unrecoverable conference failed event due
  62. // to 'item-not-found' error returned by the server.
  63. this._conference.xmpp.ping(65000).then(
  64. () => {
  65. if (!this._canceled) {
  66. this._iceFailedTimeout = window.setTimeout(() => {
  67. this._iceFailedTimeout = undefined;
  68. this._actOnIceFailed();
  69. }, 2000);
  70. }
  71. },
  72. error => {
  73. logger.error('PING error/timeout - not sending ICE failed', error);
  74. });
  75. }
  76. /**
  77. * Cancels the task.
  78. */
  79. cancel() {
  80. this._canceled = true;
  81. window.clearTimeout(this._iceFailedTimeout);
  82. }
  83. }