modified lib-jitsi-meet dev repo
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

JitsiLocalTrack.js 21KB

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