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 26KB

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