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.

ConnectionStatsTable.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../base/i18n';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link ConnectionStatsTable}.
  7. */
  8. type Props = {
  9. /**
  10. * The audio SSRC of this client.
  11. */
  12. audioSsrc: number,
  13. /**
  14. * Statistics related to bandwidth.
  15. * {{
  16. * download: Number,
  17. * upload: Number
  18. * }}
  19. */
  20. bandwidth: Object,
  21. /**
  22. * Statistics related to bitrate.
  23. * {{
  24. * download: Number,
  25. * upload: Number
  26. * }}
  27. */
  28. bitrate: Object,
  29. /**
  30. * The number of bridges (aka media servers) currently used in the
  31. * conference.
  32. */
  33. bridgeCount: number,
  34. /**
  35. * Audio/video codecs in use for the connection.
  36. */
  37. codec: Object,
  38. /**
  39. * A message describing the connection quality.
  40. */
  41. connectionSummary: string,
  42. /**
  43. * The end-to-end round-trip-time.
  44. */
  45. e2eRtt: number,
  46. /**
  47. * Whether or not should display the "Save Logs" link.
  48. */
  49. enableSaveLogs: boolean,
  50. /**
  51. * The endpoint id of this client.
  52. */
  53. participantId: string,
  54. /**
  55. * Statistics related to frame rates for each ssrc.
  56. * {{
  57. * [ ssrc ]: Number
  58. * }}
  59. */
  60. framerate: Object,
  61. /**
  62. * Whether or not the statistics are for local video.
  63. */
  64. isLocalVideo: boolean,
  65. /**
  66. * The send-side max enabled resolution (aka the highest layer that is not
  67. * suspended on the send-side).
  68. */
  69. maxEnabledResolution: number,
  70. /**
  71. * Callback to invoke when the user clicks on the download logs link.
  72. */
  73. onSaveLogs: Function,
  74. /**
  75. * Callback to invoke when the show additional stats link is clicked.
  76. */
  77. onShowMore: Function,
  78. /**
  79. * Statistics related to packet loss.
  80. * {{
  81. * download: Number,
  82. * upload: Number
  83. * }}
  84. */
  85. packetLoss: Object,
  86. /**
  87. * The region that we think the client is in.
  88. */
  89. region: string,
  90. /**
  91. * Statistics related to display resolutions for each ssrc.
  92. * {{
  93. * [ ssrc ]: {
  94. * height: Number,
  95. * width: Number
  96. * }
  97. * }}
  98. */
  99. resolution: Object,
  100. /**
  101. * The region of the media server that we are connected to.
  102. */
  103. serverRegion: string,
  104. /**
  105. * Whether or not additional stats about bandwidth and transport should be
  106. * displayed. Will not display even if true for remote participants.
  107. */
  108. shouldShowMore: boolean,
  109. /**
  110. * Invoked to obtain translated strings.
  111. */
  112. t: Function,
  113. /**
  114. * The video SSRC of this client.
  115. */
  116. videoSsrc: number,
  117. /**
  118. * Statistics related to transports.
  119. */
  120. transport: Array<Object>
  121. };
  122. /**
  123. * React {@code Component} for displaying connection statistics.
  124. *
  125. * @extends Component
  126. */
  127. class ConnectionStatsTable extends Component<Props> {
  128. /**
  129. * Implements React's {@link Component#render()}.
  130. *
  131. * @inheritdoc
  132. * @returns {ReactElement}
  133. */
  134. render() {
  135. const { isLocalVideo, enableSaveLogs } = this.props;
  136. return (
  137. <div className = 'connection-info'>
  138. { this._renderStatistics() }
  139. <div className = 'connection-actions'>
  140. { isLocalVideo && enableSaveLogs ? this._renderSaveLogs() : null}
  141. { this._renderShowMoreLink() }
  142. </div>
  143. { this.props.shouldShowMore ? this._renderAdditionalStats() : null }
  144. </div>
  145. );
  146. }
  147. /**
  148. * Creates a table as ReactElement that will display additional statistics
  149. * related to bandwidth and transport for the local user.
  150. *
  151. * @private
  152. * @returns {ReactElement}
  153. */
  154. _renderAdditionalStats() {
  155. const { isLocalVideo } = this.props;
  156. return (
  157. <table className = 'connection-info__container'>
  158. <tbody>
  159. { isLocalVideo ? this._renderBandwidth() : null }
  160. { isLocalVideo ? this._renderTransport() : null }
  161. { isLocalVideo ? this._renderRegion() : null }
  162. { this._renderAudioSsrc() }
  163. { this._renderVideoSsrc() }
  164. { this._renderParticipantId() }
  165. </tbody>
  166. </table>
  167. );
  168. }
  169. /**
  170. * Creates a table row as a ReactElement for displaying bandwidth related
  171. * statistics.
  172. *
  173. * @private
  174. * @returns {ReactElement}
  175. */
  176. _renderBandwidth() {
  177. const { download, upload } = this.props.bandwidth || {};
  178. return (
  179. <tr>
  180. <td>
  181. { this.props.t('connectionindicator.bandwidth') }
  182. </td>
  183. <td>
  184. <span className = 'connection-info__download'>
  185. &darr;
  186. </span>
  187. { download ? `${download} Kbps` : 'N/A' }
  188. <span className = 'connection-info__upload'>
  189. &uarr;
  190. </span>
  191. { upload ? `${upload} Kbps` : 'N/A' }
  192. </td>
  193. </tr>
  194. );
  195. }
  196. /**
  197. * Creates a a table row as a ReactElement for displaying bitrate related
  198. * statistics.
  199. *
  200. * @private
  201. * @returns {ReactElement}
  202. */
  203. _renderBitrate() {
  204. const { download, upload } = this.props.bitrate || {};
  205. return (
  206. <tr>
  207. <td>
  208. <span>
  209. { this.props.t('connectionindicator.bitrate') }
  210. </span>
  211. </td>
  212. <td>
  213. <span className = 'connection-info__download'>
  214. &darr;
  215. </span>
  216. { download ? `${download} Kbps` : 'N/A' }
  217. <span className = 'connection-info__upload'>
  218. &uarr;
  219. </span>
  220. { upload ? `${upload} Kbps` : 'N/A' }
  221. </td>
  222. </tr>
  223. );
  224. }
  225. /**
  226. * Creates a table row as a ReactElement for displaying the audio ssrc.
  227. * This will typically be something like "Audio SSRC: 12345".
  228. *
  229. * @returns {JSX.Element}
  230. * @private
  231. */
  232. _renderAudioSsrc() {
  233. const { audioSsrc, t } = this.props;
  234. return (
  235. <tr>
  236. <td>
  237. <span>{ t('connectionindicator.audio_ssrc') }</span>
  238. </td>
  239. <td>{ audioSsrc || 'N/A' }</td>
  240. </tr>
  241. );
  242. }
  243. /**
  244. * Creates a table row as a ReactElement for displaying the video ssrc.
  245. * This will typically be something like "Video SSRC: 12345".
  246. *
  247. * @returns {JSX.Element}
  248. * @private
  249. */
  250. _renderVideoSsrc() {
  251. const { videoSsrc, t } = this.props;
  252. return (
  253. <tr>
  254. <td>
  255. <span>{ t('connectionindicator.video_ssrc') }</span>
  256. </td>
  257. <td>{ videoSsrc || 'N/A' }</td>
  258. </tr>
  259. );
  260. }
  261. /**
  262. * Creates a table row as a ReactElement for displaying the endpoint id.
  263. * This will typically be something like "Endpoint id: 1e8fbg".
  264. *
  265. * @returns {JSX.Element}
  266. * @private
  267. */
  268. _renderParticipantId() {
  269. const { participantId, t } = this.props;
  270. return (
  271. <tr>
  272. <td>
  273. <span>{ t('connectionindicator.participant_id') }</span>
  274. </td>
  275. <td>{ participantId || 'N/A' }</td>
  276. </tr>
  277. );
  278. }
  279. /**
  280. * Creates a a table row as a ReactElement for displaying codec, if present.
  281. * This will typically be something like "Codecs (A/V): Opus, vp8".
  282. *
  283. * @private
  284. * @returns {ReactElement}
  285. */
  286. _renderCodecs() {
  287. const { codec, t } = this.props;
  288. if (!codec) {
  289. return;
  290. }
  291. let codecString;
  292. // Only report one codec, in case there are multiple for a user.
  293. Object.keys(codec || {})
  294. .forEach(ssrc => {
  295. const { audio, video } = codec[ssrc];
  296. codecString = `${audio}, ${video}`;
  297. });
  298. if (!codecString) {
  299. codecString = 'N/A';
  300. }
  301. return (
  302. <tr>
  303. <td>
  304. <span>{ t('connectionindicator.codecs') }</span>
  305. </td>
  306. <td>{ codecString }</td>
  307. </tr>
  308. );
  309. }
  310. /**
  311. * Creates a table row as a ReactElement for displaying a summary message
  312. * about the current connection status.
  313. *
  314. * @private
  315. * @returns {ReactElement}
  316. */
  317. _renderConnectionSummary() {
  318. return (
  319. <tr className = 'connection-info__status'>
  320. <td>
  321. <span>{ this.props.t('connectionindicator.status') }</span>
  322. </td>
  323. <td>{ this.props.connectionSummary }</td>
  324. </tr>
  325. );
  326. }
  327. /**
  328. * Creates a table row as a ReactElement for displaying end-to-end RTT and
  329. * the region.
  330. *
  331. * @returns {ReactElement}
  332. * @private
  333. */
  334. _renderE2eRtt() {
  335. const { e2eRtt, t } = this.props;
  336. const str = e2eRtt ? `${e2eRtt.toFixed(0)}ms` : 'N/A';
  337. return (
  338. <tr>
  339. <td>
  340. <span>{ t('connectionindicator.e2e_rtt') }</span>
  341. </td>
  342. <td>{ str }</td>
  343. </tr>
  344. );
  345. }
  346. /**
  347. * Creates a table row as a ReactElement for displaying the "connected to"
  348. * information.
  349. *
  350. * @returns {ReactElement}
  351. * @private
  352. */
  353. _renderRegion() {
  354. const { region, serverRegion, t } = this.props;
  355. let str = serverRegion;
  356. if (!serverRegion) {
  357. return;
  358. }
  359. if (region && serverRegion && region !== serverRegion) {
  360. str += ` from ${region}`;
  361. }
  362. return (
  363. <tr>
  364. <td>
  365. <span>{ t('connectionindicator.connectedTo') }</span>
  366. </td>
  367. <td>{ str }</td>
  368. </tr>
  369. );
  370. }
  371. /**
  372. * Creates a table row as a ReactElement for displaying the "bridge count"
  373. * information.
  374. *
  375. * @returns {*}
  376. * @private
  377. */
  378. _renderBridgeCount() {
  379. const { bridgeCount, t } = this.props;
  380. // 0 is valid, but undefined/null/NaN aren't.
  381. if (!bridgeCount && bridgeCount !== 0) {
  382. return;
  383. }
  384. return (
  385. <tr>
  386. <td>
  387. <span>{ t('connectionindicator.bridgeCount') }</span>
  388. </td>
  389. <td>{ bridgeCount }</td>
  390. </tr>
  391. );
  392. }
  393. /**
  394. * Creates a table row as a ReactElement for displaying frame rate related
  395. * statistics.
  396. *
  397. * @private
  398. * @returns {ReactElement}
  399. */
  400. _renderFrameRate() {
  401. const { framerate, t } = this.props;
  402. const frameRateString = Object.keys(framerate || {})
  403. .map(ssrc => framerate[ssrc])
  404. .join(', ') || 'N/A';
  405. return (
  406. <tr>
  407. <td>
  408. <span>{ t('connectionindicator.framerate') }</span>
  409. </td>
  410. <td>{ frameRateString }</td>
  411. </tr>
  412. );
  413. }
  414. /**
  415. * Creates a tables row as a ReactElement for displaying packet loss related
  416. * statistics.
  417. *
  418. * @private
  419. * @returns {ReactElement}
  420. */
  421. _renderPacketLoss() {
  422. const { packetLoss, t } = this.props;
  423. let packetLossTableData;
  424. if (packetLoss) {
  425. const { download, upload } = packetLoss;
  426. packetLossTableData = (
  427. <td>
  428. <span className = 'connection-info__download'>
  429. &darr;
  430. </span>
  431. { download === null ? 'N/A' : `${download}%` }
  432. <span className = 'connection-info__upload'>
  433. &uarr;
  434. </span>
  435. { upload === null ? 'N/A' : `${upload}%` }
  436. </td>
  437. );
  438. } else {
  439. packetLossTableData = <td>N/A</td>;
  440. }
  441. return (
  442. <tr>
  443. <td>
  444. <span>
  445. { t('connectionindicator.packetloss') }
  446. </span>
  447. </td>
  448. { packetLossTableData }
  449. </tr>
  450. );
  451. }
  452. /**
  453. * Creates a table row as a ReactElement for displaying resolution related
  454. * statistics.
  455. *
  456. * @private
  457. * @returns {ReactElement}
  458. */
  459. _renderResolution() {
  460. const { resolution, maxEnabledResolution, t } = this.props;
  461. let resolutionString = Object.keys(resolution || {})
  462. .map(ssrc => {
  463. const { width, height } = resolution[ssrc];
  464. return `${width}x${height}`;
  465. })
  466. .join(', ') || 'N/A';
  467. if (maxEnabledResolution && maxEnabledResolution < 720) {
  468. const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
  469. resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
  470. }
  471. return (
  472. <tr>
  473. <td>
  474. <span>{ t('connectionindicator.resolution') }</span>
  475. </td>
  476. <td>{ resolutionString }</td>
  477. </tr>
  478. );
  479. }
  480. /**
  481. * Creates a ReactElement for display a link to save the logs.
  482. *
  483. * @private
  484. * @returns {ReactElement}
  485. */
  486. _renderSaveLogs() {
  487. return (
  488. <span>
  489. <a
  490. className = 'savelogs link'
  491. onClick = { this.props.onSaveLogs } >
  492. { this.props.t('connectionindicator.savelogs') }
  493. </a>
  494. <span> | </span>
  495. </span>
  496. );
  497. }
  498. /**
  499. * Creates a ReactElement for display a link to toggle showing additional
  500. * statistics.
  501. *
  502. * @private
  503. * @returns {ReactElement}
  504. */
  505. _renderShowMoreLink() {
  506. const translationKey
  507. = this.props.shouldShowMore
  508. ? 'connectionindicator.less'
  509. : 'connectionindicator.more';
  510. return (
  511. <a
  512. className = 'showmore link'
  513. onClick = { this.props.onShowMore } >
  514. { this.props.t(translationKey) }
  515. </a>
  516. );
  517. }
  518. /**
  519. * Creates a table as a ReactElement for displaying connection statistics.
  520. *
  521. * @private
  522. * @returns {ReactElement}
  523. */
  524. _renderStatistics() {
  525. const isRemoteVideo = !this.props.isLocalVideo;
  526. return (
  527. <table className = 'connection-info__container'>
  528. <tbody>
  529. { this._renderConnectionSummary() }
  530. { this._renderBitrate() }
  531. { this._renderPacketLoss() }
  532. { isRemoteVideo ? this._renderE2eRtt() : null }
  533. { isRemoteVideo ? this._renderRegion() : null }
  534. { this._renderResolution() }
  535. { this._renderFrameRate() }
  536. { this._renderCodecs() }
  537. { isRemoteVideo ? null : this._renderBridgeCount() }
  538. </tbody>
  539. </table>
  540. );
  541. }
  542. /**
  543. * Creates table rows as ReactElements for displaying transport related
  544. * statistics.
  545. *
  546. * @private
  547. * @returns {ReactElement[]}
  548. */
  549. _renderTransport() {
  550. const { t, transport } = this.props;
  551. if (!transport || transport.length === 0) {
  552. const NA = (
  553. <tr key = 'address'>
  554. <td>
  555. <span>{ t('connectionindicator.address') }</span>
  556. </td>
  557. <td>
  558. N/A
  559. </td>
  560. </tr>
  561. );
  562. return [ NA ];
  563. }
  564. const data = {
  565. localIP: [],
  566. localPort: [],
  567. remoteIP: [],
  568. remotePort: [],
  569. transportType: []
  570. };
  571. for (let i = 0; i < transport.length; i++) {
  572. const ip = getIP(transport[i].ip);
  573. const localIP = getIP(transport[i].localip);
  574. const localPort = getPort(transport[i].localip);
  575. const port = getPort(transport[i].ip);
  576. if (!data.remoteIP.includes(ip)) {
  577. data.remoteIP.push(ip);
  578. }
  579. if (!data.localIP.includes(localIP)) {
  580. data.localIP.push(localIP);
  581. }
  582. if (!data.localPort.includes(localPort)) {
  583. data.localPort.push(localPort);
  584. }
  585. if (!data.remotePort.includes(port)) {
  586. data.remotePort.push(port);
  587. }
  588. if (!data.transportType.includes(transport[i].type)) {
  589. data.transportType.push(transport[i].type);
  590. }
  591. }
  592. // All of the transports should be either P2P or JVB
  593. let isP2P = false, isTURN = false;
  594. if (transport.length) {
  595. isP2P = transport[0].p2p;
  596. isTURN = transport[0].localCandidateType === 'relay'
  597. || transport[0].remoteCandidateType === 'relay';
  598. }
  599. const additionalData = [];
  600. if (isP2P) {
  601. additionalData.push(
  602. <span> (p2p)</span>);
  603. }
  604. if (isTURN) {
  605. additionalData.push(<span> (turn)</span>);
  606. }
  607. // First show remote statistics, then local, and then transport type.
  608. const tableRowConfigurations = [
  609. {
  610. additionalData,
  611. data: data.remoteIP,
  612. key: 'remoteaddress',
  613. label: t('connectionindicator.remoteaddress',
  614. { count: data.remoteIP.length })
  615. },
  616. {
  617. data: data.remotePort,
  618. key: 'remoteport',
  619. label: t('connectionindicator.remoteport',
  620. { count: transport.length })
  621. },
  622. {
  623. data: data.localIP,
  624. key: 'localaddress',
  625. label: t('connectionindicator.localaddress',
  626. { count: data.localIP.length })
  627. },
  628. {
  629. data: data.localPort,
  630. key: 'localport',
  631. label: t('connectionindicator.localport',
  632. { count: transport.length })
  633. },
  634. {
  635. data: data.transportType,
  636. key: 'transport',
  637. label: t('connectionindicator.transport',
  638. { count: data.transportType.length })
  639. }
  640. ];
  641. return tableRowConfigurations.map(this._renderTransportTableRow);
  642. }
  643. /**
  644. * Creates a table row as a ReactElement for displaying a transport related
  645. * statistic.
  646. *
  647. * @param {Object} config - Describes the contents of the row.
  648. * @param {ReactElement} config.additionalData - Extra data to display next
  649. * to the passed in config.data.
  650. * @param {Array} config.data - The transport statistics to display.
  651. * @param {string} config.key - The ReactElement's key. Must be unique for
  652. * iterating over multiple child rows.
  653. * @param {string} config.label - The text to display describing the data.
  654. * @private
  655. * @returns {ReactElement}
  656. */
  657. _renderTransportTableRow(config: Object) {
  658. const { additionalData, data, key, label } = config;
  659. return (
  660. <tr key = { key }>
  661. <td>
  662. <span>
  663. { label }
  664. </span>
  665. </td>
  666. <td>
  667. { getStringFromArray(data) }
  668. { additionalData || null }
  669. </td>
  670. </tr>
  671. );
  672. }
  673. }
  674. /**
  675. * Utility for getting the IP from a transport statistics object's
  676. * representation of an IP.
  677. *
  678. * @param {string} value - The transport's IP to parse.
  679. * @private
  680. * @returns {string}
  681. */
  682. function getIP(value) {
  683. if (!value) {
  684. return '';
  685. }
  686. return value.substring(0, value.lastIndexOf(':'));
  687. }
  688. /**
  689. * Utility for getting the port from a transport statistics object's
  690. * representation of an IP.
  691. *
  692. * @param {string} value - The transport's IP to parse.
  693. * @private
  694. * @returns {string}
  695. */
  696. function getPort(value) {
  697. if (!value) {
  698. return '';
  699. }
  700. return value.substring(value.lastIndexOf(':') + 1, value.length);
  701. }
  702. /**
  703. * Utility for concatenating values in an array into a comma separated string.
  704. *
  705. * @param {Array} array - Transport statistics to concatenate.
  706. * @private
  707. * @returns {string}
  708. */
  709. function getStringFromArray(array) {
  710. let res = '';
  711. for (let i = 0; i < array.length; i++) {
  712. res += (i === 0 ? '' : ', ') + array[i];
  713. }
  714. return res;
  715. }
  716. export default translate(ConnectionStatsTable);