@@ -20,6 +20,7 @@ import {
20
20
getPreLoginPath ,
21
21
initializeAuthenticationProd ,
22
22
useSnackMessage ,
23
+ useNotificationsListener ,
23
24
} from '@gridsuite/commons-ui' ;
24
25
import PageNotFound from './page-not-found' ;
25
26
import { FormattedMessage } from 'react-intl' ;
@@ -55,7 +56,6 @@ import { getComputedLanguage } from '../utils/language';
55
56
import AppTopBar from './app-top-bar' ;
56
57
import { StudyContainer } from './study-container' ;
57
58
import { fetchValidateUser } from '../services/user-admin' ;
58
- import { connectNotificationsWsUpdateConfig } from '../services/config-notification' ;
59
59
import { fetchConfigParameter , fetchConfigParameters } from '../services/config' ;
60
60
import { fetchDefaultParametersValues , fetchIdpSettings } from '../services/utils' ;
61
61
import { getOptionalServices } from '../services/study' ;
@@ -87,6 +87,7 @@ import {
87
87
setOptionalServices ,
88
88
setParamsLoaded ,
89
89
} from '../redux/actions' ;
90
+ import { NOTIFICATIONS_URL_KEYS } from './utils/notificationsProvider-utils' ;
90
91
91
92
const noUserManager = { instance : null , error : null } ;
92
93
@@ -270,10 +271,8 @@ const App = () => {
270
271
[ dispatch , tablesNamesIndexes , tablesDefinitionIndexes ]
271
272
) ;
272
273
273
- const connectNotificationsUpdateConfig = useCallback ( ( ) => {
274
- const ws = connectNotificationsWsUpdateConfig ( ) ;
275
-
276
- ws . onmessage = function ( event ) {
274
+ const updateConfig = useCallback (
275
+ ( event ) => {
277
276
let eventData = JSON . parse ( event . data ) ;
278
277
if ( eventData . headers && eventData . headers [ 'parameterName' ] ) {
279
278
fetchConfigParameter ( eventData . headers [ 'parameterName' ] )
@@ -290,12 +289,13 @@ const App = () => {
290
289
} )
291
290
) ;
292
291
}
293
- } ;
294
- ws . onerror = function ( event ) {
295
- console . error ( 'Unexpected Notification WebSocket error' , event ) ;
296
- } ;
297
- return ws ;
298
- } , [ updateParams , snackError , dispatch ] ) ;
292
+ } ,
293
+ [ dispatch , snackError , updateParams ]
294
+ ) ;
295
+
296
+ useNotificationsListener ( NOTIFICATIONS_URL_KEYS . CONFIG , {
297
+ listenerCallbackMessage : updateConfig ,
298
+ } ) ;
299
299
300
300
// Can't use lazy initializer because useRouteMatch is a hook
301
301
const [ initialMatchSilentRenewCallbackUrl ] = useState (
@@ -419,13 +419,8 @@ const App = () => {
419
419
headerId : 'paramsRetrievingError' ,
420
420
} )
421
421
) ;
422
-
423
- const ws = connectNotificationsUpdateConfig ( ) ;
424
- return function ( ) {
425
- ws . close ( ) ;
426
- } ;
427
422
}
428
- } , [ user , dispatch , updateParams , connectNotificationsUpdateConfig , snackError ] ) ;
423
+ } , [ user , dispatch , updateParams , snackError ] ) ;
429
424
430
425
const onChangeTab = useCallback ( ( newTabIndex ) => {
431
426
setTabIndex ( newTabIndex ) ;
0 commit comments