From 1029e6ebd642709a21e4e88cad6e19ac482b21f6 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 17 Oct 2023 19:16:24 +0200 Subject: [PATCH] browserTabSessi --- src/Components/SideMenu/index.js | 2 ++ src/Contexts/WebSocketContext.js | 6 ++++-- src/utils.js | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Components/SideMenu/index.js b/src/Components/SideMenu/index.js index 99f9a8d..39a0cc1 100644 --- a/src/Components/SideMenu/index.js +++ b/src/Components/SideMenu/index.js @@ -18,6 +18,7 @@ import { useEffect, useRef, useState } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { + BrowserTabSession, Constants, hasOnePermission, hasOneXYPermission, @@ -319,6 +320,7 @@ export default function SideMenu({ webSocketContext.SendSocketMessage(SentMessagesCommands.SubscribeToTopic, { topic: pathname, + browserTabSession: BrowserTabSession, }); }, [location.pathname]); diff --git a/src/Contexts/WebSocketContext.js b/src/Contexts/WebSocketContext.js index 5e19428..b60b576 100644 --- a/src/Contexts/WebSocketContext.js +++ b/src/Contexts/WebSocketContext.js @@ -1,5 +1,5 @@ import { createContext, useContext, useEffect, useRef } from "react"; -import { Constants, myFetch } from "../utils"; +import { BrowserTabSession, Constants, myFetch } from "../utils"; import { useSideBarContext } from "./SideBarContext"; import { useAppContext } from "./AppContext"; import { handleWebSocketMessage } from "../Handlers/WebSocketMessageHandler"; @@ -36,7 +36,9 @@ export default function WebSocketProvider({ const consolesContext = useConsolesContext(); const connect = () => { - ws.current = new WebSocket(`${Constants.WS_ADDRESS}?auth=${userSession}`); + ws.current = new WebSocket( + `${Constants.WS_ADDRESS}?auth=${userSession}&bts=${BrowserTabSession}` + ); ws.current.onopen = () => { console.log("connected"); diff --git a/src/utils.js b/src/utils.js index b234d21..01cc1bf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -244,6 +244,12 @@ export function setUserSessionToLocalStorage(session) { localStorage.setItem("session", session); } +// needed for a user who uses multiple tabs in the browser +// with the same session id because otherwise the last browser +// tab would subscribe to the topic and the other tabs would +// not receive any messages +export const BrowserTabSession = GetUuid(); + /** * websocket */