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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. import { Theme } from '@mui/material';
  2. import { withStyles } from '@mui/styles';
  3. import clsx from 'clsx';
  4. import React, { Component } from 'react';
  5. import { WithTranslation } from 'react-i18next';
  6. import { isMobileBrowser } from '../../base/environment/utils';
  7. import { translate } from '../../base/i18n/functions';
  8. import ContextMenu from '../../base/ui/components/web/ContextMenu';
  9. type DownloadUpload = {
  10. download: number;
  11. upload: number;
  12. };
  13. /**
  14. * The type of the React {@code Component} props of
  15. * {@link ConnectionStatsTable}.
  16. */
  17. interface IProps extends WithTranslation {
  18. /**
  19. * The audio SSRC of this client.
  20. */
  21. audioSsrc: number;
  22. /**
  23. * Statistics related to bandwidth.
  24. * {{
  25. * download: Number,
  26. * upload: Number
  27. * }}.
  28. */
  29. bandwidth: DownloadUpload;
  30. /**
  31. * Statistics related to bitrate.
  32. * {{
  33. * download: Number,
  34. * upload: Number
  35. * }}.
  36. */
  37. bitrate: DownloadUpload;
  38. /**
  39. * The number of bridges (aka media servers) currently used in the
  40. * conference.
  41. */
  42. bridgeCount: number;
  43. /**
  44. * An object containing the CSS classes.
  45. */
  46. classes: any;
  47. /**
  48. * Audio/video codecs in use for the connection.
  49. */
  50. codec: {
  51. [key: string]: {
  52. audio: string | undefined;
  53. video: string | undefined;
  54. };
  55. };
  56. /**
  57. * A message describing the connection quality.
  58. */
  59. connectionSummary: string;
  60. /**
  61. * Whether or not should display the "Show More" link.
  62. */
  63. disableShowMoreStats: boolean;
  64. /**
  65. * Whether or not the participant was verified.
  66. */
  67. e2eeVerified: boolean;
  68. /**
  69. * Whether or not should display the "Save Logs" link.
  70. */
  71. enableSaveLogs: boolean;
  72. /**
  73. * Statistics related to frame rates for each ssrc.
  74. * {{
  75. * [ ssrc ]: Number
  76. * }}.
  77. */
  78. framerate: {
  79. [ssrc: string]: number;
  80. };
  81. /**
  82. * Whether or not the statistics are for local video.
  83. */
  84. isLocalVideo: boolean;
  85. /**
  86. * Whether we are in narrow layout mode or not.
  87. */
  88. isNarrowLayout: boolean;
  89. /**
  90. * Whether or not the statistics are for screen share.
  91. */
  92. isVirtualScreenshareParticipant: boolean;
  93. /**
  94. * The send-side max enabled resolution (aka the highest layer that is not
  95. * suspended on the send-side).
  96. */
  97. maxEnabledResolution: number;
  98. /**
  99. * Callback to invoke when the user clicks on the download logs link.
  100. */
  101. onSaveLogs: () => void;
  102. /**
  103. * Callback to invoke when the show additional stats link is clicked.
  104. */
  105. onShowMore: (e?: React.MouseEvent) => void;
  106. /**
  107. * Statistics related to packet loss.
  108. * {{
  109. * download: Number,
  110. * upload: Number
  111. * }}.
  112. */
  113. packetLoss: DownloadUpload;
  114. /**
  115. * The endpoint id of this client.
  116. */
  117. participantId: string;
  118. /**
  119. * The region that we think the client is in.
  120. */
  121. region: string;
  122. /**
  123. * Statistics related to display resolutions for each ssrc.
  124. * {{
  125. * [ ssrc ]: {
  126. * height: Number,
  127. * width: Number
  128. * }
  129. * }}.
  130. */
  131. resolution: {
  132. [ssrc: string]: {
  133. height: number;
  134. width: number;
  135. };
  136. };
  137. /**
  138. * The region of the media server that we are connected to.
  139. */
  140. serverRegion: string;
  141. /**
  142. * Whether or not additional stats about bandwidth and transport should be
  143. * displayed. Will not display even if true for remote participants.
  144. */
  145. shouldShowMore: boolean;
  146. /**
  147. * Statistics related to transports.
  148. */
  149. transport: Array<{
  150. ip: string;
  151. localCandidateType: string;
  152. localip: string;
  153. p2p: boolean;
  154. remoteCandidateType: string;
  155. transportType: string;
  156. type: string;
  157. }>;
  158. /**
  159. * The video SSRC of this client.
  160. */
  161. videoSsrc: number;
  162. }
  163. /**
  164. * Click handler.
  165. *
  166. * @param {SyntheticEvent} event - The click event.
  167. * @returns {void}
  168. */
  169. function onClick(event: React.MouseEvent) {
  170. // If the event is propagated to the thumbnail container the participant will be pinned. That's why the propagation
  171. // needs to be stopped.
  172. event.stopPropagation();
  173. }
  174. const styles = (theme: Theme) => {
  175. return {
  176. actions: {
  177. margin: '10px auto',
  178. textAlign: 'center' as const
  179. },
  180. connectionStatsTable: {
  181. '&, & > table': {
  182. fontSize: '12px',
  183. fontWeight: '400',
  184. '& td': {
  185. padding: '2px 0'
  186. }
  187. },
  188. '& > table': {
  189. whiteSpace: 'nowrap'
  190. },
  191. '& td:nth-child(n-1)': {
  192. paddingLeft: '5px'
  193. },
  194. '& $upload, & $download': {
  195. marginRight: '2px'
  196. }
  197. },
  198. contextMenu: {
  199. position: 'relative' as const,
  200. margin: 0,
  201. right: 'auto',
  202. padding: `${theme.spacing(2)} ${theme.spacing(1)}`
  203. },
  204. download: {},
  205. mobile: {
  206. margin: theme.spacing(3)
  207. },
  208. status: {
  209. fontWeight: 'bold'
  210. },
  211. upload: {}
  212. };
  213. };
  214. /**
  215. * React {@code Component} for displaying connection statistics.
  216. *
  217. * @augments Component
  218. */
  219. class ConnectionStatsTable extends Component<IProps> {
  220. /**
  221. * Implements React's {@link Component#render()}.
  222. *
  223. * @inheritdoc
  224. * @returns {ReactElement}
  225. */
  226. render() {
  227. const {
  228. classes,
  229. disableShowMoreStats,
  230. enableSaveLogs,
  231. isVirtualScreenshareParticipant,
  232. isLocalVideo,
  233. isNarrowLayout
  234. } = this.props;
  235. const className = clsx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() || isNarrowLayout });
  236. if (isVirtualScreenshareParticipant) {
  237. return this._renderScreenShareStatus();
  238. }
  239. return (
  240. <ContextMenu
  241. className = { classes.contextMenu }
  242. hidden = { false }
  243. inDrawer = { true }>
  244. <div
  245. className = { className }
  246. onClick = { onClick }>
  247. { this._renderStatistics() }
  248. <div className = { classes.actions }>
  249. { isLocalVideo && enableSaveLogs ? this._renderSaveLogs() : null}
  250. { !disableShowMoreStats && this._renderShowMoreLink() }
  251. </div>
  252. { this.props.shouldShowMore ? this._renderAdditionalStats() : null }
  253. </div>
  254. </ContextMenu>
  255. );
  256. }
  257. /**
  258. * Creates a ReactElement that will display connection statistics for a screen share thumbnail.
  259. *
  260. * @private
  261. * @returns {ReactElement}
  262. */
  263. _renderScreenShareStatus() {
  264. const { classes } = this.props;
  265. const className = clsx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() });
  266. return (<ContextMenu
  267. className = { classes.contextMenu }
  268. hidden = { false }
  269. inDrawer = { true }>
  270. <div
  271. className = { className }
  272. onClick = { onClick }>
  273. <tbody>
  274. { this._renderResolution() }
  275. { this._renderFrameRate() }
  276. </tbody>
  277. </div>
  278. </ContextMenu>);
  279. }
  280. /**
  281. * Creates a table as ReactElement that will display additional statistics
  282. * related to bandwidth and transport for the local user.
  283. *
  284. * @private
  285. * @returns {ReactElement}
  286. */
  287. _renderAdditionalStats() {
  288. const { isLocalVideo } = this.props;
  289. return (
  290. <table>
  291. <tbody>
  292. { isLocalVideo ? this._renderBandwidth() : null }
  293. { isLocalVideo ? this._renderTransport() : null }
  294. { this._renderRegion() }
  295. { isLocalVideo ? this._renderBridgeCount() : null }
  296. { this._renderAudioSsrc() }
  297. { this._renderVideoSsrc() }
  298. { this._renderParticipantId() }
  299. </tbody>
  300. </table>
  301. );
  302. }
  303. /**
  304. * Creates a table row as a ReactElement for displaying bandwidth related
  305. * statistics.
  306. *
  307. * @private
  308. * @returns {ReactElement}
  309. */
  310. _renderBandwidth() {
  311. const { classes } = this.props;
  312. const { download, upload } = this.props.bandwidth || {};
  313. return (
  314. <tr>
  315. <td>
  316. { this.props.t('connectionindicator.bandwidth') }
  317. </td>
  318. <td>
  319. <span className = { classes.download }>
  320. &darr;
  321. </span>
  322. { download ? `${download} Kbps` : 'N/A' }
  323. <span className = { classes.upload }>
  324. &uarr;
  325. </span>
  326. { upload ? `${upload} Kbps` : 'N/A' }
  327. </td>
  328. </tr>
  329. );
  330. }
  331. /**
  332. * Creates a a table row as a ReactElement for displaying bitrate related
  333. * statistics.
  334. *
  335. * @private
  336. * @returns {ReactElement}
  337. */
  338. _renderBitrate() {
  339. const { classes } = this.props;
  340. const { download, upload } = this.props.bitrate || {};
  341. return (
  342. <tr>
  343. <td>
  344. <span>
  345. { this.props.t('connectionindicator.bitrate') }
  346. </span>
  347. </td>
  348. <td>
  349. <span className = { classes.download }>
  350. &darr;
  351. </span>
  352. { download ? `${download} Kbps` : 'N/A' }
  353. <span className = { classes.upload }>
  354. &uarr;
  355. </span>
  356. { upload ? `${upload} Kbps` : 'N/A' }
  357. </td>
  358. </tr>
  359. );
  360. }
  361. /**
  362. * Creates a table row as a ReactElement for displaying the audio ssrc.
  363. * This will typically be something like "Audio SSRC: 12345".
  364. *
  365. * @returns {JSX.Element}
  366. * @private
  367. */
  368. _renderAudioSsrc() {
  369. const { audioSsrc, t } = this.props;
  370. return (
  371. <tr>
  372. <td>
  373. <span>{ t('connectionindicator.audio_ssrc') }</span>
  374. </td>
  375. <td>{ audioSsrc || 'N/A' }</td>
  376. </tr>
  377. );
  378. }
  379. /**
  380. * Creates a table row as a ReactElement for displaying the video ssrc.
  381. * This will typically be something like "Video SSRC: 12345".
  382. *
  383. * @returns {JSX.Element}
  384. * @private
  385. */
  386. _renderVideoSsrc() {
  387. const { videoSsrc, t } = this.props;
  388. return (
  389. <tr>
  390. <td>
  391. <span>{ t('connectionindicator.video_ssrc') }</span>
  392. </td>
  393. <td>{ videoSsrc || 'N/A' }</td>
  394. </tr>
  395. );
  396. }
  397. /**
  398. * Creates a table row as a ReactElement for displaying the endpoint id.
  399. * This will typically be something like "Endpoint id: 1e8fbg".
  400. *
  401. * @returns {JSX.Element}
  402. * @private
  403. */
  404. _renderParticipantId() {
  405. const { participantId, t } = this.props;
  406. return (
  407. <tr>
  408. <td>
  409. <span>{ t('connectionindicator.participant_id') }</span>
  410. </td>
  411. <td>{ participantId || 'N/A' }</td>
  412. </tr>
  413. );
  414. }
  415. /**
  416. * Creates a a table row as a ReactElement for displaying codec, if present.
  417. * This will typically be something like "Codecs (A/V): Opus, vp8".
  418. *
  419. * @private
  420. * @returns {ReactElement}
  421. */
  422. _renderCodecs() {
  423. const { audioSsrc, codec, t, videoSsrc } = this.props;
  424. let codecString = 'N/A';
  425. if (codec) {
  426. const audioCodec = codec[audioSsrc]?.audio;
  427. const videoCodec = codec[videoSsrc]?.video;
  428. if (audioCodec || videoCodec) {
  429. codecString = [ audioCodec, videoCodec ].filter(Boolean).join(', ');
  430. }
  431. }
  432. return (
  433. <tr>
  434. <td>
  435. <span>{ t('connectionindicator.codecs') }</span>
  436. </td>
  437. <td>{ codecString }</td>
  438. </tr>
  439. );
  440. }
  441. /**
  442. * Creates a a table row as a ReactElement for displaying e2ee verication status, if present.
  443. *
  444. * @private
  445. * @returns {ReactElement}
  446. */
  447. _renderE2EEVerified() {
  448. const { e2eeVerified, t } = this.props;
  449. if (e2eeVerified === undefined) {
  450. return;
  451. }
  452. const status = e2eeVerified ? '\u{2705}' : '\u{274C}';
  453. return (
  454. <tr>
  455. <td>
  456. <span>{ t('connectionindicator.e2eeVerified') }</span>
  457. </td>
  458. <td>{ status }</td>
  459. </tr>
  460. );
  461. }
  462. /**
  463. * Creates a table row as a ReactElement for displaying a summary message
  464. * about the current connection status.
  465. *
  466. * @private
  467. * @returns {ReactElement}
  468. */
  469. _renderConnectionSummary() {
  470. const { classes } = this.props;
  471. return (
  472. <tr className = { classes.status }>
  473. <td>
  474. <span>{ this.props.t('connectionindicator.status') }</span>
  475. </td>
  476. <td>{ this.props.connectionSummary }</td>
  477. </tr>
  478. );
  479. }
  480. /**
  481. * Creates a table row as a ReactElement for displaying the "connected to"
  482. * information.
  483. *
  484. * @returns {ReactElement}
  485. * @private
  486. */
  487. _renderRegion() {
  488. const { region, serverRegion, t } = this.props;
  489. let str = serverRegion;
  490. if (!serverRegion) {
  491. return;
  492. }
  493. if (region && serverRegion && region !== serverRegion) {
  494. str += ` from ${region}`;
  495. }
  496. return (
  497. <tr>
  498. <td>
  499. <span>{ t('connectionindicator.connectedTo') }</span>
  500. </td>
  501. <td>{ str }</td>
  502. </tr>
  503. );
  504. }
  505. /**
  506. * Creates a table row as a ReactElement for displaying the "bridge count"
  507. * information.
  508. *
  509. * @returns {*}
  510. * @private
  511. */
  512. _renderBridgeCount() {
  513. const { bridgeCount, t } = this.props;
  514. // 0 is valid, but undefined/null/NaN aren't.
  515. if (!bridgeCount && bridgeCount !== 0) {
  516. return;
  517. }
  518. return (
  519. <tr>
  520. <td>
  521. <span>{ t('connectionindicator.bridgeCount') }</span>
  522. </td>
  523. <td>{ bridgeCount }</td>
  524. </tr>
  525. );
  526. }
  527. /**
  528. * Creates a table row as a ReactElement for displaying frame rate related
  529. * statistics.
  530. *
  531. * @private
  532. * @returns {ReactElement}
  533. */
  534. _renderFrameRate() {
  535. const { framerate, t, videoSsrc } = this.props;
  536. let frameRateString = 'N/A';
  537. if (framerate) {
  538. frameRateString = String(framerate[videoSsrc] ?? 'N/A');
  539. }
  540. return (
  541. <tr>
  542. <td>
  543. <span>{ t('connectionindicator.framerate') }</span>
  544. </td>
  545. <td>{ frameRateString }</td>
  546. </tr>
  547. );
  548. }
  549. /**
  550. * Creates a tables row as a ReactElement for displaying packet loss related
  551. * statistics.
  552. *
  553. * @private
  554. * @returns {ReactElement}
  555. */
  556. _renderPacketLoss() {
  557. const { classes, packetLoss, t } = this.props;
  558. let packetLossTableData;
  559. if (packetLoss) {
  560. const { download, upload } = packetLoss;
  561. packetLossTableData = (
  562. <td>
  563. <span className = { classes.download }>
  564. &darr;
  565. </span>
  566. { download === null ? 'N/A' : `${download}%` }
  567. <span className = { classes.upload }>
  568. &uarr;
  569. </span>
  570. { upload === null ? 'N/A' : `${upload}%` }
  571. </td>
  572. );
  573. } else {
  574. packetLossTableData = <td>N/A</td>;
  575. }
  576. return (
  577. <tr>
  578. <td>
  579. <span>
  580. { t('connectionindicator.packetloss') }
  581. </span>
  582. </td>
  583. { packetLossTableData }
  584. </tr>
  585. );
  586. }
  587. /**
  588. * Creates a table row as a ReactElement for displaying resolution related
  589. * statistics.
  590. *
  591. * @private
  592. * @returns {ReactElement}
  593. */
  594. _renderResolution() {
  595. const { isVirtualScreenshareParticipant, maxEnabledResolution, resolution, t, videoSsrc } = this.props;
  596. let resolutionString = 'N/A';
  597. if (resolution && videoSsrc) {
  598. const { width, height } = resolution[videoSsrc] ?? { };
  599. if (width && height) {
  600. resolutionString = `${width}x${height}`;
  601. if (maxEnabledResolution && maxEnabledResolution < 720 && !isVirtualScreenshareParticipant) {
  602. const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
  603. resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
  604. }
  605. }
  606. }
  607. return (
  608. <tr>
  609. <td>
  610. <span>{ t('connectionindicator.resolution') }</span>
  611. </td>
  612. <td>{ resolutionString }</td>
  613. </tr>
  614. );
  615. }
  616. /**
  617. * Creates a ReactElement for display a link to save the logs.
  618. *
  619. * @private
  620. * @returns {ReactElement}
  621. */
  622. _renderSaveLogs() {
  623. return (
  624. <span>
  625. <a
  626. className = 'savelogs link'
  627. onClick = { this.props.onSaveLogs }
  628. role = 'button'
  629. tabIndex = { 0 }>
  630. { this.props.t('connectionindicator.savelogs') }
  631. </a>
  632. <span> | </span>
  633. </span>
  634. );
  635. }
  636. /**
  637. * Creates a ReactElement for display a link to toggle showing additional
  638. * statistics.
  639. *
  640. * @private
  641. * @returns {ReactElement}
  642. */
  643. _renderShowMoreLink() {
  644. const translationKey
  645. = this.props.shouldShowMore
  646. ? 'connectionindicator.less'
  647. : 'connectionindicator.more';
  648. return (
  649. <a
  650. className = 'showmore link'
  651. onClick = { this.props.onShowMore }
  652. role = 'button'
  653. tabIndex = { 0 }>
  654. { this.props.t(translationKey) }
  655. </a>
  656. );
  657. }
  658. /**
  659. * Creates a table as a ReactElement for displaying connection statistics.
  660. *
  661. * @private
  662. * @returns {ReactElement}
  663. */
  664. _renderStatistics() {
  665. return (
  666. <table>
  667. <tbody>
  668. { this._renderConnectionSummary() }
  669. { this._renderBitrate() }
  670. { this._renderPacketLoss() }
  671. { this._renderResolution() }
  672. { this._renderFrameRate() }
  673. { this._renderCodecs() }
  674. { this._renderE2EEVerified() }
  675. </tbody>
  676. </table>
  677. );
  678. }
  679. /**
  680. * Creates table rows as ReactElements for displaying transport related
  681. * statistics.
  682. *
  683. * @private
  684. * @returns {ReactElement[]}
  685. */
  686. _renderTransport() {
  687. const { t, transport } = this.props;
  688. if (!transport || transport.length === 0) {
  689. const NA = (
  690. <tr key = 'address'>
  691. <td>
  692. <span>{ t('connectionindicator.address') }</span>
  693. </td>
  694. <td>
  695. N/A
  696. </td>
  697. </tr>
  698. );
  699. return [ NA ];
  700. }
  701. const data: {
  702. localIP: string[];
  703. localPort: string[];
  704. remoteIP: string[];
  705. remotePort: string[];
  706. transportType: string[];
  707. } = {
  708. localIP: [],
  709. localPort: [],
  710. remoteIP: [],
  711. remotePort: [],
  712. transportType: []
  713. };
  714. for (let i = 0; i < transport.length; i++) {
  715. const ip = getIP(transport[i].ip);
  716. const localIP = getIP(transport[i].localip);
  717. const localPort = getPort(transport[i].localip);
  718. const port = getPort(transport[i].ip);
  719. if (!data.remoteIP.includes(ip)) {
  720. data.remoteIP.push(ip);
  721. }
  722. if (!data.localIP.includes(localIP)) {
  723. data.localIP.push(localIP);
  724. }
  725. if (!data.localPort.includes(localPort)) {
  726. data.localPort.push(localPort);
  727. }
  728. if (!data.remotePort.includes(port)) {
  729. data.remotePort.push(port);
  730. }
  731. if (!data.transportType.includes(transport[i].type)) {
  732. data.transportType.push(transport[i].type);
  733. }
  734. }
  735. // All of the transports should be either P2P or JVB
  736. let isP2P = false, isTURN = false;
  737. if (transport.length) {
  738. isP2P = transport[0].p2p;
  739. isTURN = transport[0].localCandidateType === 'relay'
  740. || transport[0].remoteCandidateType === 'relay';
  741. }
  742. const additionalData = [];
  743. if (isP2P) {
  744. additionalData.push(
  745. <span> (p2p)</span>);
  746. }
  747. if (isTURN) {
  748. additionalData.push(<span> (turn)</span>);
  749. }
  750. // First show remote statistics, then local, and then transport type.
  751. const tableRowConfigurations = [
  752. {
  753. additionalData,
  754. data: data.remoteIP,
  755. key: 'remoteaddress',
  756. label: t('connectionindicator.remoteaddress',
  757. { count: data.remoteIP.length })
  758. },
  759. {
  760. data: data.remotePort,
  761. key: 'remoteport',
  762. label: t('connectionindicator.remoteport',
  763. { count: transport.length })
  764. },
  765. {
  766. data: data.localIP,
  767. key: 'localaddress',
  768. label: t('connectionindicator.localaddress',
  769. { count: data.localIP.length })
  770. },
  771. {
  772. data: data.localPort,
  773. key: 'localport',
  774. label: t('connectionindicator.localport',
  775. { count: transport.length })
  776. },
  777. {
  778. data: data.transportType,
  779. key: 'transport',
  780. label: t('connectionindicator.transport',
  781. { count: data.transportType.length })
  782. }
  783. ];
  784. return tableRowConfigurations.map(this._renderTransportTableRow);
  785. }
  786. /**
  787. * Creates a table row as a ReactElement for displaying a transport related
  788. * statistic.
  789. *
  790. * @param {Object} config - Describes the contents of the row.
  791. * @param {ReactElement} config.additionalData - Extra data to display next
  792. * to the passed in config.data.
  793. * @param {Array} config.data - The transport statistics to display.
  794. * @param {string} config.key - The ReactElement's key. Must be unique for
  795. * iterating over multiple child rows.
  796. * @param {string} config.label - The text to display describing the data.
  797. * @private
  798. * @returns {ReactElement}
  799. */
  800. _renderTransportTableRow(config: any) {
  801. const { additionalData, data, key, label } = config;
  802. return (
  803. <tr key = { key }>
  804. <td>
  805. <span>
  806. { label }
  807. </span>
  808. </td>
  809. <td>
  810. { getStringFromArray(data) }
  811. { additionalData || null }
  812. </td>
  813. </tr>
  814. );
  815. }
  816. }
  817. /**
  818. * Utility for getting the IP from a transport statistics object's
  819. * representation of an IP.
  820. *
  821. * @param {string} value - The transport's IP to parse.
  822. * @private
  823. * @returns {string}
  824. */
  825. function getIP(value: string) {
  826. if (!value) {
  827. return '';
  828. }
  829. return value.substring(0, value.lastIndexOf(':'));
  830. }
  831. /**
  832. * Utility for getting the port from a transport statistics object's
  833. * representation of an IP.
  834. *
  835. * @param {string} value - The transport's IP to parse.
  836. * @private
  837. * @returns {string}
  838. */
  839. function getPort(value: string) {
  840. if (!value) {
  841. return '';
  842. }
  843. return value.substring(value.lastIndexOf(':') + 1, value.length);
  844. }
  845. /**
  846. * Utility for concatenating values in an array into a comma separated string.
  847. *
  848. * @param {Array} array - Transport statistics to concatenate.
  849. * @private
  850. * @returns {string}
  851. */
  852. function getStringFromArray(array: string[]) {
  853. let res = '';
  854. for (let i = 0; i < array.length; i++) {
  855. res += (i === 0 ? '' : ', ') + array[i];
  856. }
  857. return res;
  858. }
  859. export default translate(withStyles(styles)(ConnectionStatsTable));