1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
import * as React from 'react';
import { Component, Styles, Text, Types, View } from 'reactxp';
import { default as ConnectionInfoDisclosure } from './ConnectionInfoDisclosure';
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;
}
interface IOutAddress {
ipv4?: string;
ipv6?: string;
}
interface IProps {
hostname?: string;
inAddress?: IInAddress;
outAddress?: IOutAddress;
defaultOpen?: boolean;
style?: Types.ViewStyleRuleSet | Types.ViewStyleRuleSet[];
onToggle?: (isOpen: boolean) => void;
}
interface IState {
isOpen: boolean;
}
export default class ConnectionInfo extends Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {
isOpen: props.defaultOpen === true,
};
}
public render() {
const { inAddress, outAddress } = this.props;
return (
<View style={this.props.style}>
<View style={styles.header}>
<Text style={styles.hostname}>{this.props.hostname || ''}</Text>
<ConnectionInfoDisclosure defaultOpen={this.props.defaultOpen} onToggle={this.onToggle}>
{'Connection details'}
</ConnectionInfoDisclosure>
</View>
{this.state.isOpen && (
<React.Fragment>
{inAddress && (
<View style={styles.row}>
<Text style={styles.caption}>{'In'}</Text>
<Text style={styles.value}>
{`${inAddress.ip}:${inAddress.port} ${inAddress.protocol.toUpperCase()}`}
</Text>
</View>
)}
{outAddress && (outAddress.ipv4 || outAddress.ipv6) && (
<View style={styles.row}>
<Text style={styles.caption}>{'Out'}</Text>
<View>
{outAddress.ipv4 && <Text style={styles.value}>{outAddress.ipv4}</Text>}
{outAddress.ipv6 && <Text style={styles.value}>{outAddress.ipv6}</Text>}
</View>
</View>
)}
</React.Fragment>
)}
</View>
);
}
private onToggle = (isOpen: boolean) => {
this.setState(
(state) => ({ ...state, isOpen }),
() => {
if (this.props.onToggle) {
this.props.onToggle(isOpen);
}
},
);
};
}
|