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

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