mobility-toolbox-js 3.1.1 → 3.1.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.
- package/api/HttpAPI.d.ts +1 -1
- package/api/RealtimeAPI.d.ts +3 -3
- package/api/WebSocketAPI.d.ts +11 -11
- package/api/WebSocketAPI.js +5 -0
- package/common/utils/debounceWebsocketMessages.js +1 -1
- package/mbt.js +11878 -9319
- package/mbt.js.map +4 -4
- package/mbt.min.js +291 -143
- package/mbt.min.js.map +4 -4
- package/ol/layers/index.d.ts +1 -1
- package/ol/layers/index.js +2 -2
- package/ol/renderers/MaplibreLayerRenderer.d.ts +2 -1
- package/ol/renderers/MaplibreLayerRenderer.js +2 -2
- package/package.json +28 -28
- package/types/index.d.ts +1 -0
package/api/HttpAPI.d.ts
CHANGED
package/api/RealtimeAPI.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ declare class RealtimeAPI {
|
|
|
135
135
|
* @return {Promise<WebSocketAPIMessageEventData<?>>} A websocket response.
|
|
136
136
|
* @public
|
|
137
137
|
*/
|
|
138
|
-
get(channelOrParams: string | WebSocketAPIParameters): Promise<WebSocketAPIMessageEventData<
|
|
138
|
+
get<T>(channelOrParams: string | WebSocketAPIParameters): Promise<WebSocketAPIMessageEventData<T>>;
|
|
139
139
|
/**
|
|
140
140
|
* Get a full trajectory of a vehicule .
|
|
141
141
|
*
|
|
@@ -211,7 +211,7 @@ declare class RealtimeAPI {
|
|
|
211
211
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
212
212
|
* @public
|
|
213
213
|
*/
|
|
214
|
-
subscribe(channel: string, onSuccess: WebSocketAPIMessageCallback<
|
|
214
|
+
subscribe<T>(channel: string, onSuccess: WebSocketAPIMessageCallback<T>, onError?: EventListener, quiet?: boolean): void;
|
|
215
215
|
/**
|
|
216
216
|
* Subscribe to deleted_vhicles channel.
|
|
217
217
|
*
|
|
@@ -327,7 +327,7 @@ declare class RealtimeAPI {
|
|
|
327
327
|
* @param {function} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
328
328
|
* @public
|
|
329
329
|
*/
|
|
330
|
-
unsubscribe(channel: string, suffix?: string, onMessage?: WebSocketAPIMessageCallback<
|
|
330
|
+
unsubscribe<T>(channel: string, suffix?: string, onMessage?: WebSocketAPIMessageCallback<T>): void;
|
|
331
331
|
/**
|
|
332
332
|
* Unsubscribe to deleted_vhicles channels.
|
|
333
333
|
* @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
package/api/WebSocketAPI.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export type WebSocketAPIMessageEventListener = (evt: WebSocketAPIMessageEvent) =
|
|
|
21
21
|
* This type represents a function that has been call with each feature returned by the websocket.
|
|
22
22
|
*/
|
|
23
23
|
export type WebSocketAPIMessageCallback<T> = (data: WebSocketAPIMessageEventData<T>) => void;
|
|
24
|
-
export declare interface WebSocketAPISubscription {
|
|
25
|
-
cb: WebSocketAPIMessageCallback<
|
|
24
|
+
export declare interface WebSocketAPISubscription<T> {
|
|
25
|
+
cb: WebSocketAPIMessageCallback<T>;
|
|
26
26
|
errorCb?: EventListener;
|
|
27
27
|
onErrorCb?: EventListener;
|
|
28
28
|
onMessageCb: WebSocketAPIMessageEventListener;
|
|
@@ -30,8 +30,8 @@ export declare interface WebSocketAPISubscription {
|
|
|
30
30
|
quiet: boolean;
|
|
31
31
|
}
|
|
32
32
|
export type WebSocketAPISubscribed = Record<string, boolean>;
|
|
33
|
-
export declare interface WebSocketAPIRequest {
|
|
34
|
-
cb: WebSocketAPIMessageCallback<
|
|
33
|
+
export declare interface WebSocketAPIRequest<T> {
|
|
34
|
+
cb: WebSocketAPIMessageCallback<T>;
|
|
35
35
|
errorCb?: EventListener;
|
|
36
36
|
onErrorCb?: EventListener;
|
|
37
37
|
onMessageCb: WebSocketAPIMessageEventListener;
|
|
@@ -50,9 +50,9 @@ declare class WebSocketAPI {
|
|
|
50
50
|
connecting?: boolean;
|
|
51
51
|
messagesOnOpen: string[];
|
|
52
52
|
open?: boolean;
|
|
53
|
-
requests: WebSocketAPIRequest[];
|
|
53
|
+
requests: WebSocketAPIRequest<unknown>[];
|
|
54
54
|
subscribed: WebSocketAPISubscribed;
|
|
55
|
-
subscriptions: WebSocketAPISubscription[];
|
|
55
|
+
subscriptions: WebSocketAPISubscription<unknown>[];
|
|
56
56
|
websocket?: WebSocket;
|
|
57
57
|
constructor();
|
|
58
58
|
/**
|
|
@@ -92,7 +92,7 @@ declare class WebSocketAPI {
|
|
|
92
92
|
* @param {function} errorCb Callback on error and close event
|
|
93
93
|
* @private
|
|
94
94
|
*/
|
|
95
|
-
get(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<
|
|
95
|
+
get<T>(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<T>, errorCb?: EventListener): void;
|
|
96
96
|
/**
|
|
97
97
|
* Listen to websocket messages.
|
|
98
98
|
*
|
|
@@ -102,7 +102,7 @@ declare class WebSocketAPI {
|
|
|
102
102
|
* @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
|
|
103
103
|
* @private
|
|
104
104
|
*/
|
|
105
|
-
listen(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<
|
|
105
|
+
listen<T>(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<T>, errorCb?: EventListener): {
|
|
106
106
|
onErrorCb?: EventListener;
|
|
107
107
|
onMessageCb: WebSocketAPIMessageEventListener;
|
|
108
108
|
};
|
|
@@ -123,7 +123,7 @@ declare class WebSocketAPI {
|
|
|
123
123
|
* @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
|
|
124
124
|
* @private
|
|
125
125
|
*/
|
|
126
|
-
subscribe(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<
|
|
126
|
+
subscribe<T>(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<T>, errorCb?: EventListener, quiet?: boolean): void;
|
|
127
127
|
/**
|
|
128
128
|
* After an auto reconnection we need to re-subscribe to the channels.
|
|
129
129
|
*/
|
|
@@ -135,13 +135,13 @@ declare class WebSocketAPI {
|
|
|
135
135
|
* @param {function} cb Callback used when listen.
|
|
136
136
|
* @private
|
|
137
137
|
*/
|
|
138
|
-
unlisten(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<
|
|
138
|
+
unlisten<T>(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<T>): void;
|
|
139
139
|
/**
|
|
140
140
|
* Unsubscribe from a channel.
|
|
141
141
|
* @param {string} source source to unsubscribe from
|
|
142
142
|
* @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
143
143
|
* @private
|
|
144
144
|
*/
|
|
145
|
-
unsubscribe(source: string, cb?: WebSocketAPIMessageCallback<
|
|
145
|
+
unsubscribe<T>(source: string, cb?: WebSocketAPIMessageCallback<T>): void;
|
|
146
146
|
}
|
|
147
147
|
export default WebSocketAPI;
|
package/api/WebSocketAPI.js
CHANGED
|
@@ -167,9 +167,11 @@ class WebSocketAPI {
|
|
|
167
167
|
requestString,
|
|
168
168
|
};
|
|
169
169
|
if (index > -1) {
|
|
170
|
+
// @ts-expect-error - We know that the requests is an array of WebSocketAPIRequest
|
|
170
171
|
this.requests[index] = newReq;
|
|
171
172
|
}
|
|
172
173
|
else {
|
|
174
|
+
// @ts-expect-error - We know that the requests is an array of WebSocketAPIRequest
|
|
173
175
|
this.requests.push(newReq);
|
|
174
176
|
}
|
|
175
177
|
}
|
|
@@ -201,6 +203,7 @@ class WebSocketAPI {
|
|
|
201
203
|
// Buffer channel message return a list of other channels to propagate to proper callbacks.
|
|
202
204
|
let contents;
|
|
203
205
|
if (data.source === 'buffer') {
|
|
206
|
+
// @ts-expect-error - We know that the data is a WebSocketAPIBufferMessageEventData
|
|
204
207
|
contents = data
|
|
205
208
|
.content;
|
|
206
209
|
}
|
|
@@ -273,9 +276,11 @@ class WebSocketAPI {
|
|
|
273
276
|
const index = this.subscriptions.findIndex((subcr) => params.channel === subcr.params.channel && cb === subcr.cb);
|
|
274
277
|
const newSubscr = { cb, errorCb, onErrorCb, onMessageCb, params, quiet };
|
|
275
278
|
if (index > -1) {
|
|
279
|
+
// @ts-expect-error - We know that the subscriptions is an array of WebSocketAPISubscription
|
|
276
280
|
this.subscriptions[index] = newSubscr;
|
|
277
281
|
}
|
|
278
282
|
else {
|
|
283
|
+
// @ts-expect-error - We know that the subscriptions is an array of WebSocketAPISubscription
|
|
279
284
|
this.subscriptions.push(newSubscr);
|
|
280
285
|
}
|
|
281
286
|
if (!this.subscribed[reqStr]) {
|
|
@@ -11,7 +11,7 @@ const debounceWebsocketMessages = (onUpdate, getObjectId, timeout = 100) => {
|
|
|
11
11
|
const objectsById = {};
|
|
12
12
|
const objects = [];
|
|
13
13
|
return (data) => {
|
|
14
|
-
const {
|
|
14
|
+
const { content, source } = data;
|
|
15
15
|
if (updateTimeout[source]) {
|
|
16
16
|
window.clearTimeout(updateTimeout[source]);
|
|
17
17
|
}
|