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

ParticipantConnectionStatus.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* global __filename, module, require */
  2. var logger = require("jitsi-meet-logger").getLogger(__filename);
  3. var RTCEvents = require("../../service/RTC/RTCEvents");
  4. import * as JitsiConferenceEvents from "../../JitsiConferenceEvents";
  5. /**
  6. * Class is responsible for emitting
  7. * JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED events.
  8. *
  9. * @constructor
  10. * @param rtc {RTC} the RTC service instance
  11. * @param conference {JitsiConference} parent conference instance
  12. */
  13. function ParticipantConnectionStatus(rtc, conference) {
  14. this.rtc = rtc;
  15. this.conference = conference;
  16. }
  17. /**
  18. * Initializes <tt>ParticipantConnectionStatus</tt> and bind required event
  19. * listeners.
  20. */
  21. ParticipantConnectionStatus.prototype.init = function() {
  22. this._onEndpointConnStatusChanged
  23. = this.onEndpointConnStatusChanged.bind(this);
  24. this.rtc.addListener(
  25. RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
  26. this._onEndpointConnStatusChanged);
  27. };
  28. /**
  29. * Removes all event listeners and disposes of all resources held by this
  30. * instance.
  31. */
  32. ParticipantConnectionStatus.prototype.dispose = function () {
  33. this.rtc.removeListener(
  34. RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
  35. this._onEndpointConnStatusChanged);
  36. };
  37. /**
  38. * Handles RTCEvents.ENDPOINT_CONN_STATUS_CHANGED triggered when we receive
  39. * notification over the data channel from the bridge about endpoint's
  40. * connection status update.
  41. * @param endpointId {string} the endpoint ID(MUC nickname/resource JID)
  42. * @param status {boolean} true if the connection is OK or false otherwise
  43. */
  44. ParticipantConnectionStatus.prototype.onEndpointConnStatusChanged
  45. = function(endpointId, status) {
  46. logger.debug(
  47. 'Detector RTCEvents.ENDPOINT_CONN_STATUS_CHANGED(' + Date.now() +'): '
  48. + endpointId +": " + status);
  49. // Filter out events for the local JID for now
  50. if (endpointId !== this.conference.myUserId()) {
  51. this._changeConnectionStatus(endpointId, status);
  52. }
  53. };
  54. ParticipantConnectionStatus.prototype._changeConnectionStatus
  55. = function (endpointId, newStatus) {
  56. var participant = this.conference.getParticipantById(endpointId);
  57. if (!participant) {
  58. // This will happen when participant exits the conference with broken
  59. // ICE connection and we join after that. The bridge keeps sending
  60. // that notification until the conference does not expire.
  61. logger.warn(
  62. 'Missed participant connection status update - ' +
  63. 'no participant for endpoint: ' + endpointId);
  64. return;
  65. }
  66. if (participant.isConnectionActive() !== newStatus) {
  67. participant._setIsConnectionActive(newStatus);
  68. logger.debug(
  69. 'Emit endpoint conn status(' + Date.now() + '): ',
  70. endpointId, newStatus);
  71. this.conference.eventEmitter.emit(
  72. JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,
  73. endpointId, newStatus);
  74. }
  75. };
  76. module.exports = ParticipantConnectionStatus;