mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Update WS deps after grist-core sync
Summary: Some WS-related code was touched in a recent PR to grist-core. This extends those changes to the rest of the codebase so that builds work again. Test Plan: N/A Reviewers: dsagal Reviewed By: dsagal Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D4224
This commit is contained in:
parent
b505d21e79
commit
c87d835533
@ -56,7 +56,8 @@ export class GristClientSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pause() and resume() are used for tests and assume a WS.WebSocket transport
|
// pause(), resume(), and isOpen() are only used by tests and assume
|
||||||
|
// a WS.WebSocket transport.
|
||||||
public pause() {
|
public pause() {
|
||||||
(this._wsSocket as WS.WebSocket)?.pause();
|
(this._wsSocket as WS.WebSocket)?.pause();
|
||||||
}
|
}
|
||||||
@ -65,6 +66,10 @@ export class GristClientSocket {
|
|||||||
(this._wsSocket as WS.WebSocket)?.resume();
|
(this._wsSocket as WS.WebSocket)?.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isOpen() {
|
||||||
|
return (this._wsSocket as WS.WebSocket)?.readyState === WS.OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
private _createWSSocket() {
|
private _createWSSocket() {
|
||||||
if (typeof WebSocket !== 'undefined') {
|
if (typeof WebSocket !== 'undefined') {
|
||||||
this._wsSocket = new WebSocket(this._url);
|
this._wsSocket = new WebSocket(this._url);
|
||||||
|
@ -330,6 +330,15 @@ export class GristWSConnection extends Disposable {
|
|||||||
this._reconnectAttempts++;
|
this._reconnectAttempts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let url: string;
|
||||||
|
try {
|
||||||
|
url = this._buildWebsocketUrl(isReconnecting, timezone);
|
||||||
|
} catch (e) {
|
||||||
|
this._warn('Failed to get the URL for the worker serving the document');
|
||||||
|
this._scheduleReconnect(isReconnecting);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Note that if a WebSocket can't establish a connection it will trigger onclose()
|
// Note that if a WebSocket can't establish a connection it will trigger onclose()
|
||||||
// As per http://dev.w3.org/html5/websockets/
|
// As per http://dev.w3.org/html5/websockets/
|
||||||
// "If the establish a WebSocket connection algorithm fails,
|
// "If the establish a WebSocket connection algorithm fails,
|
||||||
@ -337,7 +346,6 @@ export class GristWSConnection extends Disposable {
|
|||||||
// which then invokes the close the WebSocket connection algorithm,
|
// which then invokes the close the WebSocket connection algorithm,
|
||||||
// which then establishes that the WebSocket connection is closed,
|
// which then establishes that the WebSocket connection is closed,
|
||||||
// which fires the close event."
|
// which fires the close event."
|
||||||
const url = this._buildWebsocketUrl(isReconnecting, timezone);
|
|
||||||
this._log("GristWSConnection connecting to: " + url);
|
this._log("GristWSConnection connecting to: " + url);
|
||||||
this._ws = this._settings.makeWebSocket(url);
|
this._ws = this._settings.makeWebSocket(url);
|
||||||
|
|
||||||
@ -367,16 +375,20 @@ export class GristWSConnection extends Disposable {
|
|||||||
this.trigger('connectState', false);
|
this.trigger('connectState', false);
|
||||||
|
|
||||||
if (!this._wantReconnect) { return; }
|
if (!this._wantReconnect) { return; }
|
||||||
|
this._scheduleReconnect(true);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private _scheduleReconnect(isReconnecting: boolean) {
|
||||||
const reconnectTimeout = gutil.getReconnectTimeout(this._reconnectAttempts, reconnectInterval);
|
const reconnectTimeout = gutil.getReconnectTimeout(this._reconnectAttempts, reconnectInterval);
|
||||||
this._log("Trying to reconnect in", reconnectTimeout, "ms");
|
this._log('Trying to reconnect in', reconnectTimeout, 'ms');
|
||||||
this.trigger('connectionStatus', 'Trying to reconnect...', 'WARNING');
|
this.trigger('connectionStatus', 'Trying to reconnect...', 'WARNING');
|
||||||
this._reconnectTimeout = setTimeout(async () => {
|
this._reconnectTimeout = setTimeout(async () => {
|
||||||
this._reconnectTimeout = null;
|
this._reconnectTimeout = null;
|
||||||
// Make sure we've gotten through all lazy-loading.
|
// Make sure we've gotten through all lazy-loading.
|
||||||
await this._initialConnection;
|
await this._initialConnection;
|
||||||
await this.connect(true);
|
await this.connect(isReconnecting);
|
||||||
}, reconnectTimeout);
|
}, reconnectTimeout);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _buildWebsocketUrl(isReconnecting: boolean, timezone: any): string {
|
private _buildWebsocketUrl(isReconnecting: boolean, timezone: any): string {
|
||||||
|
@ -350,7 +350,7 @@ export function getEndUserProtocol(req: IncomingMessage) {
|
|||||||
}
|
}
|
||||||
// TODO we shouldn't blindly trust X-Forwarded-Proto. See the Express approach:
|
// TODO we shouldn't blindly trust X-Forwarded-Proto. See the Express approach:
|
||||||
// https://expressjs.com/en/5x/api.html#trust.proxy.options.table
|
// https://expressjs.com/en/5x/api.html#trust.proxy.options.table
|
||||||
return req.headers["x-forwarded-proto"] || ((req.socket as TLSSocket).encrypted ? 'https' : 'http');
|
return req.headers["x-forwarded-proto"] || ((req.socket as TLSSocket)?.encrypted ? 'https' : 'http');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user