@@ -2,6 +2,7 @@ import "bootstrap-vue/dist/bootstrap-vue.css";
22import { BootstrapVue , BootstrapVueIcons } from "bootstrap-vue" ;
33import * as bootstrap from "bootstrap" ;
44import TenantAwareEcho from "./common/TenantAwareEcho" ;
5+ import { initSessionSync } from "./common/sessionSync" ;
56import Router from "vue-router" ;
67import ScreenBuilder , { initializeScreenCache } from "@processmaker/screen-builder" ;
78import * as VueDeepSet from "vue-deepset" ;
@@ -350,99 +351,36 @@ if (window.Processmaker && window.Processmaker.broadcasting) {
350351}
351352
352353if ( userID ) {
353- // Session timeout
354354 const timeoutScript = document . head . querySelector ( "meta[name=\"timeout-worker\"]" ) ?. content ;
355- window . ProcessMaker . AccountTimeoutLength = parseInt ( eval ( document . head . querySelector ( "meta[name=\"timeout-length\"]" ) ?. content ) ) ;
356- window . ProcessMaker . AccountTimeoutWarnSeconds = parseInt ( document . head . querySelector ( "meta[name=\"timeout-warn-seconds\"]" ) ?. content ) ;
357- window . ProcessMaker . AccountTimeoutEnabled = document . head . querySelector ( "meta[name=\"timeout-enabled\"]" ) ? parseInt ( document . head . querySelector ( "meta[name=\"timeout-enabled\"]" ) ?. content ) : 1 ;
358- window . ProcessMaker . AccountTimeoutWorker = new Worker ( timeoutScript ) ;
359-
360- const payloadAccountTimeoutWorker = {
361- timeout : window . ProcessMaker . AccountTimeoutLength ,
362- warnSeconds : window . ProcessMaker . AccountTimeoutWarnSeconds ,
363- enabled : window . ProcessMaker . AccountTimeoutEnabled ,
364- } ;
365-
366- window . ProcessMaker . AccountTimeoutWorker . onmessage = ( e ) => {
367- if ( e . data . method === "countdown" ) {
368- window . ProcessMaker . sessionModal (
369- "Session Warning" ,
370- "<p>Your user session is expiring. If your session expires, all of your unsaved data will be lost.</p><p>Would you like to stay connected?</p>" ,
371- e . data . data . time ,
372- window . ProcessMaker . AccountTimeoutWarnSeconds ,
373- ) ;
374- }
375- if ( e . data . method === "timedOut" ) {
376- window . location = "/logout?timeout=true" ;
377- }
378- } ;
379-
380- // in some cases it's necessary to start manually
381- window . ProcessMaker . AccountTimeoutWorker . postMessage ( {
382- method : "start" ,
383- data : payloadAccountTimeoutWorker ,
384- } ) ;
385-
386- // Restart the timeout worker (when the user interacts with the page)
387- const eventsTimeoutWorker = [ "click" , "keypress" ] ;
388-
389- eventsTimeoutWorker . forEach ( ( event ) => {
390- document . addEventListener ( event , ( ) => {
391- window . ProcessMaker . AccountTimeoutWorker . postMessage ( {
392- method : "restart" ,
393- } ) ;
394- } ) ;
355+ const accountTimeoutLength = parseInt ( eval ( document . head . querySelector ( "meta[name=\"timeout-length\"]" ) ?. content ) ) ;
356+ const warnSeconds = parseInt ( document . head . querySelector ( "meta[name=\"timeout-warn-seconds\"]" ) ?. content ) ;
357+ const accountTimeoutWarnSeconds = Number . isNaN ( warnSeconds ) ? 0 : warnSeconds ;
358+ const accountTimeoutEnabled = document . head . querySelector ( "meta[name=\"timeout-enabled\"]" ) ? parseInt ( document . head . querySelector ( "meta[name=\"timeout-enabled\"]" ) ?. content ) : 1 ;
359+
360+ const sessionSyncState = initSessionSync ( {
361+ userId : userID . content ,
362+ isProd,
363+ timeoutScript,
364+ accountTimeoutLength,
365+ accountTimeoutWarnSeconds,
366+ accountTimeoutEnabled,
367+ Vue,
368+ Echo : window . Echo ,
369+ pushNotification : window . ProcessMaker . pushNotification ,
370+ alert : window . ProcessMaker . alert ,
371+ getSessionModal : ( ) => window . ProcessMaker . sessionModal ,
372+ getCloseSessionModal : ( ) => window . ProcessMaker . closeSessionModal ,
373+ getNavbar : ( ) => window . ProcessMaker . navbar ,
395374 } ) ;
396375
397- // End -> Restart the timeout worker (when the user interacts with the page)
398-
399- const isSameDevice = ( e ) => {
400- const localDeviceId = Vue . $cookies . get ( e . device_variable ) ;
401- const remoteDeviceId = e . device_id ;
402- return localDeviceId && localDeviceId === remoteDeviceId ;
403- } ;
404-
405- window . Echo . private ( `ProcessMaker.Models.User.${ userID . content } ` )
406- . notification ( ( token ) => {
407- ProcessMaker . pushNotification ( token ) ;
408- } )
409- . listen ( ".SessionStarted" , ( e ) => {
410- const lifetime = parseInt ( eval ( e . lifetime ) ) ;
411- if ( isSameDevice ( e ) ) {
412- window . ProcessMaker . AccountTimeoutWorker . postMessage ( {
413- method : "start" ,
414- data : {
415- timeout : lifetime ,
416- warnSeconds : window . ProcessMaker . AccountTimeoutWarnSeconds ,
417- enabled : window . ProcessMaker . AccountTimeoutEnabled ,
418- } ,
419- } ) ;
420- if ( window . ProcessMaker . closeSessionModal ) {
421- window . ProcessMaker . closeSessionModal ( ) ;
422- }
423- }
424- } )
425- . listen ( ".Logout" , ( e ) => {
426- if ( isSameDevice ( e ) && window . location . pathname . indexOf ( "/logout" ) === - 1 ) {
427- const localDeviceId = Vue . $cookies . get ( e . device_variable ) ;
428- const redirectLogoutinterval = setInterval ( ( ) => {
429- const newDeviceId = Vue . $cookies . get ( e . device_variable ) ;
430- if ( localDeviceId !== newDeviceId ) {
431- clearInterval ( redirectLogoutinterval ) ;
432- window . location . href = "/logout" ;
433- }
434- } , 100 ) ;
435- }
436- } )
437- . listen ( ".SecurityLogDownloadJobCompleted" , ( e ) => {
438- if ( e . success ) {
439- const { link } = e ;
440- const { message } = e ;
441- window . ProcessMaker . alert ( message , "success" , 0 , false , false , link ) ;
442- } else {
443- window . ProcessMaker . alert ( e . message , "warning" ) ;
444- }
445- } ) ;
376+ if ( sessionSyncState ) {
377+ window . ProcessMaker . AccountTimeoutLength = sessionSyncState . AccountTimeoutLength ;
378+ window . ProcessMaker . AccountTimeoutWarnSeconds = sessionSyncState . AccountTimeoutWarnSeconds ;
379+ window . ProcessMaker . AccountTimeoutWarnMinutes = sessionSyncState . AccountTimeoutWarnMinutes ;
380+ window . ProcessMaker . AccountTimeoutEnabled = sessionSyncState . AccountTimeoutEnabled ;
381+ window . ProcessMaker . AccountTimeoutWorker = sessionSyncState . AccountTimeoutWorker ;
382+ window . ProcessMaker . sessionSync = sessionSyncState . sessionSync ;
383+ }
446384}
447385
448386// Configuration Global object used by ScreenBuilder
0 commit comments