import * as React from 'react'; import { Component, Styles, Text, Types, View } from 'reactxp'; import { proxyTypeToString, TunnelType, tunnelTypeToString } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import { default as ConnectionInfoDisclosure } from './ConnectionInfoDisclosure'; import { IBridgeData } from './TunnelControl'; const styles = { row: Styles.createViewStyle({ flexDirection: 'row', marginTop: 3, }), caption: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 13, fontWeight: '600', color: 'rgb(255, 255, 255)', flex: 0, flexBasis: 30, marginRight: 8, }), value: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 13, fontWeight: '600', color: 'rgb(255, 255, 255)', letterSpacing: -0.2, }), header: Styles.createViewStyle({ flexDirection: 'row', alignItems: 'center', }), hostname: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 16, lineHeight: 20, fontWeight: '600', color: 'rgb(255, 255, 255)', flex: 1, }), }; interface IInAddress { ip: string; port: number; protocol: string; tunnelType: TunnelType; } interface IOutAddress { ipv4?: string; ipv6?: string; } interface IProps { hostname?: string; bridgeHostname?: string; inAddress?: IInAddress; bridgeInfo?: IBridgeData; outAddress?: IOutAddress; defaultOpen?: boolean; style?: Types.ViewStyleRuleSet | Types.ViewStyleRuleSet[]; onToggle?: (isOpen: boolean) => void; } interface IState { isOpen: boolean; } export default class ConnectionInfo extends Component { constructor(props: IProps) { super(props); this.state = { isOpen: props.defaultOpen === true, }; } public render() { const { inAddress, outAddress, bridgeInfo } = this.props; const transportLine = (inAddress ? tunnelTypeToString(inAddress.tunnelType) : '') + (bridgeInfo && inAddress ? ' via ' + proxyTypeToString(bridgeInfo.bridgeType) : ''); const entryPoint = bridgeInfo && inAddress ? bridgeInfo : inAddress; return ( {this.props.hostname || ''}{' '} {this.props.bridgeHostname ? `via ${this.props.bridgeHostname}` : ''} {this.state.isOpen && ( {this.props.inAddress && ( {{transportLine}} )} {entryPoint && ( {messages.pgettext('connection-info', 'In')} {`${entryPoint.ip}:${entryPoint.port} ${entryPoint.protocol.toUpperCase()}`} )} {outAddress && (outAddress.ipv4 || outAddress.ipv6) && ( {messages.pgettext('connection-info', 'Out')} {outAddress.ipv4 && {outAddress.ipv4}} {outAddress.ipv6 && {outAddress.ipv6}} )} )} ); } private onToggle = (isOpen: boolean) => { this.setState( (state) => ({ ...state, isOpen }), () => { if (this.props.onToggle) { this.props.onToggle(isOpen); } }, ); }; }