Skip to content

Commit

Permalink
add handling og onAutoreconnectIteration
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Dec 17, 2018
1 parent 405ce75 commit a5d405b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/views/tinode-web.jsx
Expand Up @@ -29,6 +29,11 @@ const messages = defineMessages({
id: 'update_available',
defaultMessage: 'Update available. <a href="">Reload</a>.',
description: 'Message shown when an app update is available.'
},
reconnect_countdown: {
id: 'reconnect_countdown',
defaultMessage: 'Disconnected. Connecting in {seconds}s&hellips; <a href="">Try now</a>',
description: 'Message shown when an app update is available.'
}
});

Expand All @@ -48,6 +53,7 @@ class TinodeWeb extends React.Component {
this.handleError = this.handleError.bind(this);
this.handleLoginRequest = this.handleLoginRequest.bind(this);
this.handleConnected = this.handleConnected.bind(this);
this.handleAutoreconnectIteration = this.handleAutoreconnectIteration.bind(this);
this.doLogin = this.doLogin.bind(this);
this.handleCredentialsRequest = this.handleCredentialsRequest.bind(this);
this.handleLoginSuccessful = this.handleLoginSuccessful.bind(this);
Expand Down Expand Up @@ -164,6 +170,7 @@ class TinodeWeb extends React.Component {
this.tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport);
this.tinode.onConnect = this.handleConnected;
this.tinode.onDisconnect = this.handleDisconnect;
this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration;

// Initialize desktop alerts.
if (this.state.desktopAlertsEnabled) {
Expand Down Expand Up @@ -351,6 +358,25 @@ class TinodeWeb extends React.Component {
this.doLogin(this.state.login, this.state.password, {meth: this.state.credMethod, resp: this.state.credCode});
}

// Called for each auto-reconnect iteration.
handleAutoreconnectIteration(sec, prom) {
console.log("handleAutoreconnectIteration", seconds, reconnecting);
}

// Connection lost
handleDisconnect(err) {
this.setState({
connected: false,
topicSelectedOnline: false,
dialogSelected: null,
errorText: err && err.message ? err.message : "Disconnected",
errorLevel: err && err.message ? 'err' : 'warn',
loginDisabled: false,
contextMenuVisible: false,
serverVersion: "no connection"
});
}

doLogin(login, password, cred) {
if (this.tinode.isAuthenticated()) {
// Already logged in. Go to default screen.
Expand Down Expand Up @@ -433,19 +459,6 @@ class TinodeWeb extends React.Component {
HashNavigation.navigateTo(HashNavigation.setUrlSidePanel(window.location.hash, 'contacts'));
}

handleDisconnect(err) {
this.setState({
connected: false,
topicSelectedOnline: false,
dialogSelected: null,
errorText: err && err.message ? err.message : "Disconnected",
errorLevel: err && err.message ? 'err' : 'warn',
loginDisabled: false,
contextMenuVisible: false,
serverVersion: "no connection"
});
}

tnMeMetaDesc(desc) {
if (desc && desc.public) {
this.setState({
Expand Down

0 comments on commit a5d405b

Please sign in to comment.