aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/services/notificationService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/framework/src/services/notificationService.ts')
-rw-r--r--sdnr/wt/odlux/framework/src/services/notificationService.ts37
1 files changed, 30 insertions, 7 deletions
diff --git a/sdnr/wt/odlux/framework/src/services/notificationService.ts b/sdnr/wt/odlux/framework/src/services/notificationService.ts
index 99e697e9a..b2880b9de 100644
--- a/sdnr/wt/odlux/framework/src/services/notificationService.ts
+++ b/sdnr/wt/odlux/framework/src/services/notificationService.ts
@@ -21,10 +21,12 @@ import { SetWebsocketAction } from '../actions/websocketAction';
const socketUrl = [location.protocol === 'https:' ? 'wss://' : 'ws://', location.hostname, ':', location.port, '/websocket'].join('');
const subscriptions: { [scope: string]: SubscriptionCallback[] } = {};
let socketReady: Promise<WebSocket>;
-let userLoggedOut = false;
let wasWebsocketConnectionEstablished: undefined | boolean;
let applicationStore: ApplicationStore | null;
+let areWebsocketsStoppedViaSettings = false;
+
+
export interface IFormatedMessage {
"event-time": string,
"data": {
@@ -166,10 +168,11 @@ const connect = (): Promise<WebSocket> => {
notificationSocket.onclose = function (event) {
console.log("socket connection closed");
- if (applicationStore) {
- applicationStore.dispatch(new SetWebsocketAction(false));
- }
- if (!userLoggedOut) {
+ dispatchSocketClose();
+
+ const isUserLoggedIn = applicationStore?.state.framework.authenticationState.user && applicationStore?.state.framework.authenticationState.user?.isValid;
+
+ if (isUserLoggedIn && !areWebsocketsStoppedViaSettings) {
socketReady = connect();
}
};
@@ -179,17 +182,37 @@ const connect = (): Promise<WebSocket> => {
export const startWebsocketSession = () => {
socketReady = connect();
- userLoggedOut = false;
+ areWebsocketsStoppedViaSettings = false;
+}
+
+export const suspendWebsocketSession = () =>{
+ areWebsocketsStoppedViaSettings = true;
+ closeSocket();
}
export const endWebsocketSession = () => {
+ closeSocket();
+}
+
+const closeSocket = () =>{
+
if (socketReady) {
socketReady.then(websocket => {
websocket.close();
- userLoggedOut = true;
});
+ }else{
+ dispatchSocketClose();
}
+}
+
+const dispatchSocketClose = () =>{
+ const isUserLoggedIn = applicationStore?.state.framework.authenticationState.user && applicationStore?.state.framework.authenticationState.user?.isValid;
+ if(isUserLoggedIn){
+ applicationStore?.dispatch(new SetWebsocketAction(false));
+ }else{
+ applicationStore?.dispatch(new SetWebsocketAction(null));
+ }
}