Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ConnectionStatsTable.tsx 25KB

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