Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 52c3930

Browse files
committed
worked more through some init connect scenarios
1 parent 3534d62 commit 52c3930

20 files changed

+323
-218
lines changed

css/obBase.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,6 +4249,10 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
42494249
top: 372px;
42504250
}
42514251
4252+
#ov1 .server-config-row {
4253+
/*min-height: 73px;*/
4254+
}
4255+
42524256
#ov1 .server-config-row .connection-failed::after {
42534257
content: '';
42544258
position: absolute;

js/App.js

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ var ipcRenderer = require('ipc-renderer'),
33
__ = require('underscore'),
44
$ = require('jquery'),
55
Socket = require('./utils/Socket'),
6-
LanguagesMd = require('./models/languagesMd'),
7-
languages = new LanguagesMd(),
8-
ServerConfigsCl = require('./collections/serverConfigsCl'),
96
_app;
107

118
function App() {
12-
var self = this,
13-
serverConfig;
9+
var self = this;
1410

1511
// ensure we're a singleton
1612
if (_app) return _app;
@@ -20,54 +16,24 @@ function App() {
2016
this._notifUnread = 0;
2117
this._chatMessagesUnread = 0;
2218

23-
this.serverConfigs = new ServerConfigsCl();
24-
this.serverConfigs.fetch();
25-
26-
if (!(serverConfig = this.getServerConfig())) {
27-
this.setServerConfig(
28-
this.serverConfigs.create({
29-
name: polyglot.t('serverConnectModal.defaultServerName'),
30-
default: true
31-
}).id
32-
);
33-
}
34-
35-
this.connectHeartbeatSocket();
36-
};
37-
38-
App.prototype.getServerConfig = function() {
39-
var config = this.serverConfigs.get(localStorage.activeServer);
40-
41-
if ((!localStorage.activeServer || !config) && this.serverConfigs.length) {
42-
localStorage.activeServer = this.serverConfigs.at(this.serverConfigs.length - 1).id;
43-
config = this.serverConfigs.get(localStorage.activeServer);
44-
}
45-
46-
return config;
47-
};
48-
49-
App.prototype.setServerConfig = function(id) {
50-
if (!this.serverConfigs.get(id)) {
51-
throw new Error(`Unable to set the server config. It must be an id of one of the available
52-
server configs stored via the ServerConfigs collection.`)
53-
}
54-
55-
localStorage.activeServer = id;
19+
// TODO: rather than attach the serverConfigs CL
20+
// in main.js, pass in the instance here so the
21+
// dependency is more explicit.
5622
};
5723

5824
App.prototype.connectHeartbeatSocket = function() {
59-
var config;
25+
var activeServer = this.serverConfigs.getActive();
6026

61-
if (!(config = this.getServerConfig())) {
62-
throw new Error(`No server config is set. Please set one via setServerConfig().`);
27+
if (!activeServer) {
28+
throw new Error(`No active server set. Please set via the Server Configs collection.`);
6329
}
6430

6531
clearTimeout(this.heartbeatSocketTimesup);
6632

6733
if (this._heartbeatSocket) {
68-
this._heartbeatSocket.connect(config.getHeartbeatSocketUrl());
34+
this._heartbeatSocket.connect(activeServer.getHeartbeatSocketUrl());
6935
} else {
70-
this._heartbeatSocket = new Socket(config.getHeartbeatSocketUrl());
36+
this._heartbeatSocket = new Socket(activeServer.getHeartbeatSocketUrl());
7137

7238
this._heartbeatSocket.on('close', () => {
7339
clearTimeout(this._heartbeatSocketTimesup);
@@ -80,26 +46,26 @@ App.prototype.connectHeartbeatSocket = function() {
8046
this._heartbeatSocket._socket.close(); //turn off for now, until server issues are fixed
8147
// alert(polyglot.t('errorMessages.serverTimeout'));
8248
}
83-
}, 3000); //wait for 30 seconds, sometimes the server stalls
49+
}, 10000); //wait for 30 seconds, sometimes the server stalls
8450
};
8551

8652
App.prototype.getHeartbeatSocket = function() {
8753
return this._heartbeatSocket;
8854
};
8955

9056
App.prototype.login = function() {
91-
var config;
57+
var activeServer = this.serverConfigs.getActive();
9258

93-
if (!(config = this.getServerConfig())) {
94-
throw new Error(`No server config is set. Please set one via setServerConfig().`);
59+
if (!activeServer) {
60+
throw new Error(`No active server set. Please set via the Server Configs collection.`);
9561
}
9662

9763
return $.ajax({
98-
url: config.getServerBaseUrl() + '/login',
64+
url: activeServer.getServerBaseUrl() + '/login',
9965
method: 'POST',
10066
data: {
101-
username: config.get('username'),
102-
password: config.get('password')
67+
username: activeServer.get('username'),
68+
password: activeServer.get('password')
10369
},
10470
timeout: 3000
10571
});

js/collections/chatConversationsCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var Backbone = require('backbone'),
44

55
module.exports = Backbone.Collection.extend({
66
url: function() {
7-
return app.serverConfig.getServerBaseUrl() + '/get_chat_conversations';
7+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_chat_conversations';
88
},
99

1010
model: ChatConversationMd,

js/collections/chatMessagesCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var Backbone = require('backbone'),
44

55
module.exports = Backbone.Collection.extend({
66
url: function() {
7-
return app.serverConfig.getServerBaseUrl() + '/get_chat_messages';
7+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_chat_messages';
88
},
99

1010
model: ChatMessageMd,

js/collections/notificationsCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Backbone = require('backbone'),
55

66
module.exports = Backbone.Collection.extend({
77
url: function() {
8-
return app.serverConfig.getServerBaseUrl() + '/get_notifications';
8+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_notifications';
99
},
1010

1111
model: NotificationMd,

js/collections/ratingCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var __ = require('underscore'),
55

66
module.exports = Backbone.Collection.extend({
77
url: function() {
8-
return app.serverConfig.getServerBaseUrl() + '/get_ratings';
8+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_ratings';
99
},
1010

1111
model: RatingMd,

js/collections/serverConfigsCl.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,31 @@ var Backbone = require('backbone'),
55
module.exports = Backbone.Collection.extend({
66
sync: localStorageSync.sync,
77
localStorage: new localStorageSync('__serverConfig'),
8-
model: ServerConfigMd
8+
model: ServerConfigMd,
9+
10+
getActive: function() {
11+
var config = this.get(localStorage.activeServer);
12+
13+
if (!config && this.length) {
14+
config = this.at(this.length - 1);
15+
this.setActive(config.id);
16+
}
17+
18+
return config;
19+
},
20+
21+
setActive: function(id) {
22+
var md;
23+
24+
if (!(md = this.get(id))) {
25+
throw new Error(`Unable to set the active server config. It must be an id of one of the available
26+
server configs stored in this collection.`)
27+
}
28+
29+
if (this._active !== id) {
30+
this._active = id;
31+
localStorage.activeServer = id;
32+
this.trigger('activeServerChange', md);
33+
}
34+
}
935
});

0 commit comments

Comments
 (0)