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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 connection is not re-established within 2 secs after the internet comes back online, the client will initiate
  9. * a session restart via 'session-terminate'. This results in Jicofo re-inviting the participant into the conference by
  10. * recreating the jvb media session so that there is minimla disruption to the user by default. However, if the
  11. * 'enableForcedReload' option is set in config.js, the conference will be forcefully reloaded.
  12. */
  13. export default class IceFailedHandling {
  14. /**
  15. * Creates new {@code DelayedIceFailed} task.
  16. * @param {JitsiConference} conference
  17. */
  18. constructor(conference) {
  19. this._conference = conference;
  20. }
  21. /**
  22. * After making sure there's no way for the ICE connection to recover this method either sends ICE failed
  23. * notification to Jicofo or emits the ice failed conference event.
  24. * @private
  25. * @returns {void}
  26. */
  27. _actOnIceFailed() {
  28. if (!this._conference.room) {
  29. return;
  30. }
  31. const { enableForcedReload } = this._conference.options.config;
  32. logger.info(`ICE failed, enableForcedReload: ${enableForcedReload}`);
  33. if (enableForcedReload) {
  34. logger.info('ICE failed, force reloading the conference');
  35. this._conference.eventEmitter.emit(
  36. JitsiConferenceEvents.CONFERENCE_FAILED,
  37. JitsiConferenceErrors.CONFERENCE_RESTARTED);
  38. return;
  39. }
  40. const jvbConnection = this._conference.jvbJingleSession;
  41. const jvbConnIceState = jvbConnection && jvbConnection.getIceConnectionState();
  42. if (!jvbConnection) {
  43. logger.warn('Not sending ICE failed - no JVB connection');
  44. } else if (jvbConnIceState === 'connected') {
  45. logger.info('ICE connection restored - not sending ICE failed');
  46. } else {
  47. logger.info(`Sending ICE failed - the connection did not recover, ICE state: ${jvbConnIceState}`);
  48. this._conference._stopJvbSession({
  49. reason: 'connectivity-error',
  50. reasonDescription: 'ICE FAILED',
  51. requestRestart: true,
  52. sendSessionTerminate: true
  53. });
  54. }
  55. }
  56. /**
  57. * Starts the task.
  58. */
  59. start() {
  60. // Using xmpp.ping allows to handle both XMPP being disconnected and internet offline cases. The ping function
  61. // uses sendIQ2 method which is resilient to XMPP connection disconnected state and will patiently wait until it
  62. // gets reconnected.
  63. // This also handles the case about waiting for the internet to come back online, because ping
  64. // will only succeed when the internet is online and then there's a chance for the ICE to recover from FAILED to
  65. // CONNECTED which is the extra 2 second timeout after ping.
  66. // The 65 second timeout is given on purpose as there's no chance for XMPP to recover after 65 seconds of no
  67. // communication with the server. Such resume attempt will result in unrecoverable conference failed event due
  68. // to 'item-not-found' error returned by the server.
  69. this._conference.xmpp.ping(65000).then(
  70. () => {
  71. if (!this._canceled) {
  72. this._iceFailedTimeout = window.setTimeout(() => {
  73. this._iceFailedTimeout = undefined;
  74. this._actOnIceFailed();
  75. }, 2000);
  76. }
  77. },
  78. error => {
  79. logger.error('PING error/timeout - not sending ICE failed', error);
  80. });
  81. }
  82. /**
  83. * Cancels the task.
  84. */
  85. cancel() {
  86. this._canceled = true;
  87. window.clearTimeout(this._iceFailedTimeout);
  88. }
  89. }