@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.
- package/dist/rides/rides.d.ts +1 -1
- package/dist/rides/rides.js +21 -20
- package/package.json +1 -1
package/dist/rides/rides.d.ts
CHANGED
package/dist/rides/rides.js
CHANGED
|
@@ -106,26 +106,27 @@ export class RidesSharedController {
|
|
|
106
106
|
* @param socket The WebSocket object.
|
|
107
107
|
*/
|
|
108
108
|
static websocket(socket) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
}
|