選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ConnectionStatsTable.tsx 24KB

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