perf: Attempt websocket connection before polling

This commit is contained in:
Tom Moor
2020-08-14 13:37:11 -07:00
parent 174acfac32
commit d3350c20b6

View File

@ -36,7 +36,11 @@ class SocketProvider extends React.Component<Props> {
componentDidMount() {
this.socket = io(window.location.origin, {
path: "/realtime",
transports: ["websocket"],
reconnectionDelay: 1000,
reconnectionDelayMax: 10000,
});
this.socket.authenticated = false;
const {
@ -73,6 +77,12 @@ class SocketProvider extends React.Component<Props> {
}
});
// on reconnection, reset the transports option, as the Websocket
// connection may have failed (caused by proxy, firewall, browser, ...)
this.socket.on("reconnect_attempt", () => {
this.socket.io.opts.transports = ["polling", "websocket"];
});
this.socket.on("authenticated", () => {
this.socket.authenticated = true;
});