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.

JitsiLocalTrack.js 22KB

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