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

IceFailedNotification.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* global __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. const logger = getLogger(__filename);
  4. /**
  5. * A delayed ICE failed notification which is triggered only if the ICE
  6. * connection does not recover soon after or before the XMPP connection is
  7. * restored (if it was ever broken). If ICE fails while the XMPP connection is
  8. * not broken then the notifications will be sent after 2 seconds delay. This
  9. * extra delay is not intentional just a side effect of the code.
  10. * NOTE that this delayed task can only be used if PING is supported by the XMPP
  11. * server.
  12. */
  13. export default class IceFailedNotification {
  14. /**
  15. * Creates new {@code DelayedIceFailed} task.
  16. * @param {JitsiConference} conference
  17. */
  18. constructor(conference) {
  19. this._conference = conference;
  20. }
  21. /**
  22. * Starts the task.
  23. * @param {JingleSessionPC} session - the JVB Jingle session.
  24. */
  25. start(session) {
  26. // The 65 seconds are greater than the default Prosody's BOSH
  27. // timeout of 60. This gives some time for the XMPP connection
  28. // to recover.
  29. this._conference.xmpp.ping(65000).then(
  30. () => {
  31. if (this._canceled) {
  32. return;
  33. }
  34. const jvbConnection = this._conference.jvbJingleSession;
  35. const jvbConnIceState = jvbConnection && jvbConnection.getIceConnectionState();
  36. if (!jvbConnection) {
  37. logger.warn('Not sending ICE failed - no JVB connection');
  38. } else if (jvbConnIceState === 'connected') {
  39. logger.info('ICE connection restored - not sending ICE failed');
  40. } else {
  41. this._iceFailedTimeout = window.setTimeout(() => {
  42. logger.info(`Sending ICE failed - the connection has not recovered: ${jvbConnIceState}`);
  43. this._iceFailedTimeout = undefined;
  44. session.sendIceFailedNotification();
  45. }, 2000);
  46. }
  47. },
  48. error => {
  49. logger.error(
  50. 'PING error/timeout - not sending ICE failed', error);
  51. });
  52. }
  53. /**
  54. * Cancels the task.
  55. */
  56. cancel() {
  57. this._canceled = true;
  58. if (this._iceFailedTimeout) {
  59. window.clearTimeout(this._iceFailedTimeout);
  60. }
  61. }
  62. }