@dexteel/mesf-core 7.22.1 → 7.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "7.22.1"
2
+ ".": "7.22.2"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [7.22.2](https://github.com/dexteel/mesf-core-frontend/compare/@dexteel/mesf-core-v7.22.1...@dexteel/mesf-core-v7.22.2) (2026-05-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **realtime:** share SignalR connection across subscribers ([023f7cf](https://github.com/dexteel/mesf-core-frontend/commit/023f7cf2805d1d9d1419c000a13480fd14d607f0))
9
+
3
10
  ## [7.22.1](https://github.com/dexteel/mesf-core-frontend/compare/@dexteel/mesf-core-v7.22.0...@dexteel/mesf-core-v7.22.1) (2026-05-11)
4
11
 
5
12
 
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
1
+ import { HubConnectionState, HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
2
2
  export * from '@microsoft/signalr';
3
3
  export { LicenseManager } from 'ag-grid-enterprise';
4
4
  import { styled, DialogTitle as DialogTitle$1, DialogContent as DialogContent$1, DialogActions as DialogActions$1, Grid2, Button, Box, MenuItem, ListItemIcon, createTheme, TextField, Alert as Alert$2, useTheme, InputAdornment, Popover, MenuList, ListItemText, alpha, Dialog as Dialog$1, Paper, List, ListItem, Chip, SvgIcon, Typography as Typography$1, Checkbox, IconButton as IconButton$1, CircularProgress, FormControl, FormHelperText, FormControlLabel, Snackbar, DialogContentText, Badge, InputLabel, Select, Input, Divider, Card, CardContent, CardActions, Collapse, Tooltip, CssBaseline, AppBar, Toolbar, Container, Menu, Switch, Autocomplete as Autocomplete$1, useMediaQuery, Drawer, Grid, Accordion, AccordionSummary, AccordionDetails, Tabs, Tab, ListSubheader, ListItemButton, StyledEngineProvider, ThemeProvider, ListItemSecondaryAction } from '@mui/material';
@@ -4341,34 +4341,63 @@ const DeleteUser = ({ userId, show, onHide, suffixTitle }) => {
4341
4341
  React__default.createElement(ErrorModal, { error: profileError, onHide: () => setprofileError(""), title: "Error Choosing Profile" })));
4342
4342
  };
4343
4343
 
4344
+ const receiveMessageHandlers = new Set();
4345
+ let connection = null;
4346
+ let startPromise = null;
4347
+ const getConnection = () => {
4348
+ if (connection)
4349
+ return connection;
4350
+ connection = new HubConnectionBuilder()
4351
+ .withUrl("/ws")
4352
+ .withAutomaticReconnect()
4353
+ .configureLogging(LogLevel.Information)
4354
+ .build();
4355
+ connection.on("ReceiveMessage", (author, message) => {
4356
+ receiveMessageHandlers.forEach((handler) => {
4357
+ handler(author, message);
4358
+ });
4359
+ });
4360
+ connection.onclose((error) => {
4361
+ if (error)
4362
+ console.log("SignalR connection closed", error);
4363
+ });
4364
+ return connection;
4365
+ };
4366
+ const startConnection = () => {
4367
+ const currentConnection = getConnection();
4368
+ if (currentConnection.state !== HubConnectionState.Disconnected) {
4369
+ return Promise.resolve();
4370
+ }
4371
+ if (startPromise)
4372
+ return startPromise;
4373
+ startPromise = currentConnection
4374
+ .start()
4375
+ .then(() => {
4376
+ console.log("SignalR connection started");
4377
+ })
4378
+ .catch((err) => {
4379
+ console.log("Error while starting SignalR connection: " + err);
4380
+ })
4381
+ .finally(() => {
4382
+ startPromise = null;
4383
+ });
4384
+ return startPromise;
4385
+ };
4386
+ const subscribeMesfRealtime = (handler) => {
4387
+ receiveMessageHandlers.add(handler);
4388
+ void startConnection();
4389
+ return () => {
4390
+ receiveMessageHandlers.delete(handler);
4391
+ };
4392
+ };
4393
+
4344
4394
  const useMesfRealtime = ({ onReceiveMessage }) => {
4395
+ const onReceiveMessageRef = useRef(onReceiveMessage);
4396
+ onReceiveMessageRef.current = onReceiveMessage;
4345
4397
  useEffect(() => {
4346
- const connection = new HubConnectionBuilder()
4347
- .withUrl("/ws")
4348
- .withAutomaticReconnect()
4349
- .configureLogging(LogLevel.Information)
4350
- .build();
4351
- connection
4352
- .start()
4353
- .then(() => {
4354
- console.log("Connection started");
4355
- })
4356
- .catch((err) => {
4357
- console.log("Error while starting connection: " + err);
4358
- });
4359
- connection.on("ReceiveMessage", (author, message) => {
4360
- onReceiveMessage(author, message);
4398
+ return subscribeMesfRealtime((author, message) => {
4399
+ onReceiveMessageRef.current(author, message);
4361
4400
  });
4362
- return () => {
4363
- connection
4364
- .stop()
4365
- .then(() => {
4366
- console.log("Connection stopped");
4367
- })
4368
- .catch((err) => {
4369
- console.log("Error while stopping connection: " + err);
4370
- });
4371
- };
4372
4401
  }, []);
4373
4402
  };
4374
4403
 
@@ -10265,6 +10294,7 @@ const ChatComponent = () => {
10265
10294
  const [user, setUser] = useState("");
10266
10295
  const [message, setMessage] = useState("");
10267
10296
  const messageEndRef = useRef(null);
10297
+ const connectionRef = useRef(null);
10268
10298
  const latestMessages = useRef([]);
10269
10299
  latestMessages.current = messages;
10270
10300
  const scrollToBottom = () => {
@@ -10281,6 +10311,7 @@ const ChatComponent = () => {
10281
10311
  .withAutomaticReconnect()
10282
10312
  .configureLogging(LogLevel.Information)
10283
10313
  .build();
10314
+ connectionRef.current = newConnection;
10284
10315
  newConnection.on("ReceiveMessage", (user, message) => {
10285
10316
  const newMessage = {
10286
10317
  user,
@@ -10311,7 +10342,9 @@ const ChatComponent = () => {
10311
10342
  useEffect(() => {
10312
10343
  startConnection();
10313
10344
  return () => {
10314
- connection === null || connection === void 0 ? void 0 : connection.stop();
10345
+ var _a;
10346
+ void ((_a = connectionRef.current) === null || _a === void 0 ? void 0 : _a.stop());
10347
+ connectionRef.current = null;
10315
10348
  };
10316
10349
  }, [startConnection]);
10317
10350
  const sendMessage = (e) => __awaiter(void 0, void 0, void 0, function* () {