Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

JitsiLocalTrack.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /* global __filename, Promise */
  2. import CameraFacingMode from '../../service/RTC/CameraFacingMode';
  3. import { getLogger } from 'jitsi-meet-logger';
  4. import JitsiTrack from './JitsiTrack';
  5. import JitsiTrackError from '../../JitsiTrackError';
  6. import * as JitsiTrackErrors from '../../JitsiTrackErrors';
  7. import * as JitsiTrackEvents from '../../JitsiTrackEvents';
  8. import * as MediaType from '../../service/RTC/MediaType';
  9. import RTCBrowserType from './RTCBrowserType';
  10. import RTCEvents from '../../service/RTC/RTCEvents';
  11. import RTCUtils from './RTCUtils';
  12. import Statistics from '../statistics/statistics';
  13. import VideoType from '../../service/RTC/VideoType';
  14. const logger = getLogger(__filename);
  15. /* eslint-disable max-params */
  16. /**
  17. * Represents a single media track(either audio or video).
  18. * One <tt>JitsiLocalTrack</tt> corresponds to one WebRTC MediaStreamTrack.
  19. * @param stream WebRTC MediaStream, parent of the track
  20. * @param track underlying WebRTC MediaStreamTrack for new JitsiRemoteTrack
  21. * @param mediaType the MediaType of the JitsiRemoteTrack
  22. * @param videoType the VideoType of the JitsiRemoteTrack
  23. * @param resolution the video resolution if it's a video track
  24. * @param deviceId the ID of the local device for this track
  25. * @param facingMode the camera facing mode used in getUserMedia call
  26. * @constructor
  27. */
  28. function JitsiLocalTrack(
  29. stream,
  30. track,
  31. mediaType,
  32. videoType,
  33. resolution,
  34. deviceId,
  35. facingMode) {
  36. JitsiTrack.call(
  37. this,
  38. null /* RTC */,
  39. stream,
  40. track,
  41. () => {
  42. if (!this.dontFireRemoveEvent) {
  43. this.eventEmitter.emit(JitsiTrackEvents.LOCAL_TRACK_STOPPED);
  44. }
  45. this.dontFireRemoveEvent = false;
  46. } /* inactiveHandler */,
  47. mediaType,
  48. videoType,
  49. null /* ssrc */);
  50. this.dontFireRemoveEvent = false;
  51. this.resolution = resolution;
  52. // FIXME: currently firefox is ignoring our constraints about resolutions
  53. // so we do not store it, to avoid wrong reporting of local track resolution
  54. if (RTCBrowserType.isFirefox()) {
  55. this.resolution = null;
  56. }
  57. this.deviceId = deviceId;
  58. this.startMuted = false;
  59. this.initialMSID = this.getMSID();
  60. this.inMuteOrUnmuteProgress = false;
  61. /**
  62. * The facing mode of the camera from which this JitsiLocalTrack instance
  63. * was obtained.
  64. */
  65. this._facingMode = facingMode;
  66. // Currently there is no way to know the MediaStreamTrack ended due to to
  67. // device disconnect in Firefox through e.g. "readyState" property. Instead
  68. // we will compare current track's label with device labels from
  69. // enumerateDevices() list.
  70. this._trackEnded = false;
  71. /**
  72. * The value of bytes sent received from the statistics module.
  73. */
  74. this._bytesSent = null;
  75. /**
  76. * Used only for detection of audio problems. We want to check only once
  77. * whether the track is sending bytes ot not. This flag is set to false
  78. * after the check.
  79. */
  80. this._testByteSent = true;
  81. // Currently there is no way to determine with what device track was
  82. // created (until getConstraints() support), however we can associate tracks
  83. // with real devices obtained from enumerateDevices() call as soon as it's
  84. // called.
  85. this._realDeviceId = this.deviceId === '' ? undefined : this.deviceId;
  86. /**
  87. * Indicates that we have called RTCUtils.stopMediaStream for the
  88. * MediaStream related to this JitsiTrack object.
  89. */
  90. this.stopStreamInProgress = false;
  91. /**
  92. * On mute event we are waiting for 3s to check if the stream is going to
  93. * be still muted before firing the event for camera issue detected
  94. * (NO_DATA_FROM_SOURCE).
  95. */
  96. this._noDataFromSourceTimeout = null;
  97. this._onDeviceListChanged = devices => {
  98. this._setRealDeviceIdFromDeviceList(devices);
  99. // Mark track as ended for those browsers that do not support
  100. // "readyState" property. We do not touch tracks created with default
  101. // device ID "".
  102. if (typeof this.getTrack().readyState === 'undefined'
  103. && typeof this._realDeviceId !== 'undefined'
  104. && !devices.find(d => d.deviceId === this._realDeviceId)) {
  105. this._trackEnded = true;
  106. }
  107. };
  108. // Subscribe each created local audio track to
  109. // RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED event. This is different from
  110. // handling this event for remote tracks (which are handled in RTC.js),
  111. // because there might be local tracks not attached to a conference.
  112. if (this.isAudioTrack() && RTCUtils.isDeviceChangeAvailable('output')) {
  113. this._onAudioOutputDeviceChanged = this.setAudioOutput.bind(this);
  114. RTCUtils.addListener(
  115. RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  116. this._onAudioOutputDeviceChanged);
  117. }
  118. RTCUtils.addListener(
  119. RTCEvents.DEVICE_LIST_CHANGED,
  120. this._onDeviceListChanged);
  121. this._initNoDataFromSourceHandlers();
  122. }
  123. /* eslint-enable max-params */
  124. JitsiLocalTrack.prototype = Object.create(JitsiTrack.prototype);
  125. JitsiLocalTrack.prototype.constructor = JitsiLocalTrack;
  126. /**
  127. * Returns if associated MediaStreamTrack is in the 'ended' state
  128. * @returns {boolean}
  129. */
  130. JitsiLocalTrack.prototype.isEnded = function() {
  131. return this.getTrack().readyState === 'ended' || this._trackEnded;
  132. };
  133. /**
  134. * Sets handlers to the MediaStreamTrack object that will detect camera issues.
  135. */
  136. JitsiLocalTrack.prototype._initNoDataFromSourceHandlers = function() {
  137. if (this.isVideoTrack() && this.videoType === VideoType.CAMERA) {
  138. const _onNoDataFromSourceError
  139. = this._onNoDataFromSourceError.bind(this);
  140. this._setHandler('track_mute', () => {
  141. if (this._checkForCameraIssues()) {
  142. const now = window.performance.now();
  143. this._noDataFromSourceTimeout
  144. = setTimeout(_onNoDataFromSourceError, 3000);
  145. this._setHandler('track_unmute', () => {
  146. this._clearNoDataFromSourceMuteResources();
  147. Statistics.sendEventToAll(
  148. `${this.getType()}.track_unmute`,
  149. { value: window.performance.now() - now });
  150. });
  151. }
  152. });
  153. this._setHandler('track_ended', _onNoDataFromSourceError);
  154. }
  155. };
  156. /**
  157. * Clears all timeouts and handlers set on MediaStreamTrack mute event.
  158. * FIXME: Change the name of the method with better one.
  159. */
  160. JitsiLocalTrack.prototype._clearNoDataFromSourceMuteResources = function() {
  161. if (this._noDataFromSourceTimeout) {
  162. clearTimeout(this._noDataFromSourceTimeout);
  163. this._noDataFromSourceTimeout = null;
  164. }
  165. this._setHandler('track_unmute', undefined);
  166. };
  167. /**
  168. * Called when potential camera issue is detected. Clears the handlers and
  169. * timeouts set on MediaStreamTrack muted event. Verifies that the camera
  170. * issue persists and fires NO_DATA_FROM_SOURCE event.
  171. */
  172. JitsiLocalTrack.prototype._onNoDataFromSourceError = function() {
  173. this._clearNoDataFromSourceMuteResources();
  174. if (this._checkForCameraIssues()) {
  175. this._fireNoDataFromSourceEvent();
  176. }
  177. };
  178. /**
  179. * Fires JitsiTrackEvents.NO_DATA_FROM_SOURCE and logs it to analytics and
  180. * callstats.
  181. */
  182. JitsiLocalTrack.prototype._fireNoDataFromSourceEvent = function() {
  183. this.eventEmitter.emit(JitsiTrackEvents.NO_DATA_FROM_SOURCE);
  184. const eventName = `${this.getType()}.no_data_from_source`;
  185. Statistics.analytics.sendEvent(eventName);
  186. const log = { name: eventName };
  187. if (this.isAudioTrack()) {
  188. log.isReceivingData = this._isReceivingData();
  189. }
  190. Statistics.sendLog(JSON.stringify(log));
  191. };
  192. /**
  193. * Sets real device ID by comparing track information with device information.
  194. * This is temporary solution until getConstraints() method will be implemented
  195. * in browsers.
  196. * @param {MediaDeviceInfo[]} devices - list of devices obtained from
  197. * enumerateDevices() call
  198. */
  199. JitsiLocalTrack.prototype._setRealDeviceIdFromDeviceList = function(devices) {
  200. const track = this.getTrack();
  201. const device
  202. = devices.find(
  203. d => d.kind === `${track.kind}input` && d.label === track.label);
  204. if (device) {
  205. this._realDeviceId = device.deviceId;
  206. }
  207. };
  208. /**
  209. * Mutes the track. Will reject the Promise if there is mute/unmute operation
  210. * in progress.
  211. * @returns {Promise}
  212. */
  213. JitsiLocalTrack.prototype.mute = function() {
  214. return createMuteUnmutePromise(this, true);
  215. };
  216. /**
  217. * Unmutes the track. Will reject the Promise if there is mute/unmute operation
  218. * in progress.
  219. * @returns {Promise}
  220. */
  221. JitsiLocalTrack.prototype.unmute = function() {
  222. return createMuteUnmutePromise(this, false);
  223. };
  224. /**
  225. * Creates Promise for mute/unmute operation.
  226. *
  227. * @param {JitsiLocalTrack} track - The track that will be muted/unmuted.
  228. * @param {boolean} mute - Whether to mute or unmute the track.
  229. * @returns {Promise}
  230. */
  231. function createMuteUnmutePromise(track, mute) {
  232. if (track.inMuteOrUnmuteProgress) {
  233. return Promise.reject(
  234. new JitsiTrackError(JitsiTrackErrors.TRACK_MUTE_UNMUTE_IN_PROGRESS)
  235. );
  236. }
  237. track.inMuteOrUnmuteProgress = true;
  238. return track._setMute(mute)
  239. .then(() => {
  240. track.inMuteOrUnmuteProgress = false;
  241. })
  242. .catch(status => {
  243. track.inMuteOrUnmuteProgress = false;
  244. throw status;
  245. });
  246. }
  247. /**
  248. * Mutes / unmutes the track.
  249. *
  250. * @param {boolean} mute - If true the track will be muted. Otherwise the track
  251. * will be unmuted.
  252. * @private
  253. * @returns {Promise}
  254. */
  255. JitsiLocalTrack.prototype._setMute = function(mute) {
  256. if (this.isMuted() === mute) {
  257. return Promise.resolve();
  258. }
  259. let promise = Promise.resolve();
  260. const self = this;
  261. // Local track can be used out of conference, so we need to handle that
  262. // case and mark that track should start muted or not when added to
  263. // conference.
  264. if (!this.conference || !this.conference.room) {
  265. this.startMuted = mute;
  266. }
  267. this.dontFireRemoveEvent = false;
  268. // FIXME FF does not support 'removeStream' method used to mute
  269. if (this.isAudioTrack()
  270. || this.videoType === VideoType.DESKTOP
  271. || RTCBrowserType.isFirefox()) {
  272. if (this.track) {
  273. this.track.enabled = !mute;
  274. }
  275. } else if (mute) {
  276. this.dontFireRemoveEvent = true;
  277. promise = new Promise((resolve, reject) => {
  278. this._removeStreamFromConferenceAsMute(() => {
  279. // FIXME: Maybe here we should set the SRC for the containers
  280. // to something
  281. this._stopMediaStream();
  282. this._setStream(null);
  283. resolve();
  284. }, err => {
  285. reject(err);
  286. });
  287. });
  288. } else {
  289. // This path is only for camera.
  290. const streamOptions = {
  291. cameraDeviceId: this.getDeviceId(),
  292. devices: [ MediaType.VIDEO ],
  293. facingMode: this.getCameraFacingMode()
  294. };
  295. if (this.resolution) {
  296. streamOptions.resolution = this.resolution;
  297. }
  298. promise = RTCUtils.obtainAudioAndVideoPermissions(streamOptions)
  299. .then(streamsInfo => {
  300. const mediaType = self.getType();
  301. const streamInfo
  302. = streamsInfo.find(info => info.mediaType === mediaType);
  303. if (streamInfo) {
  304. self._setStream(streamInfo.stream);
  305. self.track = streamInfo.track;
  306. // This is not good when video type changes after
  307. // unmute, but let's not crash here
  308. if (self.videoType !== streamInfo.videoType) {
  309. logger.warn(
  310. 'Video type has changed after unmute!',
  311. self.videoType, streamInfo.videoType);
  312. self.videoType = streamInfo.videoType;
  313. }
  314. } else {
  315. throw new JitsiTrackError(
  316. JitsiTrackErrors.TRACK_NO_STREAM_FOUND);
  317. }
  318. self.containers
  319. = self.containers.map(
  320. cont => RTCUtils.attachMediaStream(cont, self.stream));
  321. return self._addStreamToConferenceAsUnmute();
  322. });
  323. }
  324. return promise
  325. .then(() => self._sendMuteStatus(mute))
  326. .then(function() {
  327. self.eventEmitter.emit(JitsiTrackEvents.TRACK_MUTE_CHANGED, this);
  328. });
  329. };
  330. /**
  331. * Adds stream to conference and marks it as "unmute" operation.
  332. *
  333. * @private
  334. * @returns {Promise}
  335. */
  336. JitsiLocalTrack.prototype._addStreamToConferenceAsUnmute = function() {
  337. if (!this.conference) {
  338. return Promise.resolve();
  339. }
  340. return new Promise((resolve, reject) => {
  341. this.conference._addLocalStream(
  342. this.stream,
  343. resolve,
  344. error => reject(new Error(error)),
  345. {
  346. mtype: this.type,
  347. type: 'unmute',
  348. ssrcs: this.ssrc && this.ssrc.ssrcs,
  349. groups: this.ssrc && this.ssrc.groups,
  350. msid: this.getMSID()
  351. });
  352. });
  353. };
  354. /**
  355. * Removes stream from conference and marks it as "mute" operation.
  356. * @param {Function} successCallback will be called on success
  357. * @param {Function} errorCallback will be called on error
  358. * @private
  359. */
  360. JitsiLocalTrack.prototype._removeStreamFromConferenceAsMute
  361. = function(successCallback, errorCallback) {
  362. if (!this.conference) {
  363. successCallback();
  364. return;
  365. }
  366. this.conference.removeLocalStream(
  367. this.stream,
  368. successCallback,
  369. error => errorCallback(new Error(error)),
  370. {
  371. mtype: this.type,
  372. type: 'mute',
  373. ssrcs: this.ssrc && this.ssrc.ssrcs,
  374. groups: this.ssrc && this.ssrc.groups
  375. });
  376. };
  377. /**
  378. * Sends mute status for a track to conference if any.
  379. *
  380. * @param {boolean} mute - If track is muted.
  381. * @private
  382. * @returns {Promise}
  383. */
  384. JitsiLocalTrack.prototype._sendMuteStatus = function(mute) {
  385. if (!this.conference || !this.conference.room) {
  386. return Promise.resolve();
  387. }
  388. return new Promise(resolve => {
  389. this.conference.room[
  390. this.isAudioTrack()
  391. ? 'setAudioMute'
  392. : 'setVideoMute'](mute, resolve);
  393. });
  394. };
  395. /**
  396. * @inheritdoc
  397. *
  398. * Stops sending the media track. And removes it from the HTML.
  399. * NOTE: Works for local tracks only.
  400. *
  401. * @extends JitsiTrack#dispose
  402. * @returns {Promise}
  403. */
  404. JitsiLocalTrack.prototype.dispose = function() {
  405. const self = this;
  406. let promise = Promise.resolve();
  407. if (this.conference) {
  408. promise = this.conference.removeTrack(this);
  409. }
  410. if (this.stream) {
  411. this._stopMediaStream();
  412. this.detach();
  413. }
  414. RTCUtils.removeListener(RTCEvents.DEVICE_LIST_CHANGED,
  415. this._onDeviceListChanged);
  416. if (this._onAudioOutputDeviceChanged) {
  417. RTCUtils.removeListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  418. this._onAudioOutputDeviceChanged);
  419. }
  420. return promise
  421. .then(() => JitsiTrack.prototype.dispose.call(self) // super.dispose();
  422. );
  423. };
  424. /**
  425. * Returns <tt>true</tt> - if the stream is muted
  426. * and <tt>false</tt> otherwise.
  427. * @returns {boolean} <tt>true</tt> - if the stream is muted
  428. * and <tt>false</tt> otherwise.
  429. */
  430. JitsiLocalTrack.prototype.isMuted = function() {
  431. // this.stream will be null when we mute local video on Chrome
  432. if (!this.stream) {
  433. return true;
  434. }
  435. if (this.isVideoTrack() && !this.isActive()) {
  436. return true;
  437. }
  438. return !this.track || !this.track.enabled;
  439. };
  440. /**
  441. * Updates the SSRC associated with the MediaStream in JitsiLocalTrack object.
  442. * @ssrc the new ssrc
  443. */
  444. JitsiLocalTrack.prototype._setSSRC = function(ssrc) {
  445. this.ssrc = ssrc;
  446. };
  447. /**
  448. * Sets the JitsiConference object associated with the track. This is temp
  449. * solution.
  450. * @param conference the JitsiConference object
  451. */
  452. JitsiLocalTrack.prototype._setConference = function(conference) {
  453. this.conference = conference;
  454. // We want to keep up with postponed events which should have been fired
  455. // on "attach" call, but for local track we not always have the conference
  456. // before attaching. However this may result in duplicated events if they
  457. // have been triggered on "attach" already.
  458. for (let i = 0; i < this.containers.length; i++) {
  459. this._maybeFireTrackAttached(this.containers[i]);
  460. }
  461. };
  462. /**
  463. * Gets the SSRC of this local track if it's available already or <tt>null</tt>
  464. * otherwise. That's because we don't know the SSRC until local description is
  465. * created.
  466. * In case of video and simulcast returns the the primarySSRC.
  467. * @returns {string} or {null}
  468. */
  469. JitsiLocalTrack.prototype.getSSRC = function() {
  470. if (this.ssrc && this.ssrc.groups && this.ssrc.groups.length) {
  471. return this.ssrc.groups[0].ssrcs[0];
  472. } else if (this.ssrc && this.ssrc.ssrcs && this.ssrc.ssrcs.length) {
  473. return this.ssrc.ssrcs[0];
  474. }
  475. return null;
  476. };
  477. /**
  478. * Returns <tt>true</tt>.
  479. * @returns {boolean} <tt>true</tt>
  480. */
  481. JitsiLocalTrack.prototype.isLocal = function() {
  482. return true;
  483. };
  484. /**
  485. * Returns device id associated with track.
  486. * @returns {string}
  487. */
  488. JitsiLocalTrack.prototype.getDeviceId = function() {
  489. return this._realDeviceId || this.deviceId;
  490. };
  491. /**
  492. * Sets the value of bytes sent statistic.
  493. * @param bytesSent {integer} the new value (FIXME: what is an integer in js?)
  494. * NOTE: used only for audio tracks to detect audio issues.
  495. */
  496. JitsiLocalTrack.prototype._setByteSent = function(bytesSent) {
  497. this._bytesSent = bytesSent;
  498. // FIXME it's a shame that PeerConnection and ICE status does not belong
  499. // to the RTC module and it has to be accessed through
  500. // the conference(and through the XMPP chat room ???) instead
  501. const iceConnectionState
  502. = this.conference ? this.conference.getConnectionState() : null;
  503. if (this._testByteSent && iceConnectionState === 'connected') {
  504. setTimeout(() => {
  505. if (this._bytesSent <= 0) {
  506. // we are not receiving anything from the microphone
  507. this._fireNoDataFromSourceEvent();
  508. }
  509. }, 3000);
  510. this._testByteSent = false;
  511. }
  512. };
  513. /**
  514. * Returns facing mode for video track from camera. For other cases (e.g. audio
  515. * track or 'desktop' video track) returns undefined.
  516. *
  517. * @returns {CameraFacingMode|undefined}
  518. */
  519. JitsiLocalTrack.prototype.getCameraFacingMode = function() {
  520. if (this.isVideoTrack() && this.videoType === VideoType.CAMERA) {
  521. // MediaStreamTrack#getSettings() is not implemented in many browsers,
  522. // so we need feature checking here. Progress on the respective
  523. // browser's implementation can be tracked at
  524. // https://bugs.chromium.org/p/webrtc/issues/detail?id=2481 for Chromium
  525. // and https://bugzilla.mozilla.org/show_bug.cgi?id=1213517 for Firefox.
  526. // Even if a browser implements getSettings() already, it might still
  527. // not return anything for 'facingMode'.
  528. let trackSettings;
  529. try {
  530. trackSettings = this.track.getSettings();
  531. } catch (e) {
  532. // XXX React-native-webrtc, for example, defines
  533. // MediaStreamTrack#getSettings() but the implementation throws a
  534. // "Not implemented" Error.
  535. }
  536. if (trackSettings && 'facingMode' in trackSettings) {
  537. return trackSettings.facingMode;
  538. }
  539. if (typeof this._facingMode !== 'undefined') {
  540. return this._facingMode;
  541. }
  542. // In most cases we are showing a webcam. So if we've gotten here, it
  543. // should be relatively safe to assume that we are probably showing
  544. // the user-facing camera.
  545. return CameraFacingMode.USER;
  546. }
  547. return undefined;
  548. };
  549. /**
  550. * Stops the associated MediaStream.
  551. */
  552. JitsiLocalTrack.prototype._stopMediaStream = function() {
  553. this.stopStreamInProgress = true;
  554. RTCUtils.stopMediaStream(this.stream);
  555. this.stopStreamInProgress = false;
  556. };
  557. /**
  558. * Detects camera issues on ended and mute events from MediaStreamTrack.
  559. * @returns {boolean} true if an issue is detected and false otherwise
  560. */
  561. JitsiLocalTrack.prototype._checkForCameraIssues = function() {
  562. if (!this.isVideoTrack() || this.stopStreamInProgress
  563. || this.videoType === VideoType.DESKTOP) {
  564. return false;
  565. }
  566. return !this._isReceivingData();
  567. };
  568. /**
  569. * Checks whether the attached MediaStream is receiving data from source or
  570. * not. If the stream property is null(because of mute or another reason) this
  571. * method will return false.
  572. * NOTE: This method doesn't indicate problem with the streams directly.
  573. * For example in case of video mute the method will return false or if the
  574. * user has disposed the track.
  575. * @returns {boolean} true if the stream is receiving data and false otherwise.
  576. */
  577. JitsiLocalTrack.prototype._isReceivingData = function() {
  578. if (!this.stream) {
  579. return false;
  580. }
  581. // In older version of the spec there is no muted property and
  582. // readyState can have value muted. In the latest versions
  583. // readyState can have values "live" and "ended" and there is
  584. // muted boolean property. If the stream is muted that means that
  585. // we aren't receiving any data from the source. We want to notify
  586. // the users for error if the stream is muted or ended on it's
  587. // creation.
  588. return this.stream.getTracks().some(track =>
  589. (!('readyState' in track) || track.readyState === 'live')
  590. && (!('muted' in track) || track.muted !== true));
  591. };
  592. module.exports = JitsiLocalTrack;