我有我的应用程序,并且我希望用户在使用套接字通过注销消息到达该应用程序时注销,但是当我的应用程序处于后台运行时(意味着它未打开并且在最近的应用程序托盘中),它不会触发任何操作功能,什么也不做...
我用于构建网络套接字的代码
var ws = new WebSocket('wss://connect.websocket.in/v2');
ws.onopen = () => {
// connection opened
};
ws.onerror = e => {
// a message was received
console.log(e.data);
};
ws.onclose = e => {
// connection closed
console.log(e.code, e.reason);
};
ws.onmessage = ({ data }) => {
// an error occurred
if (IsJsonString(data)) {
if (!Array.isArray(data)) {
console.log(JSON.parse(data))
const message = JSON.parse(data)
if (message.function === 'NewUser') {
if (message.uuid === store.getState().user.uuid) {
logout()
Alert.alert('Alert', 'Someone else logged in with this Mobile Number.', [{ text: 'OK', onPress: () => Updates.reload() }], { cancelable: false })
}
}
}
else { console.log(data) }
}
else {
console.log(data)
}
};