aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/web
diff options
context:
space:
mode:
Diffstat (limited to 'diplomacy/web')
-rw-r--r--diplomacy/web/src/diplomacy/client/connection.js19
-rw-r--r--diplomacy/web/src/diplomacy/utils/future_event.js4
-rw-r--r--diplomacy/web/src/gui/core/page.jsx13
-rw-r--r--diplomacy/web/src/gui/diplomacy/contents/content_connection.jsx3
4 files changed, 32 insertions, 7 deletions
diff --git a/diplomacy/web/src/diplomacy/client/connection.js b/diplomacy/web/src/diplomacy/client/connection.js
index 8931df5..54f6f2d 100644
--- a/diplomacy/web/src/diplomacy/client/connection.js
+++ b/diplomacy/web/src/diplomacy/client/connection.js
@@ -156,7 +156,7 @@ class ConnectionProcessing {
this.connection.socket.close();
if (this.attemptIndex === UTILS.NB_CONNECTION_ATTEMPTS) {
this.connection.isConnecting.set(
- new Error('Connection failed after ' + UTILS.NB_CONNECTION_ATTEMPTS + ' attempts.'));
+ new Error(`${this.connection.isReconnecting.isWaiting() ? 'Reconnection' : 'Connection'} failed after ${UTILS.NB_CONNECTION_ATTEMPTS} attempts.`));
return;
}
this.logger.warn('Connection failing (attempt ' + this.attemptIndex + '/' +
@@ -223,6 +223,10 @@ export class Connection {
this.onSocketClose = this.onSocketClose.bind(this);
this.isReconnecting.set();
+
+ /** Public events. **/
+ this.onReconnection = null; // onReconnection()
+ this.onReconnectionError = null; // onReconnectionError(error)
}
getUrl() {
@@ -273,7 +277,18 @@ export class Connection {
else {
Diplog.error('Disconnected, trying to reconnect.');
this.isReconnecting.clear();
- this.__connect().then(() => new Reconnection(this).reconnect());
+ this.__connect()
+ .then(() => {
+ new Reconnection(this).reconnect();
+ if (this.onReconnection)
+ this.onReconnection();
+ })
+ .catch(error => {
+ if (this.onReconnectionError)
+ this.onReconnectionError(error);
+ else
+ throw error;
+ });
}
}
diff --git a/diplomacy/web/src/diplomacy/utils/future_event.js b/diplomacy/web/src/diplomacy/utils/future_event.js
index a9dfcd8..2285035 100644
--- a/diplomacy/web/src/diplomacy/utils/future_event.js
+++ b/diplomacy/web/src/diplomacy/utils/future_event.js
@@ -38,4 +38,8 @@ export class FutureEvent {
wait() {
return this.__future.promise();
}
+
+ isWaiting() {
+ return !this.__future.done();
+ }
}
diff --git a/diplomacy/web/src/gui/core/page.jsx b/diplomacy/web/src/gui/core/page.jsx
index 560252c..5e7aee2 100644
--- a/diplomacy/web/src/gui/core/page.jsx
+++ b/diplomacy/web/src/gui/core/page.jsx
@@ -59,6 +59,7 @@ export class Page extends React.Component {
this._add_to_my_games = this._add_to_my_games.bind(this);
this._remove_from_my_games = this._remove_from_my_games.bind(this);
this._remove_from_games = this._remove_from_games.bind(this);
+ this.onReconnectionError = this.onReconnectionError.bind(this);
}
static wrapMessage(message) {
@@ -75,6 +76,10 @@ export class Page extends React.Component {
return <ContentConnection/>;
}
+ onReconnectionError(error) {
+ this.__disconnect(error);
+ }
+
//// Methods to load a global fancybox.
loadFancyBox(title, callback) {
@@ -124,18 +129,18 @@ export class Page extends React.Component {
//// Methods to sign out channel and go back to connection page.
- __disconnect() {
+ __disconnect(error) {
// Clear local data and go back to connection page.
this.connection.close();
this.connection = null;
this.channel = null;
this.availableMaps = null;
- const message = Page.wrapMessage(`Disconnected from channel and server.`);
+ const message = Page.wrapMessage(error ? `${error.toString()}` : `Disconnected from channel and server.`);
Diplog.success(message);
this.setState({
- error: null,
+ error: error ? message : null,
info: null,
- success: message,
+ success: error ? null : message,
name: null,
body: null,
// When disconnected, remove all games previously loaded.
diff --git a/diplomacy/web/src/gui/diplomacy/contents/content_connection.jsx b/diplomacy/web/src/gui/diplomacy/contents/content_connection.jsx
index 8c952a4..5947e01 100644
--- a/diplomacy/web/src/gui/diplomacy/contents/content_connection.jsx
+++ b/diplomacy/web/src/gui/diplomacy/contents/content_connection.jsx
@@ -39,6 +39,7 @@ export class ContentConnection extends React.Component {
this.connection.currentConnectionProcessing.stop();
}
this.connection = new Connection(data.hostname, data.port, window.location.protocol.toLowerCase() === 'https:');
+ this.connection.onReconnectionError = page.onReconnectionError;
// Page is passed as logger object (with methods info(), error(), success()) when connecting.
this.connection.connect(page)
.then(() => {
@@ -97,4 +98,4 @@ export class ContentConnection extends React.Component {
}
}
-ContentConnection.contextType = PageContext; \ No newline at end of file
+ContentConnection.contextType = PageContext;