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

ParticipantConnectionStatus.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /* global __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  4. import * as JitsiTrackEvents from '../../JitsiTrackEvents';
  5. import * as MediaType from '../../service/RTC/MediaType';
  6. import RTCBrowserType from '../RTC/RTCBrowserType';
  7. import RTCEvents from '../../service/RTC/RTCEvents';
  8. import Statistics from '../statistics/statistics';
  9. const logger = getLogger(__filename);
  10. /**
  11. * Default value of 2000 milliseconds for
  12. * {@link ParticipantConnectionStatus.rtcMuteTimeout}.
  13. *
  14. * @type {number}
  15. */
  16. const DEFAULT_RTC_MUTE_TIMEOUT = 2000;
  17. /**
  18. * The time to wait a track to be restored. Track which was out of lastN
  19. * should be inactive and when entering lastN it becomes restoring and when
  20. * data is received from bridge it will become active, but if no data is
  21. * received for some time we set status of that participant connection to
  22. * interrupted.
  23. * @type {number}
  24. */
  25. const DEFAULT_RESTORING_TIMEOUT = 5000;
  26. /**
  27. * Participant connection statuses.
  28. *
  29. * @type {{
  30. * ACTIVE: string,
  31. * INACTIVE: string,
  32. * INTERRUPTED: string,
  33. * RESTORING: string
  34. * }}
  35. */
  36. export const ParticipantConnectionStatus = {
  37. /**
  38. * Status indicating that connection is currently active.
  39. */
  40. ACTIVE: 'active',
  41. /**
  42. * Status indicating that connection is currently inactive.
  43. * Inactive means the connection was stopped on purpose from the bridge,
  44. * like exiting lastN or adaptivity decided to drop video because of not
  45. * enough bandwidth.
  46. */
  47. INACTIVE: 'inactive',
  48. /**
  49. * Status indicating that connection is currently interrupted.
  50. */
  51. INTERRUPTED: 'interrupted',
  52. /**
  53. * Status indicating that connection is currently restoring.
  54. */
  55. RESTORING: 'restoring'
  56. };
  57. /**
  58. * Class is responsible for emitting
  59. * JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED events.
  60. */
  61. export default class ParticipantConnectionStatusHandler {
  62. /* eslint-disable max-params*/
  63. /**
  64. * Calculates the new {@link ParticipantConnectionStatus} based on
  65. * the values given for some specific remote user. It is assumed that
  66. * the conference is currently in the JVB mode (in contrary to the P2P mode)
  67. * @param {boolean} isConnectionActiveByJvb true if the JVB did not get any
  68. * data from the user for the last 15 seconds.
  69. * @param {boolean} isInLastN indicates whether the user is in the last N
  70. * set. When set to false it means that JVB is not sending any video for
  71. * the user.
  72. * @param {boolean} isRestoringTimedout if true it means that the user has
  73. * been outside of last N too long to be considered
  74. * {@link ParticipantConnectionStatus.RESTORING}.
  75. * @param {boolean} isVideoMuted true if the user is video muted and we
  76. * should not expect to receive any video.
  77. * @param {boolean} isVideoTrackFrozen if the current browser support video
  78. * frozen detection then it will be set to true when the video track is
  79. * frozen. If the current browser does not support frozen detection the it's
  80. * always false.
  81. * @return {ParticipantConnectionStatus} the new connection status for
  82. * the user for whom the values above were provided.
  83. * @private
  84. */
  85. static _getNewStateForJvbMode(
  86. isConnectionActiveByJvb,
  87. isInLastN,
  88. isRestoringTimedout,
  89. isVideoMuted,
  90. isVideoTrackFrozen) {
  91. if (!isConnectionActiveByJvb) {
  92. // when there is a connection problem signaled from jvb
  93. // it means no media was flowing for at least 15secs, so both audio
  94. // and video are most likely interrupted
  95. return ParticipantConnectionStatus.INTERRUPTED;
  96. } else if (isVideoMuted) {
  97. // If the connection is active according to JVB and the user is
  98. // video muted there is no way for the connection to be inactive,
  99. // because the detection logic below only makes sense for video.
  100. return ParticipantConnectionStatus.ACTIVE;
  101. }
  102. // Logic when isVideoTrackFrozen is supported
  103. if (RTCBrowserType.isVideoMuteOnConnInterruptedSupported()) {
  104. if (!isVideoTrackFrozen) {
  105. // If the video is playing we're good
  106. return ParticipantConnectionStatus.ACTIVE;
  107. } else if (isInLastN) {
  108. return isRestoringTimedout
  109. ? ParticipantConnectionStatus.INTERRUPTED
  110. : ParticipantConnectionStatus.RESTORING;
  111. }
  112. return ParticipantConnectionStatus.INACTIVE;
  113. }
  114. // Because this browser is incapable of detecting frozen video we must
  115. // rely on the lastN value
  116. return isInLastN
  117. ? ParticipantConnectionStatus.ACTIVE
  118. : ParticipantConnectionStatus.INACTIVE;
  119. }
  120. /* eslint-enable max-params*/
  121. /**
  122. * In P2P mode we don't care about any values coming from the JVB and
  123. * the connection status can be only active or inactive.
  124. * @param {boolean} isVideoMuted the user if video muted
  125. * @param {boolean} isVideoTrackFrozen true if the video track for
  126. * the remote user is currently frozen. If the current browser does not
  127. * support video frozen detection then it's always false.
  128. * @return {ParticipantConnectionStatus}
  129. * @private
  130. */
  131. static _getNewStateForP2PMode(isVideoMuted, isVideoTrackFrozen) {
  132. if (!RTCBrowserType.isVideoMuteOnConnInterruptedSupported()) {
  133. // There's no way to detect problems in P2P when there's no video
  134. // track frozen detection...
  135. return ParticipantConnectionStatus.ACTIVE;
  136. }
  137. return isVideoMuted || !isVideoTrackFrozen
  138. ? ParticipantConnectionStatus.ACTIVE
  139. : ParticipantConnectionStatus.INACTIVE;
  140. }
  141. /**
  142. * Creates new instance of <tt>ParticipantConnectionStatus</tt>.
  143. *
  144. * @constructor
  145. * @param {RTC} rtc the RTC service instance
  146. * @param {JitsiConference} conference parent conference instance
  147. * @param {number} rtcMuteTimeout (optional) custom value for
  148. * {@link ParticipantConnectionStatus.rtcMuteTimeout}.
  149. */
  150. constructor(rtc, conference, rtcMuteTimeout) {
  151. this.rtc = rtc;
  152. this.conference = conference;
  153. /**
  154. * A map of the "endpoint ID"(which corresponds to the resource part
  155. * of MUC JID(nickname)) to the timeout callback IDs scheduled using
  156. * window.setTimeout.
  157. * @type {Object.<string, number>}
  158. */
  159. this.trackTimers = {};
  160. /**
  161. * This map holds the endpoint connection status received from the JVB
  162. * (as it might be different than the one stored in JitsiParticipant).
  163. * Required for getting back in sync when remote video track is removed.
  164. * @type {Object.<string, boolean>}
  165. */
  166. this.connStatusFromJvb = { };
  167. /**
  168. * How long we're going to wait after the RTC video track muted event
  169. * for the corresponding signalling mute event, before the connection
  170. * interrupted is fired. The default value is
  171. * {@link DEFAULT_RTC_MUTE_TIMEOUT}.
  172. *
  173. * @type {number} amount of time in milliseconds
  174. */
  175. this.rtcMuteTimeout
  176. = typeof rtcMuteTimeout === 'number'
  177. ? rtcMuteTimeout : DEFAULT_RTC_MUTE_TIMEOUT;
  178. /**
  179. * This map holds a timestamp indicating when participant's video track
  180. * was RTC muted (it is assumed that each participant can have only 1
  181. * video track at a time). The purpose of storing the timestamp is to
  182. * avoid the transition to disconnected status in case of legitimate
  183. * video mute operation where the signalling video muted event can
  184. * arrive shortly after RTC muted event.
  185. *
  186. * The key is participant's ID which is the same as endpoint id in
  187. * the Colibri conference allocated on the JVB.
  188. *
  189. * The value is a timestamp measured in milliseconds obtained with
  190. * <tt>Date.now()</tt>.
  191. *
  192. * FIXME merge this logic with NO_DATA_FROM_SOURCE event
  193. * implemented in JitsiLocalTrack by extending the event to
  194. * the remote track and allowing to set different timeout for
  195. * local and remote tracks.
  196. *
  197. * @type {Object.<string, number>}
  198. */
  199. this.rtcMutedTimestamp = { };
  200. logger.info(`RtcMuteTimeout set to: ${this.rtcMuteTimeout}`);
  201. /**
  202. * This map holds the timestamps indicating when participant's video
  203. * entered lastN set. Participants entering lastN will have connection
  204. * status restoring and when we start receiving video will become
  205. * active, but if video is not received for certain time
  206. * {@link DEFAULT_RESTORING_TIMEOUT} that participant connection status
  207. * will become interrupted.
  208. *
  209. * @type {Map<string, number>}
  210. */
  211. this.enteredLastNTimestamp = new Map();
  212. /**
  213. * A map of the "endpoint ID"(which corresponds to the resource part
  214. * of MUC JID(nickname)) to the restoring timeout callback IDs
  215. * scheduled using window.setTimeout.
  216. *
  217. * @type {Map<string, number>}
  218. */
  219. this.restoringTimers = new Map();
  220. }
  221. /**
  222. * Initializes <tt>ParticipantConnectionStatus</tt> and bind required event
  223. * listeners.
  224. */
  225. init() {
  226. this._onEndpointConnStatusChanged
  227. = this.onEndpointConnStatusChanged.bind(this);
  228. this.rtc.addListener(
  229. RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
  230. this._onEndpointConnStatusChanged);
  231. // Handles P2P status changes
  232. this._onP2PStatus = this.refreshConnectionStatusForAll.bind(this);
  233. this.conference.on(JitsiConferenceEvents.P2P_STATUS, this._onP2PStatus);
  234. // On some browsers MediaStreamTrack trigger "onmute"/"onunmute"
  235. // events for video type tracks when they stop receiving data which is
  236. // often a sign that remote user is having connectivity issues
  237. if (RTCBrowserType.isVideoMuteOnConnInterruptedSupported()) {
  238. this._onTrackRtcMuted = this.onTrackRtcMuted.bind(this);
  239. this.rtc.addListener(
  240. RTCEvents.REMOTE_TRACK_MUTE, this._onTrackRtcMuted);
  241. this._onTrackRtcUnmuted = this.onTrackRtcUnmuted.bind(this);
  242. this.rtc.addListener(
  243. RTCEvents.REMOTE_TRACK_UNMUTE, this._onTrackRtcUnmuted);
  244. // Track added/removed listeners are used to bind "mute"/"unmute"
  245. // event handlers
  246. this._onRemoteTrackAdded = this.onRemoteTrackAdded.bind(this);
  247. this.conference.on(
  248. JitsiConferenceEvents.TRACK_ADDED,
  249. this._onRemoteTrackAdded);
  250. this._onRemoteTrackRemoved = this.onRemoteTrackRemoved.bind(this);
  251. this.conference.on(
  252. JitsiConferenceEvents.TRACK_REMOVED,
  253. this._onRemoteTrackRemoved);
  254. // Listened which will be bound to JitsiRemoteTrack to listen for
  255. // signalling mute/unmute events.
  256. this._onSignallingMuteChanged
  257. = this.onSignallingMuteChanged.bind(this);
  258. }
  259. this._onLastNChanged = this._onLastNChanged.bind(this);
  260. this.conference.on(
  261. JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  262. this._onLastNChanged);
  263. }
  264. /**
  265. * Removes all event listeners and disposes of all resources held by this
  266. * instance.
  267. */
  268. dispose() {
  269. this.rtc.removeListener(
  270. RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
  271. this._onEndpointConnStatusChanged);
  272. if (RTCBrowserType.isVideoMuteOnConnInterruptedSupported()) {
  273. this.rtc.removeListener(
  274. RTCEvents.REMOTE_TRACK_MUTE,
  275. this._onTrackRtcMuted);
  276. this.rtc.removeListener(
  277. RTCEvents.REMOTE_TRACK_UNMUTE,
  278. this._onTrackRtcUnmuted);
  279. this.conference.off(
  280. JitsiConferenceEvents.TRACK_ADDED,
  281. this._onRemoteTrackAdded);
  282. this.conference.off(
  283. JitsiConferenceEvents.TRACK_REMOVED,
  284. this._onRemoteTrackRemoved);
  285. }
  286. this.conference.off(
  287. JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  288. this._onLastNChanged);
  289. this.conference.off(
  290. JitsiConferenceEvents.P2P_STATUS, this._onP2PStatus);
  291. const participantIds = Object.keys(this.trackTimers);
  292. for (const participantId of participantIds) {
  293. this.clearTimeout(participantId);
  294. this.clearRtcMutedTimestamp(participantId);
  295. }
  296. // Clear RTC connection status cache
  297. this.connStatusFromJvb = {};
  298. }
  299. /**
  300. * Handles RTCEvents.ENDPOINT_CONN_STATUS_CHANGED triggered when we receive
  301. * notification over the data channel from the bridge about endpoint's
  302. * connection status update.
  303. * @param {string} endpointId the endpoint ID(MUC nickname/resource JID)
  304. * @param {boolean} isActive true if the connection is OK or false otherwise
  305. */
  306. onEndpointConnStatusChanged(endpointId, isActive) {
  307. logger.debug(
  308. `Detector RTCEvents.ENDPOINT_CONN_STATUS_CHANGED(${Date.now()}): ${
  309. endpointId}: ${isActive}`);
  310. // Filter out events for the local JID for now
  311. if (endpointId !== this.conference.myUserId()) {
  312. // Store the status received over the data channels
  313. this.connStatusFromJvb[endpointId] = isActive;
  314. this.figureOutConnectionStatus(endpointId);
  315. }
  316. }
  317. /**
  318. * Changes connection status.
  319. * @param {JitsiParticipant} participant
  320. * @param newStatus
  321. */
  322. _changeConnectionStatus(participant, newStatus) {
  323. if (participant.getConnectionStatus() !== newStatus) {
  324. const endpointId = participant.getId();
  325. participant._setConnectionStatus(newStatus);
  326. logger.debug(
  327. `Emit endpoint conn status(${Date.now()}) ${endpointId}: ${
  328. newStatus}`);
  329. // Log the event on CallStats
  330. Statistics.sendLog(
  331. JSON.stringify({
  332. id: 'peer.conn.status',
  333. participant: endpointId,
  334. status: newStatus
  335. }));
  336. this.conference.eventEmitter.emit(
  337. JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,
  338. endpointId, newStatus);
  339. }
  340. }
  341. /**
  342. * Reset the postponed "connection interrupted" event which was previously
  343. * scheduled as a timeout on RTC 'onmute' event.
  344. *
  345. * @param {string} participantId the participant for which the "connection
  346. * interrupted" timeout was scheduled
  347. */
  348. clearTimeout(participantId) {
  349. if (this.trackTimers[participantId]) {
  350. window.clearTimeout(this.trackTimers[participantId]);
  351. this.trackTimers[participantId] = null;
  352. }
  353. }
  354. /**
  355. * Clears the timestamp of the RTC muted event for participant's video track
  356. * @param {string} participantId the id of the conference participant which
  357. * is the same as the Colibri endpoint ID of the video channel allocated for
  358. * the user on the videobridge.
  359. */
  360. clearRtcMutedTimestamp(participantId) {
  361. this.rtcMutedTimestamp[participantId] = null;
  362. }
  363. /**
  364. * Bind signalling mute event listeners for video {JitsiRemoteTrack} when
  365. * a new one is added to the conference.
  366. *
  367. * @param {JitsiTrack} remoteTrack the {JitsiTrack} which is being added to
  368. * the conference.
  369. */
  370. onRemoteTrackAdded(remoteTrack) {
  371. if (!remoteTrack.isLocal()
  372. && remoteTrack.getType() === MediaType.VIDEO) {
  373. logger.debug(
  374. `Detector on remote track added for: ${
  375. remoteTrack.getParticipantId()}`);
  376. remoteTrack.on(
  377. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  378. this._onSignallingMuteChanged);
  379. }
  380. }
  381. /**
  382. * Removes all event listeners bound to the remote video track and clears
  383. * any related timeouts.
  384. *
  385. * @param {JitsiRemoteTrack} remoteTrack the remote track which is being
  386. * removed from the conference.
  387. */
  388. onRemoteTrackRemoved(remoteTrack) {
  389. if (!remoteTrack.isLocal()
  390. && remoteTrack.getType() === MediaType.VIDEO) {
  391. const endpointId = remoteTrack.getParticipantId();
  392. logger.debug(`Detector on remote track removed: ${endpointId}`);
  393. remoteTrack.off(
  394. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  395. this._onSignallingMuteChanged);
  396. this.clearTimeout(endpointId);
  397. this.clearRtcMutedTimestamp(endpointId);
  398. this.figureOutConnectionStatus(endpointId);
  399. }
  400. }
  401. /**
  402. * Checks if given participant's video is considered frozen.
  403. * @param {JitsiParticipant} participant
  404. * @return {boolean} <tt>true</tt> if the video has frozen for given
  405. * participant or <tt>false</tt> when it's either not considered frozen
  406. * (yet) or if freeze detection is not supported by the current browser.
  407. *
  408. * FIXME merge this logic with NO_DATA_FROM_SOURCE event
  409. * implemented in JitsiLocalTrack by extending the event to
  410. * the remote track and allowing to set different timeout for
  411. * local and remote tracks.
  412. *
  413. */
  414. isVideoTrackFrozen(participant) {
  415. if (!RTCBrowserType.isVideoMuteOnConnInterruptedSupported()) {
  416. return false;
  417. }
  418. const hasAnyVideoRTCMuted = participant.hasAnyVideoTrackWebRTCMuted();
  419. const rtcMutedTimestamp
  420. = this.rtcMutedTimestamp[participant.getId()];
  421. return hasAnyVideoRTCMuted
  422. && typeof rtcMutedTimestamp === 'number'
  423. && (Date.now() - rtcMutedTimestamp) >= this.rtcMuteTimeout;
  424. }
  425. /**
  426. * Goes over every participant and updates connectivity status.
  427. * Should be called when a parameter which affects all of the participants
  428. * is changed (P2P for example).
  429. */
  430. refreshConnectionStatusForAll() {
  431. const participants = this.conference.getParticipants();
  432. for (const participant of participants) {
  433. this.figureOutConnectionStatus(participant.getId());
  434. }
  435. }
  436. /**
  437. * Figures out (and updates) the current connectivity status for
  438. * the participant identified by the given id.
  439. *
  440. * @param {string} id the participant's id (MUC nickname or Colibri endpoint
  441. * ID).
  442. */
  443. figureOutConnectionStatus(id) {
  444. const participant = this.conference.getParticipantById(id);
  445. if (!participant) {
  446. // Probably the participant is no longer in the conference
  447. // (at the time of writing this code, participant is
  448. // detached from the conference and TRACK_REMOVED events are
  449. // fired),
  450. // so we don't care, but let's print the warning for
  451. // debugging purpose
  452. logger.warn(`figure out conn status - no participant for: ${id}`);
  453. return;
  454. }
  455. const inP2PMode = this.conference.isP2PActive();
  456. const isRestoringTimedOut = this._isRestoringTimedout(id);
  457. const isVideoMuted = participant.isVideoMuted();
  458. const isVideoTrackFrozen = this.isVideoTrackFrozen(participant);
  459. const isInLastN = this.rtc.isInLastN(id);
  460. let isConnActiveByJvb = this.connStatusFromJvb[id];
  461. if (typeof isConnActiveByJvb !== 'boolean') {
  462. // If no status was received from the JVB it means that it's active
  463. // (the bridge does not send notification unless there is a problem)
  464. logger.debug('Assuming connection active by JVB - no notification');
  465. isConnActiveByJvb = true;
  466. }
  467. const newState
  468. = inP2PMode
  469. ? ParticipantConnectionStatusHandler._getNewStateForP2PMode(
  470. isVideoMuted,
  471. isVideoTrackFrozen)
  472. : ParticipantConnectionStatusHandler._getNewStateForJvbMode(
  473. isConnActiveByJvb,
  474. isInLastN,
  475. isRestoringTimedOut,
  476. isVideoMuted,
  477. isVideoTrackFrozen);
  478. // if the new state is not restoring clear timers and timestamps
  479. // that we use to track the restoring state
  480. if (newState !== ParticipantConnectionStatus.RESTORING) {
  481. this._clearRestoringTimer(id);
  482. }
  483. logger.debug(
  484. `Figure out conn status for ${id}, is video muted: ${isVideoMuted
  485. } is active(jvb): ${isConnActiveByJvb
  486. } video track frozen: ${isVideoTrackFrozen
  487. } p2p mode: ${inP2PMode
  488. } is in last N: ${isInLastN
  489. } currentStatus => newStatus:
  490. ${participant.getConnectionStatus()} => ${newState}`);
  491. this._changeConnectionStatus(participant, newState);
  492. }
  493. /**
  494. * On change in Last N set check all leaving and entering participants to
  495. * change their corresponding statuses.
  496. *
  497. * @param {Array<string>} leavingLastN array of ids leaving lastN.
  498. * @param {Array<string>} enteringLastN array of ids entering lastN.
  499. * @private
  500. */
  501. _onLastNChanged(leavingLastN = [], enteringLastN = []) {
  502. for (const id of leavingLastN) {
  503. this.enteredLastNTimestamp.delete(id);
  504. this._clearRestoringTimer(id);
  505. this.figureOutConnectionStatus(id);
  506. }
  507. for (const id of enteringLastN) {
  508. // store the timestamp this id is entering lastN
  509. this.enteredLastNTimestamp.set(id, Date.now());
  510. this.figureOutConnectionStatus(id);
  511. }
  512. }
  513. /**
  514. * Clears the restoring timer for participant's video track and the
  515. * timestamp for entering lastN.
  516. *
  517. * @param {string} participantId the id of the conference participant which
  518. * is the same as the Colibri endpoint ID of the video channel allocated for
  519. * the user on the videobridge.
  520. */
  521. _clearRestoringTimer(participantId) {
  522. const rTimer = this.restoringTimers.get(participantId);
  523. if (rTimer) {
  524. clearTimeout(rTimer);
  525. this.restoringTimers.delete(participantId);
  526. }
  527. }
  528. /**
  529. * Checks whether a track had stayed enough in restoring state, compares
  530. * current time and the time the track entered in lastN. If it hasn't
  531. * timedout and there is no timer added, add new timer in order to give it
  532. * more time to become active or mark it as interrupted on next check.
  533. *
  534. * @param {string} participantId the id of the conference participant which
  535. * is the same as the Colibri endpoint ID of the video channel allocated for
  536. * the user on the videobridge.
  537. * @returns {boolean} <tt>true</tt> if the track was in restoring state
  538. * more than the timeout ({@link DEFAULT_RESTORING_TIMEOUT}.) in order to
  539. * set its status to interrupted.
  540. * @private
  541. */
  542. _isRestoringTimedout(participantId) {
  543. const enteredLastNTimestamp
  544. = this.enteredLastNTimestamp.get(participantId);
  545. if (enteredLastNTimestamp
  546. && (Date.now() - enteredLastNTimestamp)
  547. >= DEFAULT_RESTORING_TIMEOUT) {
  548. return true;
  549. }
  550. // still haven't reached timeout, if there is no timer scheduled,
  551. // schedule one so we can track the restoring state and change it after
  552. // reaching the timeout
  553. const rTimer = this.restoringTimers.get(participantId);
  554. if (!rTimer) {
  555. this.restoringTimers.set(participantId, setTimeout(
  556. () => this.figureOutConnectionStatus(participantId),
  557. DEFAULT_RESTORING_TIMEOUT));
  558. }
  559. return false;
  560. }
  561. /**
  562. * Handles RTC 'onmute' event for the video track.
  563. *
  564. * @param {JitsiRemoteTrack} track the video track for which 'onmute' event
  565. * will be processed.
  566. */
  567. onTrackRtcMuted(track) {
  568. const participantId = track.getParticipantId();
  569. const participant = this.conference.getParticipantById(participantId);
  570. logger.debug(`Detector track RTC muted: ${participantId}`);
  571. if (!participant) {
  572. logger.error(`No participant for id: ${participantId}`);
  573. return;
  574. }
  575. this.rtcMutedTimestamp[participantId] = Date.now();
  576. if (!participant.isVideoMuted()) {
  577. // If the user is not muted according to the signalling we'll give
  578. // it some time, before the connection interrupted event is
  579. // triggered.
  580. this.clearTimeout(participantId);
  581. this.trackTimers[participantId] = window.setTimeout(() => {
  582. logger.debug(`RTC mute timeout for: ${participantId}`);
  583. this.clearTimeout(participantId);
  584. this.figureOutConnectionStatus(participantId);
  585. }, this.rtcMuteTimeout);
  586. }
  587. }
  588. /**
  589. * Handles RTC 'onunmute' event for the video track.
  590. *
  591. * @param {JitsiRemoteTrack} track the video track for which 'onunmute'
  592. * event will be processed.
  593. */
  594. onTrackRtcUnmuted(track) {
  595. const participantId = track.getParticipantId();
  596. logger.debug(`Detector track RTC unmuted: ${participantId}`);
  597. this.clearTimeout(participantId);
  598. this.clearRtcMutedTimestamp(participantId);
  599. this.figureOutConnectionStatus(participantId);
  600. }
  601. /**
  602. * Here the signalling "mute"/"unmute" events are processed.
  603. *
  604. * @param {JitsiRemoteTrack} track the remote video track for which
  605. * the signalling mute/unmute event will be processed.
  606. */
  607. onSignallingMuteChanged(track) {
  608. const participantId = track.getParticipantId();
  609. logger.debug(
  610. `Detector on track signalling mute changed: ${participantId}`,
  611. track.isMuted());
  612. this.figureOutConnectionStatus(participantId);
  613. }
  614. }