browserTabSessi

main
alex 2023-10-17 19:16:24 +02:00
parent 585afb821f
commit 1029e6ebd6
3 changed files with 12 additions and 2 deletions

View File

@ -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]);

View File

@ -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");

View File

@ -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
*/