You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectionStatsTable.js 25KB

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