diff --git a/src/components/app.js b/src/components/app.js index 6bd138546..c15d90d29 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -28,6 +28,7 @@ import { CardErrorBoundary, getPreLoginPath, initializeAuthenticationProd, + useAnnouncementsSubscriber, } from '@gridsuite/commons-ui'; import { useMatch } from 'react-router-dom'; @@ -39,6 +40,8 @@ import { fetchConfigParameter, fetchConfigParameters, fetchValidateUser, + getAnnouncementsWsUrl, + getToken, } from '../utils/rest-api'; import { APP_NAME, @@ -79,6 +82,8 @@ const App = () => { const location = useLocation(); + useAnnouncementsSubscriber(getAnnouncementsWsUrl(), getToken()); + const updateParams = useCallback( (params) => { console.debug('received UI parameters : ', params); diff --git a/src/utils/rest-api.js b/src/utils/rest-api.js index 8a864e351..39a9cffbc 100644 --- a/src/utils/rest-api.js +++ b/src/utils/rest-api.js @@ -30,9 +30,9 @@ const PREFIX_FILTERS_QUERIES = process.env.REACT_APP_API_GATEWAY + '/filter/v1/filters'; const PREFIX_STUDY_QUERIES = process.env.REACT_APP_API_GATEWAY + '/study'; -function getToken() { +export function getToken() { const state = store.getState(); - return state.user.id_token; + return state.user?.id_token; } export const getRequestParamFromList = (params, paramName) => { @@ -41,10 +41,18 @@ export const getRequestParamFromList = (params, paramName) => { ); }; +export const getWsBase = () => + document.baseURI + .replace(/^http:\/\//, 'ws://') + .replace(/^https:\/\//, 'wss://'); + +export function getAnnouncementsWsUrl() { + const webSocketBaseUrl = getWsBase(); + return webSocketBaseUrl + PREFIX_CONFIG_NOTIFICATION_WS + '/global'; +} + export function connectNotificationsWsUpdateConfig() { - const webSocketBaseUrl = document.baseURI - .replace(/^http:\/\//, 'ws://') - .replace(/^https:\/\//, 'wss://'); + const webSocketBaseUrl = getWsBase() const webSocketUrl = webSocketBaseUrl + PREFIX_CONFIG_NOTIFICATION_WS + @@ -798,9 +806,7 @@ export function newScriptFromFiltersContingencyList( * @returns {ReconnectingWebSocket} */ export function connectNotificationsWsUpdateDirectories() { - const webSocketBaseUrl = document.baseURI - .replace(/^http:\/\//, 'ws://') - .replace(/^https:\/\//, 'wss://'); + const webSocketBaseUrl = getWsBase() const webSocketUrl = webSocketBaseUrl + PREFIX_NOTIFICATION_WS +