@@ -52,20 +52,16 @@ var Polyglot = require('node-polyglot'),
5252 startUpConnectRetryDelay = 2 * 1000 ,
5353 startUpConnectMaxTime = 6 * 1000 ,
5454 startTime = Date . now ( ) ,
55+ startUpRetry ,
5556 onActiveServerSync ,
5657 extendPolyglot ,
5758 newPageNavView ,
5859 newSocketView ,
5960 serverConnectModal ,
6061 onboardingModal ,
61- startInitSequence ,
62- startLocalInitSequence ,
63- startRemoteInitSequence ,
6462 launchOnboarding ,
65- launchServerConnect ,
6663 setServerUrl ,
67- guidCreating ,
68- after401LoginRequest ;
64+ guidCreating ;
6965
7066//put language in the window so all templates and models can reach it. It's especially important in formatting currency.
7167//retrieve the stored value, since user is a blank model at this point
@@ -105,8 +101,6 @@ app.serverConfigs.fetch().done(() => {
105101( setServerUrl = function ( ) {
106102 var baseServerUrl = app . serverConfigs . getActive ( ) . getServerBaseUrl ( ) ;
107103
108- console . log ( `mr bo jangles: ${ baseServerUrl } ` ) ;
109-
110104 user . urlRoot = baseServerUrl + "/settings" ;
111105 user . set ( 'serverUrl' , baseServerUrl + '/' ) ;
112106 userProfile . urlRoot = baseServerUrl + "/profile" ;
@@ -350,26 +344,6 @@ var loadProfile = function(landingRoute, onboarded) {
350344 } ) ;
351345} ;
352346
353- $ ( document ) . ajaxError ( function ( event , jqxhr , settings , thrownError ) {
354- // if (jqxhr.status === 401) {
355- // if (after401LoginRequest && after401LoginRequest.state() === 'pending') return;
356-
357- // after401LoginRequest = app.login().done(function(data) {
358- // var route = location.hash;
359-
360- // if (data.success) {
361- // // refresh the current route
362- // Backbone.history.navigate('blah-blah-blah');
363- // Backbone.history.navigate(route, { replace: true, trigger: true });
364- // } else {
365- // launchServerConnect();
366- // }
367- // }).fail(function() {
368- // launchServerConnect();
369- // });
370- // }
371- } ) ;
372-
373347$ ( document ) . ajaxSend ( function ( e , jqXhr , settings ) {
374348 // With this we could map ajax responses to the server config
375349 // that was active when they were initiated.
@@ -410,43 +384,30 @@ app.serverConnectModal.on('connected', (authenticated) => {
410384} ) ;
411385
412386app . getHeartbeatSocket ( ) . on ( 'open' , function ( e ) {
387+ app . getHeartbeatSocket ( ) . off ( 'close' , startUpRetry ) ;
388+
413389 // clear some flags so the heartbeat events will
414390 // appropriatally loadProfile or launch onboarding
415391 guidCreating = null ;
416392 loadProfileNeeded = true ;
417393
418394 onboardingModal && onboardingModal . remove ( ) ;
419-
420- // if (profileLoaded) {
421- // location.reload();
422- // } else {
423- // // clear some flags so the heartbeat events will
424- // // appropriatally loadProfile or launch onboarding
425- // guidCreating = null;
426- // loadProfileNeeded = true;
427-
428- // onboardingModal && onboardingModal.remove();
429- // }
430395} ) ;
431396
432- app . getHeartbeatSocket ( ) . on ( 'close' , function ( e ) {
433- // if (
434- // Date.now() - startTime < startUpConnectMaxTime &&
435- // startUpConnectMaxRetries
436- // ) {
437- // setTimeout(() => {
438- // startUpConnectMaxRetries--;
439- // app.connectHeartbeatSocket();
440- // }, startUpConnectRetryDelay);
441- // } else {
442- // launchServerConnect();
443- // }
444-
445- // launchServerConnect();
446-
447- app . serverConnectModal . failConnection ( null , app . serverConfigs . getActive ( ) )
448- . open ( ) ;
449- } ) ;
397+ app . getHeartbeatSocket ( ) . on ( 'close' , ( startUpRetry = function ( e ) {
398+ if (
399+ Date . now ( ) - startTime < startUpConnectMaxTime &&
400+ startUpConnectMaxRetries
401+ ) {
402+ setTimeout ( ( ) => {
403+ startUpConnectMaxRetries -- ;
404+ app . connectHeartbeatSocket ( ) ;
405+ } , startUpConnectRetryDelay ) ;
406+ } else {
407+ app . serverConnectModal . failConnection ( null , app . serverConfigs . getActive ( ) )
408+ . open ( ) ;
409+ }
410+ } ) ) ;
450411
451412app . getHeartbeatSocket ( ) . on ( 'message' , function ( e ) {
452413 if ( e . jsonData && e . jsonData . status ) {
0 commit comments