Initialize and close WebSocket more accurately and consistently (#3683)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
199c55b566
Коммит
fc7ae6ba65
@@ -10,7 +10,6 @@ export default class WebSocketClient {
|
|||||||
this.conn = null;
|
this.conn = null;
|
||||||
this.sequence = 1;
|
this.sequence = 1;
|
||||||
this.connectFailCount = 0;
|
this.connectFailCount = 0;
|
||||||
this.manuallyClosed = false;
|
|
||||||
this.eventCallback = null;
|
this.eventCallback = null;
|
||||||
this.responseCallbacks = {};
|
this.responseCallbacks = {};
|
||||||
this.reconnectCallback = null;
|
this.reconnectCallback = null;
|
||||||
@@ -27,8 +26,6 @@ export default class WebSocketClient {
|
|||||||
console.log('websocket connecting to ' + connectionUrl); //eslint-disable-line no-console
|
console.log('websocket connecting to ' + connectionUrl); //eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
this.manuallyClosed = false;
|
|
||||||
|
|
||||||
this.conn = new WebSocket(connectionUrl);
|
this.conn = new WebSocket(connectionUrl);
|
||||||
|
|
||||||
this.conn.onopen = () => {
|
this.conn.onopen = () => {
|
||||||
@@ -51,10 +48,6 @@ export default class WebSocketClient {
|
|||||||
console.log('websocket closed'); //eslint-disable-line no-console
|
console.log('websocket closed'); //eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.manuallyClosed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectFailCount++;
|
this.connectFailCount++;
|
||||||
|
|
||||||
if (this.closeCallback) {
|
if (this.closeCallback) {
|
||||||
@@ -124,11 +117,13 @@ export default class WebSocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.manuallyClosed = true;
|
|
||||||
this.connectFailCount = 0;
|
this.connectFailCount = 0;
|
||||||
this.sequence = 1;
|
this.sequence = 1;
|
||||||
if (this.conn && this.conn.readyState === WebSocket.OPEN) {
|
if (this.conn && this.conn.readyState === WebSocket.OPEN) {
|
||||||
|
this.conn.onclose = () => {}; //eslint-disable-line no-empty-function
|
||||||
this.conn.close();
|
this.conn.close();
|
||||||
|
this.conn = null;
|
||||||
|
console.log('websocket closed'); //eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ export default class LoggedIn extends React.Component {
|
|||||||
this.onUserChanged = this.onUserChanged.bind(this);
|
this.onUserChanged = this.onUserChanged.bind(this);
|
||||||
this.setupUser = this.setupUser.bind(this);
|
this.setupUser = this.setupUser.bind(this);
|
||||||
|
|
||||||
// Initalize websocket
|
|
||||||
WebSocketActions.initialize();
|
|
||||||
|
|
||||||
// Force logout of all tabs if one tab is logged out
|
// Force logout of all tabs if one tab is logged out
|
||||||
$(window).bind('storage', (e) => {
|
$(window).bind('storage', (e) => {
|
||||||
// when one tab on a browser logs out, it sets __logout__ in localStorage to trigger other tabs to log out
|
// when one tab on a browser logs out, it sets __logout__ in localStorage to trigger other tabs to log out
|
||||||
@@ -105,6 +102,9 @@ export default class LoggedIn extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
// Initalize websocket
|
||||||
|
WebSocketActions.initialize();
|
||||||
|
|
||||||
// Listen for user
|
// Listen for user
|
||||||
UserStore.addChangeListener(this.onUserChanged);
|
UserStore.addChangeListener(this.onUserChanged);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user