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,
SmsMessage,
proxyBackgroundService,
proxySendMessage,
onProxyMessage,
} from "rnwalletman";
import {
@@ -81,11 +83,26 @@ export default class App extends Component<AppProps, WalletmanAppState> {
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
}
private echoSub?: ReturnType<typeof onProxyMessage>;
componentWillUnmount() {
this.stopProxyClient();
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) => {
if (nextAppState === 'background' || nextAppState === 'inactive') {
console.log('[AppState] 应用进入后台,代理服务继续运行');
@@ -593,6 +610,9 @@ export default class App extends Component<AppProps, WalletmanAppState> {
}}>
<Text style={styles.bindButtonText}> Freecharge Personal</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.bindButton, { backgroundColor: '#2ecc71' }]} onPress={this.sendEcho}>
<Text style={styles.bindButtonText}>Echo </Text>
</TouchableOpacity>
</View>
);
}