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

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