@@ -2,23 +2,37 @@ import * as React from 'react';
2
2
import { useState , useEffect } from 'react' ;
3
3
import type { NativeStackScreenProps } from '@react-navigation/native-stack' ;
4
4
5
- import { StyleSheet , View , TextInput , Text , Button } from 'react-native' ;
5
+ import {
6
+ StyleSheet ,
7
+ View ,
8
+ TextInput ,
9
+ Text ,
10
+ Button ,
11
+ Switch ,
12
+ } from 'react-native' ;
6
13
import type { RootStackParamList } from './App' ;
7
14
import { useTheme } from '@react-navigation/native' ;
8
15
import AsyncStorage from '@react-native-async-storage/async-storage' ;
9
16
10
- const DEFAULT_URL = 'wss://www.example.com' ;
11
- const DEFAULT_TOKEN = '' ;
17
+ const DEFAULT_URL = 'ws://192.168.11.3:7880' ;
18
+ const DEFAULT_TOKEN =
19
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzU3ODc4OTYsImlzcyI6IkFQSVRMV3JLOHRid3I0NyIsIm5iZiI6MTczMzE5NTg5Niwic3ViIjoicGhvbmUiLCJ2aWRlbyI6eyJyb29tIjoibXlyb29tIiwicm9vbUpvaW4iOnRydWV9fQ.2ucoFK_t1rX8cnUVdx_7nS-TOGv_2Io6uNEw11kPs3M' ;
20
+ const DEFAULT_E2EE = false ;
21
+ const DEFAULT_E2EE_KEY = '' ;
12
22
13
23
const URL_KEY = 'url' ;
14
24
const TOKEN_KEY = 'token' ;
25
+ const E2EE_KEY = 'e2eeEnabled' ;
26
+ const E2EE_SHARED_KEY_KEY = 'e2eeSharedKey' ;
15
27
16
28
export const PreJoinPage = ( {
17
29
navigation,
18
30
} : NativeStackScreenProps < RootStackParamList , 'PreJoinPage' > ) => {
19
31
const [ url , setUrl ] = useState ( DEFAULT_URL ) ;
20
32
const [ token , setToken ] = useState ( DEFAULT_TOKEN ) ;
21
-
33
+ const [ e2eeEnabled , setE2EE ] = useState ( DEFAULT_E2EE ) ;
34
+ const [ e2eeKey , setE2EEKey ] = useState ( DEFAULT_E2EE_KEY ) ;
35
+ const toggleE2EE = ( ) => setE2EE ( ( previousState ) => ! previousState ) ;
22
36
useEffect ( ( ) => {
23
37
AsyncStorage . getItem ( URL_KEY ) . then ( ( value ) => {
24
38
if ( value ) {
@@ -31,14 +45,44 @@ export const PreJoinPage = ({
31
45
setToken ( value ) ;
32
46
}
33
47
} ) ;
48
+ AsyncStorage . getItem ( E2EE_KEY ) . then ( ( value ) => {
49
+ if ( value ) {
50
+ setE2EE ( value === 'true' ) ;
51
+ }
52
+ } ) ;
53
+ AsyncStorage . getItem ( E2EE_SHARED_KEY_KEY ) . then ( ( value ) => {
54
+ if ( value ) {
55
+ setE2EEKey ( value ) ;
56
+ }
57
+ } ) ;
34
58
} , [ ] ) ;
35
59
36
60
const { colors } = useTheme ( ) ;
37
61
38
- let saveValues = ( saveUrl : string , saveToken : string ) => {
62
+ let e2eeKeyInputTitle = < Text style = { { color : colors . text } } > E2EE Key</ Text > ;
63
+ let e2eeKeyInput = (
64
+ < TextInput
65
+ style = { {
66
+ color : colors . text ,
67
+ borderColor : colors . border ,
68
+ ...styles . input ,
69
+ } }
70
+ onChangeText = { setE2EEKey }
71
+ value = { e2eeKey }
72
+ />
73
+ ) ;
74
+ let saveValues = (
75
+ saveUrl : string ,
76
+ saveToken : string ,
77
+ saveE2EE : boolean ,
78
+ saveE2EEKey : string
79
+ ) => {
39
80
AsyncStorage . setItem ( URL_KEY , saveUrl ) ;
40
81
AsyncStorage . setItem ( TOKEN_KEY , saveToken ) ;
82
+ AsyncStorage . setItem ( E2EE_KEY , saveE2EE . toString ( ) ) ;
83
+ AsyncStorage . setItem ( E2EE_SHARED_KEY_KEY , saveE2EEKey ) ;
41
84
} ;
85
+
42
86
return (
43
87
< View style = { styles . container } >
44
88
< Text style = { { color : colors . text } } > URL</ Text >
@@ -63,10 +107,25 @@ export const PreJoinPage = ({
63
107
value = { token }
64
108
/>
65
109
110
+ < Text style = { { color : colors . text } } > Enable E2EE</ Text >
111
+ < Switch onValueChange = { toggleE2EE } value = { e2eeEnabled } />
112
+
113
+ < View style = { styles . spacer } />
114
+
115
+ { e2eeEnabled ? e2eeKeyInputTitle : null }
116
+ { e2eeEnabled ? e2eeKeyInput : null }
117
+
118
+ < View style = { styles . spacer } />
119
+
66
120
< Button
67
121
title = "Connect"
68
122
onPress = { ( ) => {
69
- navigation . push ( 'RoomPage' , { url : url , token : token } ) ;
123
+ navigation . push ( 'RoomPage' , {
124
+ url,
125
+ token,
126
+ e2ee : e2eeEnabled ,
127
+ e2eeKey,
128
+ } ) ;
70
129
} }
71
130
/>
72
131
@@ -75,7 +134,7 @@ export const PreJoinPage = ({
75
134
< Button
76
135
title = "Save Values"
77
136
onPress = { ( ) => {
78
- saveValues ( url , token ) ;
137
+ saveValues ( url , token , e2eeEnabled , e2eeKey ) ;
79
138
} }
80
139
/>
81
140
@@ -84,9 +143,16 @@ export const PreJoinPage = ({
84
143
< Button
85
144
title = "Reset Values"
86
145
onPress = { ( ) => {
87
- saveValues ( DEFAULT_URL , DEFAULT_TOKEN ) ;
146
+ saveValues (
147
+ DEFAULT_URL ,
148
+ DEFAULT_TOKEN ,
149
+ DEFAULT_E2EE ,
150
+ DEFAULT_E2EE_KEY
151
+ ) ;
88
152
setUrl ( DEFAULT_URL ) ;
89
153
setToken ( DEFAULT_TOKEN ) ;
154
+ setE2EE ( DEFAULT_E2EE ) ;
155
+ setE2EEKey ( DEFAULT_E2EE_KEY ) ;
90
156
} }
91
157
/>
92
158
</ View >
@@ -105,7 +171,7 @@ const styles = StyleSheet.create({
105
171
marginVertical : 20 ,
106
172
} ,
107
173
input : {
108
- width : '100 %' ,
174
+ width : '90 %' ,
109
175
height : 40 ,
110
176
margin : 12 ,
111
177
borderWidth : 1 ,
0 commit comments