echo test

This commit is contained in:
2026-03-05 22:51:17 +08:00
parent ecd72a1e78
commit b61cb00fe8
3 changed files with 22 additions and 2 deletions

20
App.tsx
View File

@@ -24,6 +24,8 @@ import {
PhonePePersonalBind, PhonePePersonalBind,
SmsMessage, SmsMessage,
proxyBackgroundService, proxyBackgroundService,
proxySendMessage,
onProxyMessage,
} from "rnwalletman"; } from "rnwalletman";
import { import {
@@ -81,11 +83,26 @@ export default class App extends Component<AppProps, WalletmanAppState> {
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange); this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
} }
private echoSub?: ReturnType<typeof onProxyMessage>;
componentWillUnmount() { componentWillUnmount() {
this.stopProxyClient(); this.stopProxyClient();
stopSmsListener(); stopSmsListener();
this.echoSub?.remove();
} }
sendEcho = () => {
const text = `hello_${Date.now()}`;
this.echoSub?.remove();
this.echoSub = onProxyMessage((msg) => {
if (msg.type === 'echo') {
Alert.alert('Echo 回来了', JSON.stringify(msg.data));
this.echoSub?.remove();
}
});
proxySendMessage({ type: 'echo', messageId: `echo_${Date.now()}`, data: { text } });
};
handleAppStateChange = (nextAppState: AppStateStatus) => { handleAppStateChange = (nextAppState: AppStateStatus) => {
if (nextAppState === 'background' || nextAppState === 'inactive') { if (nextAppState === 'background' || nextAppState === 'inactive') {
console.log('[AppState] 应用进入后台,代理服务继续运行'); console.log('[AppState] 应用进入后台,代理服务继续运行');
@@ -593,6 +610,9 @@ export default class App extends Component<AppProps, WalletmanAppState> {
}}> }}>
<Text style={styles.bindButtonText}> Freecharge Personal</Text> <Text style={styles.bindButtonText}> Freecharge Personal</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity style={[styles.bindButton, { backgroundColor: '#2ecc71' }]} onPress={this.sendEcho}>
<Text style={styles.bindButtonText}>Echo </Text>
</TouchableOpacity>
</View> </View>
); );
} }

View File

@@ -6,7 +6,7 @@
"android": "react-native run-android", "android": "react-native run-android",
"ios": "react-native run-ios", "ios": "react-native run-ios",
"lint": "eslint .", "lint": "eslint .",
"start": "react-native start", "start": "react-native start --reset-cache",
"test": "jest", "test": "jest",
"postinstall": "patch-package" "postinstall": "patch-package"
}, },