11var ipcRenderer = require ( 'ipc-renderer' ) ,
2- Socket = require ( './utils/Socket' ) ,
2+ Polyglot = require ( 'node-polyglot' ) ,
3+ __ = require ( 'underscore' ) ,
34 $ = require ( 'jquery' ) ,
4- ServerConfigMd = require ( './models/serverConfigMd ' ) ,
5+ Socket = require ( './utils/Socket ' ) ,
56 _app ;
67
78function App ( ) {
@@ -15,55 +16,42 @@ function App() {
1516 this . _notifUnread = 0 ;
1617 this . _chatMessagesUnread = 0 ;
1718
18- // TODO: what is wrong with the localStorage adapter??? shouldn't need
19- // to manually provide the data to the model. All that should be needed
20- // is an ID and then a subsequent fetch, but that doesn't return the data.
21- // Investigate!
22- this . serverConfig = new ServerConfigMd ( JSON . parse ( localStorage [ '_serverConfig-1' ] || '{}' ) ) ;
23-
24- // serverConfigMd.fetch();
25- if ( ! localStorage [ '_serverConfig-1' ] ) {
26- this . serverConfig . save ( ) ;
27- }
28-
29- this . connectHeartbeatSocket ( ) ;
30- }
19+ // TODO: rather than attach the serverConfigs CL
20+ // in main.js, pass in the instance here so the
21+ // dependency is more explicit.
22+ } ;
3123
3224App . prototype . connectHeartbeatSocket = function ( ) {
33- var self = this ;
25+ var activeServer = this . serverConfigs . getActive ( ) ;
3426
35- clearTimeout ( this . heartbeatSocketTimesup ) ;
27+ if ( ! activeServer ) {
28+ throw new Error ( `No active server set. Please set via the Server Configs collection.` ) ;
29+ }
3630
3731 if ( this . _heartbeatSocket ) {
38- this . _heartbeatSocket . connect ( this . serverConfig . getHeartbeatSocketUrl ( ) ) ;
32+ this . _heartbeatSocket . connect ( activeServer . getHeartbeatSocketUrl ( ) ) ;
3933 } else {
40- this . _heartbeatSocket = new Socket ( this . serverConfig . getHeartbeatSocketUrl ( ) ) ;
41-
42- this . _heartbeatSocket . on ( 'close' , function ( ) {
43- clearTimeout ( self . _heartbeatSocketTimesup ) ;
44- } ) ;
34+ this . _heartbeatSocket = new Socket ( activeServer . getHeartbeatSocketUrl ( ) ) ;
4535 }
46-
47- // give up if it takes to long
48- this . _heartbeatSocketTimesup = setTimeout ( function ( ) {
49- if ( self . _heartbeatSocket . getReadyState ( ) !== 1 ) {
50- //self._heartbeatSocket._socket.close(); //turn off for now, until server issues are fixed
51- alert ( polyglot . t ( 'errorMessages.serverTimeout' ) ) ;
52- }
53- } , 30000 ) ; //wait for 30 seconds, sometimes the server stalls
5436} ;
5537
5638App . prototype . getHeartbeatSocket = function ( ) {
5739 return this . _heartbeatSocket ;
5840} ;
5941
6042App . prototype . login = function ( ) {
43+ var activeServer = this . serverConfigs . getActive ( ) ;
44+
45+ if ( ! activeServer ) {
46+ throw new Error ( `No active server set. Please set via the Server Configs collection.` ) ;
47+ }
48+
6149 return $ . ajax ( {
62- url : this . serverConfig . getServerBaseUrl ( ) + '/login' ,
50+ url : activeServer . getServerBaseUrl ( ) + '/login' ,
6351 method : 'POST' ,
6452 data : {
65- username : this . serverConfig . get ( 'username' ) ,
66- password : this . serverConfig . get ( 'password' )
53+ username : activeServer . get ( 'username' ) ,
54+ password : activeServer . get ( 'password' )
6755 } ,
6856 timeout : 3000
6957 } ) ;
@@ -148,7 +136,4 @@ App.getApp = function() {
148136 return _app ;
149137} ;
150138
151-
152- module . exports = App ;
153-
154-
139+ module . exports = App ;
0 commit comments