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 23KB

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