Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ConnectionStatsTable.tsx 25KB

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