@@ -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
118function 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
5824App . 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
8652App . prototype . getHeartbeatSocket = function ( ) {
8753 return this . _heartbeatSocket ;
8854} ;
8955
9056App . 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 } ) ;
0 commit comments