From 541877451223859643dd5328211b5926ec2c5b22 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Sun, 13 Dec 2015 19:57:39 -0600 Subject: [PATCH] Redirect to the server selection on error. --- src/app.jsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app.jsx b/src/app.jsx index 5bf1ca6..fca56c5 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -67,6 +67,21 @@ export default class App extends React.Component { discover() .then(server => createSocket(server.info.address)) .then(socket => { + // Redirect to server selection on disconnect (for now). + // Since close always follows an emitted 'error' on socket, we'll only + // redirect in close. + socket.on('close', (hadError) => { + if (hadError) { + console.error('Connection to Fallout 4 server had an error. Redirecting to server selection screen.'); + } + this.props.history.pushState(null, '/'); + }); + socket.on('timeout', () => { + console.error('Fallout 4 timed out.'); + socket.destroy(); + }); + socket.setTimeout(2000); + this.cancelHeartbeat = sendPeriodicHeartbeat(socket); this.connection = createConnectionSubject(socket); this.subscription = this.connection.subscribe(x => {