@@ -8,6 +8,7 @@ import Logger from './logger/logger';
88import './app.scss' ;
99import localStorageKeys from './local-storage-keys' ;
1010import fallback from './assets/fallback.png' ;
11+ import idFromPath from './id-from-path' ;
1112
1213/**
1314 * App component.
@@ -20,9 +21,9 @@ function App() {
2021 localStorageKeys . FALLBACK_IMAGE
2122 ) ;
2223
23- const loginCheckTimeout = 15 * 1000 ;
24- const refreshTimeout = 60 * 1000 ;
25- const releaseTimestampIntervalTimeout = 1000 * 60 * 5 ;
24+ const loginCheckTimeoutDefault = 20 * 1000 ;
25+ const refreshTokenTimeoutDefault = 60 * 1000 * 15 ;
26+ const releaseTimestampIntervalTimeoutDefault = 1000 * 60 * 10 ;
2627
2728 const [ running , setRunning ] = useState ( false ) ;
2829 const [ screen , setScreen ] = useState ( '' ) ;
@@ -96,7 +97,7 @@ function App() {
9697 Logger . log ( 'info' , 'Refreshing token.' ) ;
9798
9899 ConfigLoader . loadConfig ( ) . then ( ( config ) => {
99- fetch ( config . authenticationRefreshTokenEndpoint , {
100+ fetch ( ` ${ config . apiEndpoint } /v2/authentication/token/refresh` , {
100101 method : 'POST' ,
101102 headers : {
102103 'Content-Type' : 'application/json' ,
@@ -167,8 +168,13 @@ function App() {
167168 } )
168169 ) ;
169170
170- // Start refresh token interval.
171- refreshTokenIntervalRef . current = setInterval ( checkToken , refreshTimeout ) ;
171+ ConfigLoader . loadConfig ( ) . then ( ( config ) => {
172+ // Start refresh token interval.
173+ refreshTokenIntervalRef . current = setInterval (
174+ checkToken ,
175+ config . refreshTokenTimeout ?? refreshTokenTimeoutDefault
176+ ) ;
177+ } ) ;
172178 } ;
173179
174180 const checkLogin = ( ) => {
@@ -181,7 +187,7 @@ function App() {
181187 startContent ( localScreenId ) ;
182188 } else {
183189 ConfigLoader . loadConfig ( ) . then ( ( config ) => {
184- fetch ( config . authenticationEndpoint , {
190+ fetch ( ` ${ config . apiEndpoint } /v2/authentication/screen` , {
185191 method : 'POST' ,
186192 mode : 'cors' ,
187193 credentials : 'include' ,
@@ -224,15 +230,21 @@ function App() {
224230 clearTimeout ( timeoutRef . current ) ;
225231 }
226232
227- timeoutRef . current = setTimeout ( checkLogin , loginCheckTimeout ) ;
233+ timeoutRef . current = setTimeout (
234+ checkLogin ,
235+ config . loginCheckTimeout ?? loginCheckTimeoutDefault
236+ ) ;
228237 }
229238 } )
230239 . catch ( ( ) => {
231240 if ( timeoutRef . current !== null ) {
232241 clearTimeout ( timeoutRef . current ) ;
233242 }
234243
235- timeoutRef . current = setTimeout ( checkLogin , loginCheckTimeout ) ;
244+ timeoutRef . current = setTimeout (
245+ checkLogin ,
246+ config . loginCheckTimeout ?? loginCheckTimeoutDefault
247+ ) ;
236248 } ) ;
237249 } ) ;
238250 }
@@ -302,6 +314,24 @@ function App() {
302314 } ;
303315
304316 useEffect ( ( ) => {
317+ const currentUrl = new URL ( window . location . href ) ;
318+
319+ // Make sure have releaseVersion and releaseTimestamp set in url parameters.
320+ if (
321+ ! currentUrl . searchParams . has ( 'releaseVersion' ) ||
322+ ! currentUrl . searchParams . has ( 'releaseTimestamp' )
323+ ) {
324+ ReleaseLoader . loadConfig ( ) . then ( ( release ) => {
325+ currentUrl . searchParams . set (
326+ 'releaseTimestamp' ,
327+ release . releaseTimestamp
328+ ) ;
329+ currentUrl . searchParams . set ( 'releaseVersion' , release . releaseVersion ) ;
330+
331+ window . history . replaceState ( null , '' , currentUrl ) ;
332+ } ) ;
333+ }
334+
305335 document . addEventListener ( 'screen' , screenHandler ) ;
306336 document . addEventListener ( 'reauthenticate' , reauthenticateHandler ) ;
307337 document . addEventListener ( 'contentEmpty' , contentEmpty ) ;
@@ -312,10 +342,13 @@ function App() {
312342
313343 checkForUpdates ( ) ;
314344
315- releaseTimestampIntervalRef . current = setInterval (
316- checkForUpdates ,
317- releaseTimestampIntervalTimeout
318- ) ;
345+ ConfigLoader . loadConfig ( ) . then ( ( config ) => {
346+ releaseTimestampIntervalRef . current = setInterval (
347+ checkForUpdates ,
348+ config . releaseTimestampIntervalTimeout ??
349+ releaseTimestampIntervalTimeoutDefault
350+ ) ;
351+ } ) ;
319352
320353 return function cleanup ( ) {
321354 Logger . log ( 'info' , 'Unmounting App.' ) ;
@@ -341,6 +374,15 @@ function App() {
341374 } , [ ] ) ;
342375
343376 useEffect ( ( ) => {
377+ // Append screenId to current url for easier debugging. If errors are logged in the API's standard http log this
378+ // makes it easy to see what screen client has made the http call by putting the screen id in the referer http
379+ // header.
380+ if ( screen && screen [ '@id' ] ) {
381+ const url = new URL ( window . location . href ) ;
382+ url . searchParams . set ( 'screenId' , idFromPath ( screen [ '@id' ] ) ) ;
383+ window . history . replaceState ( null , '' , url ) ;
384+ }
385+
344386 ConfigLoader . loadConfig ( ) . then ( ( config ) => {
345387 const token = localStorage . getItem ( localStorageKeys . API_TOKEN ) ;
346388 const tenantKey = localStorage . getItem ( localStorageKeys . TENANT_KEY ) ;
0 commit comments