[FIX] Handle disconnect and reconnect properly (#1131)
This commit is contained in:
parent
047a0ddf8d
commit
5bb477d00e
|
@ -11,38 +11,14 @@ const removeListener = listener => listener.stop();
|
||||||
|
|
||||||
export default function subscribeRoom({ rid }) {
|
export default function subscribeRoom({ rid }) {
|
||||||
let promises;
|
let promises;
|
||||||
let timer = null;
|
|
||||||
let connectedListener;
|
let connectedListener;
|
||||||
let disconnectedListener;
|
let disconnectedListener;
|
||||||
let notifyRoomListener;
|
let notifyRoomListener;
|
||||||
let messageReceivedListener;
|
let messageReceivedListener;
|
||||||
const typingTimeouts = {};
|
const typingTimeouts = {};
|
||||||
const loop = () => {
|
|
||||||
if (timer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timer = setTimeout(() => {
|
|
||||||
try {
|
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
this.loadMissedMessages({ rid });
|
|
||||||
loop();
|
|
||||||
} catch (e) {
|
|
||||||
loop();
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConnected = () => {
|
const handleConnection = () => {
|
||||||
this.loadMissedMessages({ rid });
|
this.loadMissedMessages({ rid });
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDisconnected = () => {
|
|
||||||
if (this.sdk.userId) {
|
|
||||||
loop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserTyping = username => (
|
const getUserTyping = username => (
|
||||||
|
@ -176,8 +152,6 @@ export default function subscribeRoom({ rid }) {
|
||||||
messageReceivedListener.then(removeListener);
|
messageReceivedListener.then(removeListener);
|
||||||
messageReceivedListener = false;
|
messageReceivedListener = false;
|
||||||
}
|
}
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
Object.keys(typingTimeouts).forEach((key) => {
|
Object.keys(typingTimeouts).forEach((key) => {
|
||||||
if (typingTimeouts[key]) {
|
if (typingTimeouts[key]) {
|
||||||
clearTimeout(typingTimeouts[key]);
|
clearTimeout(typingTimeouts[key]);
|
||||||
|
@ -190,8 +164,8 @@ export default function subscribeRoom({ rid }) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
connectedListener = this.sdk.onStreamData('connected', handleConnected);
|
connectedListener = this.sdk.onStreamData('connected', handleConnection);
|
||||||
disconnectedListener = this.sdk.onStreamData('close', handleDisconnected);
|
disconnectedListener = this.sdk.onStreamData('close', handleConnection);
|
||||||
notifyRoomListener = this.sdk.onStreamData('stream-notify-room', handleNotifyRoomReceived);
|
notifyRoomListener = this.sdk.onStreamData('stream-notify-room', handleNotifyRoomReceived);
|
||||||
messageReceivedListener = this.sdk.onStreamData('stream-room-messages', handleMessageReceived);
|
messageReceivedListener = this.sdk.onStreamData('stream-room-messages', handleMessageReceived);
|
||||||
|
|
||||||
|
|
|
@ -16,29 +16,8 @@ let streamListener;
|
||||||
let subServer;
|
let subServer;
|
||||||
|
|
||||||
export default function subscribeRooms() {
|
export default function subscribeRooms() {
|
||||||
let timer = null;
|
const handleConnection = () => {
|
||||||
const loop = () => {
|
|
||||||
if (timer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timer = setTimeout(() => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
store.dispatch(roomsRequest());
|
|
||||||
loop();
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConnected = () => {
|
|
||||||
store.dispatch(roomsRequest());
|
store.dispatch(roomsRequest());
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDisconnected = () => {
|
|
||||||
if (this.sdk.userId) {
|
|
||||||
loop();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStreamMessageReceived = protectedFunction((ddpMessage) => {
|
const handleStreamMessageReceived = protectedFunction((ddpMessage) => {
|
||||||
|
@ -145,12 +124,10 @@ export default function subscribeRooms() {
|
||||||
streamListener.then(removeListener);
|
streamListener.then(removeListener);
|
||||||
streamListener = false;
|
streamListener = false;
|
||||||
}
|
}
|
||||||
clearTimeout(timer);
|
|
||||||
timer = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connectedListener = this.sdk.onStreamData('connected', handleConnected);
|
connectedListener = this.sdk.onStreamData('connected', handleConnection);
|
||||||
disconnectedListener = this.sdk.onStreamData('close', handleDisconnected);
|
disconnectedListener = this.sdk.onStreamData('close', handleConnection);
|
||||||
streamListener = this.sdk.onStreamData('stream-notify-user', handleStreamMessageReceived);
|
streamListener = this.sdk.onStreamData('stream-notify-user', handleStreamMessageReceived);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rocket.chat/sdk": "1.0.0-alpha.28",
|
"@rocket.chat/sdk": "1.0.0-alpha.30",
|
||||||
"deep-equal": "^1.0.1",
|
"deep-equal": "^1.0.1",
|
||||||
"ejson": "2.2.0",
|
"ejson": "2.2.0",
|
||||||
"expo-haptics": "^6.0.0",
|
"expo-haptics": "^6.0.0",
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
diff --git a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
|
||||||
|
index 6f1e5e8..b835657 100644
|
||||||
|
--- a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
|
||||||
|
+++ b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
|
||||||
|
@@ -595,6 +595,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ [self.delegate webSocket:self didCloseWithCode:code reason:reason wasClean:YES];
|
||||||
|
[self _sendFrameWithOpcode:RCTSROpCodeConnectionClose data:payload];
|
||||||
|
});
|
||||||
|
}
|
||||||
diff --git a/node_modules/react-native/React/Modules/RCTRedBox.m b/node_modules/react-native/React/Modules/RCTRedBox.m
|
diff --git a/node_modules/react-native/React/Modules/RCTRedBox.m b/node_modules/react-native/React/Modules/RCTRedBox.m
|
||||||
index 7ed4900..bb85402 100644
|
index 7ed4900..bb85402 100644
|
||||||
--- a/node_modules/react-native/React/Modules/RCTRedBox.m
|
--- a/node_modules/react-native/React/Modules/RCTRedBox.m
|
||||||
|
@ -10,4 +22,4 @@ index 7ed4900..bb85402 100644
|
||||||
+ return RCTSharedApplication().delegate.window.safeAreaInsets.bottom;
|
+ return RCTSharedApplication().delegate.window.safeAreaInsets.bottom;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
12
yarn.lock
12
yarn.lock
|
@ -1347,10 +1347,10 @@
|
||||||
resolved "https://registry.yarnpkg.com/@redux-saga/types/-/types-1.0.2.tgz#1d94f02800b094753f9271c206a26c2a06ca14ee"
|
resolved "https://registry.yarnpkg.com/@redux-saga/types/-/types-1.0.2.tgz#1d94f02800b094753f9271c206a26c2a06ca14ee"
|
||||||
integrity sha512-8/qcMh15507AnXJ3lBeuhsdFwnWQqnp68EpUuHlYPixJ5vjVmls7/Jq48cnUlrZI8Jd9U1jkhfCl0gaT5KMgVw==
|
integrity sha512-8/qcMh15507AnXJ3lBeuhsdFwnWQqnp68EpUuHlYPixJ5vjVmls7/Jq48cnUlrZI8Jd9U1jkhfCl0gaT5KMgVw==
|
||||||
|
|
||||||
"@rocket.chat/sdk@1.0.0-alpha.28":
|
"@rocket.chat/sdk@1.0.0-alpha.30":
|
||||||
version "1.0.0-alpha.28"
|
version "1.0.0-alpha.30"
|
||||||
resolved "https://registry.yarnpkg.com/@rocket.chat/sdk/-/sdk-1.0.0-alpha.28.tgz#569f3c578c5c12ed54a9317d36fa8413208ce021"
|
resolved "https://registry.yarnpkg.com/@rocket.chat/sdk/-/sdk-1.0.0-alpha.30.tgz#fabfab601892bde9c9277a8aae92e88da770d64e"
|
||||||
integrity sha512-tQ+tIIX5R931cxIlTTn2ftCfiIo372vCG3omzDwzSfw6Kq24f7giUxVEpWfsI4GtuTU4caoren7wuGYwnST/+A==
|
integrity sha512-beKIoCw0XLjN8dcusqwBiS1hCVKE+y1IzpRYHUtNciS5LhOPujLUwrzF+pys2xkia5TohbRlsbNYlXPehvSHLQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/event-emitter" "^0.3.2"
|
"@types/event-emitter" "^0.3.2"
|
||||||
"@types/eventemitter3" "^2.0.2"
|
"@types/eventemitter3" "^2.0.2"
|
||||||
|
@ -8754,9 +8754,9 @@ pad-component@0.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/pad-component/-/pad-component-0.0.1.tgz#ad1f22ce1bf0fdc0d6ddd908af17f351a404b8ac"
|
resolved "https://registry.yarnpkg.com/pad-component/-/pad-component-0.0.1.tgz#ad1f22ce1bf0fdc0d6ddd908af17f351a404b8ac"
|
||||||
integrity sha1-rR8izhvw/cDW3dkIrxfzUaQEuKw=
|
integrity sha1-rR8izhvw/cDW3dkIrxfzUaQEuKw=
|
||||||
|
|
||||||
paho-mqtt@eclipse/paho.mqtt.javascript#master:
|
"paho-mqtt@github:eclipse/paho.mqtt.javascript#master":
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://codeload.github.com/eclipse/paho.mqtt.javascript/tar.gz/9b761defeeb4a627db31d92ae1b0ca91b44b226e"
|
resolved "https://codeload.github.com/eclipse/paho.mqtt.javascript/tar.gz/f5859463aba9a9b7c19f99ab7c4849a723f8d832"
|
||||||
|
|
||||||
pako@~1.0.2:
|
pako@~1.0.2:
|
||||||
version "1.0.8"
|
version "1.0.8"
|
||||||
|
|
Loading…
Reference in New Issue