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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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 = clsx(classes.connectionStatsTable, { [classes.mobile]: isMobileBrowser() });
  247. return (<ContextMenu
  248. className = { classes.contextMenu }
  249. hidden = { false }
  250. inDrawer = { true }>
  251. <div
  252. className = { className }
  253. onClick = { onClick }>
  254. <tbody>
  255. { this._renderResolution() }
  256. { this._renderFrameRate() }
  257. </tbody>
  258. </div>
  259. </ContextMenu>);
  260. }
  261. /**
  262. * Creates a table as ReactElement that will display additional statistics
  263. * related to bandwidth and transport for the local user.
  264. *
  265. * @private
  266. * @returns {ReactElement}
  267. */
  268. _renderAdditionalStats() {
  269. const { isLocalVideo } = this.props;
  270. return (
  271. <table>
  272. <tbody>
  273. { isLocalVideo ? this._renderBandwidth() : null }
  274. { isLocalVideo ? this._renderTransport() : null }
  275. { isLocalVideo ? this._renderRegion() : null }
  276. { this._renderAudioSsrc() }
  277. { this._renderVideoSsrc() }
  278. { this._renderParticipantId() }
  279. </tbody>
  280. </table>
  281. );
  282. }
  283. /**
  284. * Creates a table row as a ReactElement for displaying bandwidth related
  285. * statistics.
  286. *
  287. * @private
  288. * @returns {ReactElement}
  289. */
  290. _renderBandwidth() {
  291. const { classes } = this.props;
  292. const { download, upload } = this.props.bandwidth || {};
  293. return (
  294. <tr>
  295. <td>
  296. { this.props.t('connectionindicator.bandwidth') }
  297. </td>
  298. <td>
  299. <span className = { classes.download }>
  300. &darr;
  301. </span>
  302. { download ? `${download} Kbps` : 'N/A' }
  303. <span className = { classes.upload }>
  304. &uarr;
  305. </span>
  306. { upload ? `${upload} Kbps` : 'N/A' }
  307. </td>
  308. </tr>
  309. );
  310. }
  311. /**
  312. * Creates a a table row as a ReactElement for displaying bitrate related
  313. * statistics.
  314. *
  315. * @private
  316. * @returns {ReactElement}
  317. */
  318. _renderBitrate() {
  319. const { classes } = this.props;
  320. const { download, upload } = this.props.bitrate || {};
  321. return (
  322. <tr>
  323. <td>
  324. <span>
  325. { this.props.t('connectionindicator.bitrate') }
  326. </span>
  327. </td>
  328. <td>
  329. <span className = { classes.download }>
  330. &darr;
  331. </span>
  332. { download ? `${download} Kbps` : 'N/A' }
  333. <span className = { classes.upload }>
  334. &uarr;
  335. </span>
  336. { upload ? `${upload} Kbps` : 'N/A' }
  337. </td>
  338. </tr>
  339. );
  340. }
  341. /**
  342. * Creates a table row as a ReactElement for displaying the audio ssrc.
  343. * This will typically be something like "Audio SSRC: 12345".
  344. *
  345. * @returns {JSX.Element}
  346. * @private
  347. */
  348. _renderAudioSsrc() {
  349. const { audioSsrc, t } = this.props;
  350. return (
  351. <tr>
  352. <td>
  353. <span>{ t('connectionindicator.audio_ssrc') }</span>
  354. </td>
  355. <td>{ audioSsrc || 'N/A' }</td>
  356. </tr>
  357. );
  358. }
  359. /**
  360. * Creates a table row as a ReactElement for displaying the video ssrc.
  361. * This will typically be something like "Video SSRC: 12345".
  362. *
  363. * @returns {JSX.Element}
  364. * @private
  365. */
  366. _renderVideoSsrc() {
  367. const { videoSsrc, t } = this.props;
  368. return (
  369. <tr>
  370. <td>
  371. <span>{ t('connectionindicator.video_ssrc') }</span>
  372. </td>
  373. <td>{ videoSsrc || 'N/A' }</td>
  374. </tr>
  375. );
  376. }
  377. /**
  378. * Creates a table row as a ReactElement for displaying the endpoint id.
  379. * This will typically be something like "Endpoint id: 1e8fbg".
  380. *
  381. * @returns {JSX.Element}
  382. * @private
  383. */
  384. _renderParticipantId() {
  385. const { participantId, t } = this.props;
  386. return (
  387. <tr>
  388. <td>
  389. <span>{ t('connectionindicator.participant_id') }</span>
  390. </td>
  391. <td>{ participantId || 'N/A' }</td>
  392. </tr>
  393. );
  394. }
  395. /**
  396. * Creates a a table row as a ReactElement for displaying codec, if present.
  397. * This will typically be something like "Codecs (A/V): Opus, vp8".
  398. *
  399. * @private
  400. * @returns {ReactElement}
  401. */
  402. _renderCodecs() {
  403. const { codec, t, sourceNameSignalingEnabled } = this.props;
  404. if (!codec) {
  405. return;
  406. }
  407. let codecString;
  408. if (sourceNameSignalingEnabled) {
  409. codecString = `${codec.audio}, ${codec.video}`;
  410. } else {
  411. // Only report one codec, in case there are multiple for a user.
  412. Object.keys(codec || {})
  413. .forEach(ssrc => {
  414. const { audio, video } = codec[ssrc];
  415. codecString = `${audio}, ${video}`;
  416. });
  417. }
  418. if (!codecString) {
  419. codecString = 'N/A';
  420. }
  421. return (
  422. <tr>
  423. <td>
  424. <span>{ t('connectionindicator.codecs') }</span>
  425. </td>
  426. <td>{ codecString }</td>
  427. </tr>
  428. );
  429. }
  430. /**
  431. * Creates a table row as a ReactElement for displaying a summary message
  432. * about the current connection status.
  433. *
  434. * @private
  435. * @returns {ReactElement}
  436. */
  437. _renderConnectionSummary() {
  438. const { classes } = this.props;
  439. return (
  440. <tr className = { classes.status }>
  441. <td>
  442. <span>{ this.props.t('connectionindicator.status') }</span>
  443. </td>
  444. <td>{ this.props.connectionSummary }</td>
  445. </tr>
  446. );
  447. }
  448. /**
  449. * Creates a table row as a ReactElement for displaying end-to-end RTT and
  450. * the region.
  451. *
  452. * @returns {ReactElement}
  453. * @private
  454. */
  455. _renderE2eRtt() {
  456. const { e2eRtt, t } = this.props;
  457. const str = e2eRtt ? `${e2eRtt.toFixed(0)}ms` : 'N/A';
  458. return (
  459. <tr>
  460. <td>
  461. <span>{ t('connectionindicator.e2e_rtt') }</span>
  462. </td>
  463. <td>{ str }</td>
  464. </tr>
  465. );
  466. }
  467. /**
  468. * Creates a table row as a ReactElement for displaying the "connected to"
  469. * information.
  470. *
  471. * @returns {ReactElement}
  472. * @private
  473. */
  474. _renderRegion() {
  475. const { region, serverRegion, t } = this.props;
  476. let str = serverRegion;
  477. if (!serverRegion) {
  478. return;
  479. }
  480. if (region && serverRegion && region !== serverRegion) {
  481. str += ` from ${region}`;
  482. }
  483. return (
  484. <tr>
  485. <td>
  486. <span>{ t('connectionindicator.connectedTo') }</span>
  487. </td>
  488. <td>{ str }</td>
  489. </tr>
  490. );
  491. }
  492. /**
  493. * Creates a table row as a ReactElement for displaying the "bridge count"
  494. * information.
  495. *
  496. * @returns {*}
  497. * @private
  498. */
  499. _renderBridgeCount() {
  500. const { bridgeCount, t } = this.props;
  501. // 0 is valid, but undefined/null/NaN aren't.
  502. if (!bridgeCount && bridgeCount !== 0) {
  503. return;
  504. }
  505. return (
  506. <tr>
  507. <td>
  508. <span>{ t('connectionindicator.bridgeCount') }</span>
  509. </td>
  510. <td>{ bridgeCount }</td>
  511. </tr>
  512. );
  513. }
  514. /**
  515. * Creates a table row as a ReactElement for displaying frame rate related
  516. * statistics.
  517. *
  518. * @private
  519. * @returns {ReactElement}
  520. */
  521. _renderFrameRate() {
  522. const { framerate, t, sourceNameSignalingEnabled } = this.props;
  523. let frameRateString;
  524. if (sourceNameSignalingEnabled) {
  525. frameRateString = framerate || 'N/A';
  526. } else {
  527. frameRateString = Object.keys(framerate || {})
  528. .map(ssrc => framerate[ssrc])
  529. .join(', ') || 'N/A';
  530. }
  531. return (
  532. <tr>
  533. <td>
  534. <span>{ t('connectionindicator.framerate') }</span>
  535. </td>
  536. <td>{ frameRateString }</td>
  537. </tr>
  538. );
  539. }
  540. /**
  541. * Creates a tables row as a ReactElement for displaying packet loss related
  542. * statistics.
  543. *
  544. * @private
  545. * @returns {ReactElement}
  546. */
  547. _renderPacketLoss() {
  548. const { classes, packetLoss, t } = this.props;
  549. let packetLossTableData;
  550. if (packetLoss) {
  551. const { download, upload } = packetLoss;
  552. packetLossTableData = (
  553. <td>
  554. <span className = { classes.download }>
  555. &darr;
  556. </span>
  557. { download === null ? 'N/A' : `${download}%` }
  558. <span className = { classes.upload }>
  559. &uarr;
  560. </span>
  561. { upload === null ? 'N/A' : `${upload}%` }
  562. </td>
  563. );
  564. } else {
  565. packetLossTableData = <td>N/A</td>;
  566. }
  567. return (
  568. <tr>
  569. <td>
  570. <span>
  571. { t('connectionindicator.packetloss') }
  572. </span>
  573. </td>
  574. { packetLossTableData }
  575. </tr>
  576. );
  577. }
  578. /**
  579. * Creates a table row as a ReactElement for displaying resolution related
  580. * statistics.
  581. *
  582. * @private
  583. * @returns {ReactElement}
  584. */
  585. _renderResolution() {
  586. const { resolution, maxEnabledResolution, t, sourceNameSignalingEnabled } = this.props;
  587. let resolutionString;
  588. if (sourceNameSignalingEnabled) {
  589. resolutionString = resolution ? `${resolution.width}x${resolution.height}` : 'N/A';
  590. } else {
  591. resolutionString = Object.keys(resolution || {})
  592. .map(ssrc => {
  593. const { width, height } = resolution[ssrc];
  594. return `${width}x${height}`;
  595. })
  596. .join(', ') || 'N/A';
  597. }
  598. if (maxEnabledResolution && maxEnabledResolution < 720) {
  599. const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
  600. resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
  601. }
  602. return (
  603. <tr>
  604. <td>
  605. <span>{ t('connectionindicator.resolution') }</span>
  606. </td>
  607. <td>{ resolutionString }</td>
  608. </tr>
  609. );
  610. }
  611. /**
  612. * Creates a ReactElement for display a link to save the logs.
  613. *
  614. * @private
  615. * @returns {ReactElement}
  616. */
  617. _renderSaveLogs() {
  618. return (
  619. <span>
  620. <a
  621. className = 'savelogs link'
  622. onClick = { this.props.onSaveLogs }
  623. role = 'button'
  624. tabIndex = { 0 }>
  625. { this.props.t('connectionindicator.savelogs') }
  626. </a>
  627. <span> | </span>
  628. </span>
  629. );
  630. }
  631. /**
  632. * Creates a ReactElement for display a link to toggle showing additional
  633. * statistics.
  634. *
  635. * @private
  636. * @returns {ReactElement}
  637. */
  638. _renderShowMoreLink() {
  639. const translationKey
  640. = this.props.shouldShowMore
  641. ? 'connectionindicator.less'
  642. : 'connectionindicator.more';
  643. return (
  644. <a
  645. className = 'showmore link'
  646. onClick = { this.props.onShowMore }
  647. role = 'button'
  648. tabIndex = { 0 }>
  649. { this.props.t(translationKey) }
  650. </a>
  651. );
  652. }
  653. /**
  654. * Creates a table as a ReactElement for displaying connection statistics.
  655. *
  656. * @private
  657. * @returns {ReactElement}
  658. */
  659. _renderStatistics() {
  660. const isRemoteVideo = !this.props.isLocalVideo;
  661. return (
  662. <table>
  663. <tbody>
  664. { this._renderConnectionSummary() }
  665. { this._renderBitrate() }
  666. { this._renderPacketLoss() }
  667. { isRemoteVideo ? this._renderE2eRtt() : null }
  668. { isRemoteVideo ? this._renderRegion() : null }
  669. { this._renderResolution() }
  670. { this._renderFrameRate() }
  671. { this._renderCodecs() }
  672. { isRemoteVideo ? null : this._renderBridgeCount() }
  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: [],
  701. localPort: [],
  702. remoteIP: [],
  703. remotePort: [],
  704. transportType: []
  705. };
  706. for (let i = 0; i < transport.length; i++) {
  707. const ip = getIP(transport[i].ip);
  708. const localIP = getIP(transport[i].localip);
  709. const localPort = getPort(transport[i].localip);
  710. const port = getPort(transport[i].ip);
  711. if (!data.remoteIP.includes(ip)) {
  712. data.remoteIP.push(ip);
  713. }
  714. if (!data.localIP.includes(localIP)) {
  715. data.localIP.push(localIP);
  716. }
  717. if (!data.localPort.includes(localPort)) {
  718. data.localPort.push(localPort);
  719. }
  720. if (!data.remotePort.includes(port)) {
  721. data.remotePort.push(port);
  722. }
  723. if (!data.transportType.includes(transport[i].type)) {
  724. data.transportType.push(transport[i].type);
  725. }
  726. }
  727. // All of the transports should be either P2P or JVB
  728. let isP2P = false, isTURN = false;
  729. if (transport.length) {
  730. isP2P = transport[0].p2p;
  731. isTURN = transport[0].localCandidateType === 'relay'
  732. || transport[0].remoteCandidateType === 'relay';
  733. }
  734. const additionalData = [];
  735. if (isP2P) {
  736. additionalData.push(
  737. <span> (p2p)</span>);
  738. }
  739. if (isTURN) {
  740. additionalData.push(<span> (turn)</span>);
  741. }
  742. // First show remote statistics, then local, and then transport type.
  743. const tableRowConfigurations = [
  744. {
  745. additionalData,
  746. data: data.remoteIP,
  747. key: 'remoteaddress',
  748. label: t('connectionindicator.remoteaddress',
  749. { count: data.remoteIP.length })
  750. },
  751. {
  752. data: data.remotePort,
  753. key: 'remoteport',
  754. label: t('connectionindicator.remoteport',
  755. { count: transport.length })
  756. },
  757. {
  758. data: data.localIP,
  759. key: 'localaddress',
  760. label: t('connectionindicator.localaddress',
  761. { count: data.localIP.length })
  762. },
  763. {
  764. data: data.localPort,
  765. key: 'localport',
  766. label: t('connectionindicator.localport',
  767. { count: transport.length })
  768. },
  769. {
  770. data: data.transportType,
  771. key: 'transport',
  772. label: t('connectionindicator.transport',
  773. { count: data.transportType.length })
  774. }
  775. ];
  776. return tableRowConfigurations.map(this._renderTransportTableRow);
  777. }
  778. /**
  779. * Creates a table row as a ReactElement for displaying a transport related
  780. * statistic.
  781. *
  782. * @param {Object} config - Describes the contents of the row.
  783. * @param {ReactElement} config.additionalData - Extra data to display next
  784. * to the passed in config.data.
  785. * @param {Array} config.data - The transport statistics to display.
  786. * @param {string} config.key - The ReactElement's key. Must be unique for
  787. * iterating over multiple child rows.
  788. * @param {string} config.label - The text to display describing the data.
  789. * @private
  790. * @returns {ReactElement}
  791. */
  792. _renderTransportTableRow(config: Object) {
  793. const { additionalData, data, key, label } = config;
  794. return (
  795. <tr key = { key }>
  796. <td>
  797. <span>
  798. { label }
  799. </span>
  800. </td>
  801. <td>
  802. { getStringFromArray(data) }
  803. { additionalData || null }
  804. </td>
  805. </tr>
  806. );
  807. }
  808. }
  809. /**
  810. * Utility for getting the IP from a transport statistics object's
  811. * representation of an IP.
  812. *
  813. * @param {string} value - The transport's IP to parse.
  814. * @private
  815. * @returns {string}
  816. */
  817. function getIP(value) {
  818. if (!value) {
  819. return '';
  820. }
  821. return value.substring(0, value.lastIndexOf(':'));
  822. }
  823. /**
  824. * Utility for getting the port from a transport statistics object's
  825. * representation of an IP.
  826. *
  827. * @param {string} value - The transport's IP to parse.
  828. * @private
  829. * @returns {string}
  830. */
  831. function getPort(value) {
  832. if (!value) {
  833. return '';
  834. }
  835. return value.substring(value.lastIndexOf(':') + 1, value.length);
  836. }
  837. /**
  838. * Utility for concatenating values in an array into a comma separated string.
  839. *
  840. * @param {Array} array - Transport statistics to concatenate.
  841. * @private
  842. * @returns {string}
  843. */
  844. function getStringFromArray(array) {
  845. let res = '';
  846. for (let i = 0; i < array.length; i++) {
  847. res += (i === 0 ? '' : ', ') + array[i];
  848. }
  849. return res;
  850. }
  851. export default translate(withStyles(styles)(ConnectionStatsTable));