@tmlmobilidade/controllers 20260203.1129.22 → 20260203.1404.18

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.
@@ -20,5 +20,5 @@ export declare class RidesSharedController {
20
20
  * WebSocket event handler.
21
21
  * @param socket The WebSocket object.
22
22
  */
23
- static websocket(socket: WebSocket): void;
23
+ static websocket(socket: WebSocket): () => void;
24
24
  }
@@ -106,26 +106,27 @@ export class RidesSharedController {
106
106
  * @param socket The WebSocket object.
107
107
  */
108
108
  static websocket(socket) {
109
- socket.on('message', async () => {
110
- //
111
- //
112
- // Create a listener that sends updates to this WebSocket client
113
- const listener = (message) => {
114
- if (socket.readyState === socket.OPEN && socket.bufferedAmount < 1_000_000) {
115
- socket.send(JSON.stringify(message));
116
- }
117
- };
118
- //
119
- // Subscribe to the singleton change stream
109
+ //
110
+ //
111
+ // Create a listener that sends updates to this WebSocket client
112
+ const listener = (message) => {
113
+ if (socket.readyState === socket.OPEN && socket.bufferedAmount < 1_000_000) {
114
+ socket.send(JSON.stringify(message));
115
+ }
116
+ };
117
+ //
118
+ // Subscribe to the singleton change stream
119
+ const subscribe = () => {
120
120
  ridesChangeStream.subscribe(listener);
121
- //
122
- // Cleanup: unsubscribe when socket closes or errors
123
- const cleanup = async () => {
124
- ridesChangeStream.unsubscribe(listener);
125
- };
126
- socket.on('close', cleanup);
127
- socket.on('error', cleanup);
128
- //
129
- });
121
+ };
122
+ //
123
+ // Cleanup the subscription to the singleton change stream
124
+ const cleanup = () => {
125
+ ridesChangeStream.unsubscribe(listener);
126
+ };
127
+ socket.on('open', subscribe);
128
+ socket.on('close', cleanup);
129
+ socket.on('error', cleanup);
130
+ return cleanup;
130
131
  }
131
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/controllers",
3
- "version": "20260203.1129.22",
3
+ "version": "20260203.1404.18",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"