mobility-toolbox-js 3.0.0-beta.8 → 3.0.0
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/README.md +11 -3
- package/api/HttpAPI.d.ts +20 -0
- package/api/HttpAPI.js +1 -14
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +265 -206
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +17 -11
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -165
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +32 -32
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -11
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -10
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +102 -0
- package/common/typedefs.js +6 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +2 -0
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +6 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.js +7 -6
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.js +2 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +38 -0
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +29 -0
- package/maplibre/layers/Layer.js +2 -3
- package/maplibre/layers/RealtimeLayer.d.ts +124 -0
- package/maplibre/layers/RealtimeLayer.js +154 -118
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
- package/maplibre/utils/getSourceCoordinates.js +6 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +14585 -14557
- package/mbt.js.map +4 -4
- package/mbt.min.js +75 -75
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +39 -0
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +213 -0
- package/ol/controls/RoutingControl.js +250 -264
- package/ol/controls/StopFinderControl.d.ts +56 -0
- package/ol/controls/StopFinderControl.js +24 -5
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/Layer.d.ts +26 -0
- package/ol/layers/Layer.js +39 -0
- package/ol/layers/MaplibreLayer.d.ts +91 -0
- package/ol/layers/MaplibreLayer.js +154 -31
- package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
- package/ol/layers/MaplibreStyleLayer.js +281 -210
- package/ol/layers/RealtimeLayer.d.ts +150 -0
- package/ol/layers/RealtimeLayer.js +210 -206
- package/ol/layers/VectorLayer.d.ts +17 -0
- package/ol/layers/VectorLayer.js +33 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +50 -70
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +3 -0
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
- package/ol/utils/index.d.ts +1 -0
- package/package.json +44 -44
- package/setupTests.d.ts +1 -0
- package/setupTests.js +17 -4
- package/types/common.d.ts +53 -69
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +98 -95
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/common/mixins/RealtimeLayerMixin.js +0 -743
- package/ol/layers/MapGlLayer.js +0 -142
- package/ol/mixins/MobilityLayerMixin.js +0 -9
- package/ol/mixins/PropertiesLayerMixin.js +0 -142
package/api/RealtimeAPI.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
/* eslint-disable class-methods-use-this */
|
|
3
|
-
import WebSocketAPI from './WebSocketAPI';
|
|
4
2
|
import debounceWebsocketMessages from '../common/utils/debounceWebsocketMessages';
|
|
5
3
|
import getModeSuffix from '../common/utils/getRealtimeModeSuffix';
|
|
4
|
+
/* eslint-disable class-methods-use-this */
|
|
5
|
+
import WebSocketAPI from './WebSocketAPI';
|
|
6
6
|
/**
|
|
7
7
|
* Enum for Realtime modes.
|
|
8
8
|
* @readonly
|
|
@@ -11,14 +11,15 @@ import getModeSuffix from '../common/utils/getRealtimeModeSuffix';
|
|
|
11
11
|
* @property {string} SCHEMATIC "schematic"
|
|
12
12
|
* @property {string} TOPOGRAPHIC "topographic"
|
|
13
13
|
* @enum {RealtimeMode}
|
|
14
|
+
* @public
|
|
14
15
|
*/
|
|
15
16
|
export const RealtimeModes = {
|
|
16
17
|
RAW: 'raw',
|
|
17
|
-
TOPOGRAPHIC: 'topographic',
|
|
18
18
|
SCHEMATIC: 'schematic',
|
|
19
|
+
TOPOGRAPHIC: 'topographic',
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
|
-
* This class provides convenience methods to use to the [geOps
|
|
22
|
+
* This class provides convenience methods to use to the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* import { RealtimeAPI } from 'mobility-toolbox-js/api';
|
|
@@ -29,27 +30,27 @@ export const RealtimeModes = {
|
|
|
29
30
|
* // url: "wss://api.geops.io/tracker-ws/v1/",
|
|
30
31
|
* });
|
|
31
32
|
*
|
|
33
|
+
* // Open the websocket connection
|
|
32
34
|
* api.open();
|
|
33
35
|
*
|
|
36
|
+
* // Subscribe to channel
|
|
34
37
|
* api.subscribeTrajectory('topographic', (data) => {
|
|
35
38
|
* console.log('Log trajectories:', JSON.stringify(data.content));
|
|
36
39
|
* });
|
|
37
40
|
*
|
|
41
|
+
* // Close the websocket connection
|
|
42
|
+
* api.close();
|
|
43
|
+
*
|
|
38
44
|
* @public
|
|
39
45
|
*/
|
|
40
46
|
class RealtimeAPI {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (this.wsApi.open || this.wsApi.connecting) {
|
|
49
|
-
this.open();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
47
|
+
/**
|
|
48
|
+
* This callback type is called `requestCallback` and is displayed as a global symbol.
|
|
49
|
+
*
|
|
50
|
+
* @callback onFullTrajectoryMessageCallback
|
|
51
|
+
* @param {number} responseCode
|
|
52
|
+
* @param {string} responseMessage
|
|
53
|
+
*/
|
|
53
54
|
/**
|
|
54
55
|
* The bounding box to receive data from.\
|
|
55
56
|
* Example: [minX, minY, maxX, maxY, zoom, mots , gen_level, tenant, ...]\
|
|
@@ -102,13 +103,25 @@ class RealtimeAPI {
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
get url() {
|
|
107
|
+
return this._url;
|
|
108
|
+
}
|
|
109
|
+
set url(newUrl) {
|
|
110
|
+
if (this._url !== newUrl) {
|
|
111
|
+
this._url = newUrl;
|
|
112
|
+
// Update the websocket only if the url has changed and the websocket is already open or is opening.
|
|
113
|
+
if (this.wsApi.open || this.wsApi.connecting) {
|
|
114
|
+
this.open();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
105
118
|
/**
|
|
106
119
|
* Constructor
|
|
107
120
|
*
|
|
108
|
-
* @param {Object} options
|
|
109
|
-
* @param {string} options.url Url to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
|
|
121
|
+
* @param {Object} options Options.
|
|
110
122
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
111
123
|
* @param {string[]} options.bbox The bounding box to receive data from.
|
|
124
|
+
* @param {string} [options.url='wss://api.geops.io/tracker-ws/v1/'] Url of the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
|
|
112
125
|
* @public
|
|
113
126
|
*/
|
|
114
127
|
constructor(options = {}) {
|
|
@@ -126,6 +139,7 @@ class RealtimeAPI {
|
|
|
126
139
|
}
|
|
127
140
|
this._url = (url || 'wss://api.geops.io/tracker-ws/v1/') + suffix;
|
|
128
141
|
this._buffer = opt.buffer || [100, 100];
|
|
142
|
+
this._bbox = opt.bbox;
|
|
129
143
|
this.version = opt.version || '2';
|
|
130
144
|
/**
|
|
131
145
|
* Interval between PING request in ms.
|
|
@@ -144,32 +158,111 @@ class RealtimeAPI {
|
|
|
144
158
|
this.wsApi = wsApi;
|
|
145
159
|
}
|
|
146
160
|
/**
|
|
147
|
-
*
|
|
161
|
+
* Close the websocket connection without reconnection.
|
|
148
162
|
*
|
|
149
163
|
* @public
|
|
150
164
|
*/
|
|
151
|
-
|
|
152
|
-
this.wsApi.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
close() {
|
|
166
|
+
this.wsApi.close();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Send GET to a channel.
|
|
170
|
+
*
|
|
171
|
+
* @param {string | WebSocketAPIParameters} channelOrParams Name of the websocket channel to send GET or an object representing parameters to send
|
|
172
|
+
* @return {Promise<WebSocketAPIMessageEventData<?>>} A websocket response.
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
get(channelOrParams) {
|
|
176
|
+
let params = channelOrParams;
|
|
177
|
+
if (typeof channelOrParams === 'string') {
|
|
178
|
+
params = { channel: channelOrParams };
|
|
158
179
|
}
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
this.wsApi.get(params, resolve, reject);
|
|
182
|
+
});
|
|
159
183
|
}
|
|
160
184
|
/**
|
|
161
|
-
*
|
|
185
|
+
* Get a full trajectory of a vehicule .
|
|
162
186
|
*
|
|
187
|
+
* @param {string} id A vehicle id.
|
|
188
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
189
|
+
* @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
|
|
190
|
+
* @return {Promise<{data: { content: RealtimeFullTrajectory }}>} Return a full trajectory.
|
|
163
191
|
* @public
|
|
164
192
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
193
|
+
getFullTrajectory(id, mode, generalizationLevel) {
|
|
194
|
+
let suffix = '';
|
|
195
|
+
if (this.version === '1') {
|
|
196
|
+
suffix = getModeSuffix(mode, RealtimeModes);
|
|
197
|
+
}
|
|
198
|
+
const channel = [`full_trajectory${suffix}`];
|
|
199
|
+
if (id) {
|
|
200
|
+
channel.push(id);
|
|
201
|
+
}
|
|
202
|
+
if ((!mode || mode === RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
|
|
203
|
+
channel.push(`gen${generalizationLevel}`);
|
|
204
|
+
}
|
|
205
|
+
return this.get(channel.join('_'));
|
|
167
206
|
}
|
|
168
207
|
/**
|
|
169
|
-
*
|
|
208
|
+
* Return a station with a given uic number and a mode.
|
|
209
|
+
*
|
|
210
|
+
* @param {number} uic UIC of the station.
|
|
211
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
212
|
+
* @return {Promise<{data: { content: RealtimeStation }}>} A station.
|
|
213
|
+
* @public
|
|
170
214
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
215
|
+
getStation(uic, mode) {
|
|
216
|
+
const params = {
|
|
217
|
+
args: uic,
|
|
218
|
+
channel: `station${getModeSuffix(mode, RealtimeModes)}`,
|
|
219
|
+
};
|
|
220
|
+
return this.get(params);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the list of ststions available for a specifc mode. The promise is resolved every 100ms
|
|
224
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
225
|
+
* @param {number} timeout = 100 Duration in ms between each promise resolve calls.
|
|
226
|
+
* @return {Promise<RealtimeStation[]>} An array of stations.
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
getStations(mode, timeout = 100) {
|
|
230
|
+
return new Promise((resolve) => {
|
|
231
|
+
this.get(`station${getModeSuffix(mode, RealtimeModes)}`).then(debounceWebsocketMessages(resolve, undefined, timeout));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get the list of stops for this vehicle.
|
|
236
|
+
*
|
|
237
|
+
* @param {string} id A vehicle id.
|
|
238
|
+
* @return {Promise<{data: { content: RealtimeStopSequence[] }}>} Returns a stop sequence object.
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
getStopSequence(id) {
|
|
242
|
+
return this.get(`stopsequence_${id}`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Return a partial trajectory with a given id and a mode.
|
|
246
|
+
*
|
|
247
|
+
* @param {number} id The identifier of a trajectory.
|
|
248
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
249
|
+
* @return {Promise<{data: { content: RealtimeTrajectory }}>} A trajectory.
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
getTrajectory(id, mode) {
|
|
253
|
+
return this.get(`partial_trajectory${getModeSuffix(mode, RealtimeModes)}_${id}`);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Callback when the websocket is closed by the server.
|
|
257
|
+
* It auto reconnects after a timeout.
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
onClose() {
|
|
261
|
+
window.clearTimeout(this.pingInterval);
|
|
262
|
+
window.clearTimeout(this.reconnectTimeout);
|
|
263
|
+
if (this.reconnectTimeoutMs) {
|
|
264
|
+
this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
|
|
265
|
+
}
|
|
173
266
|
}
|
|
174
267
|
/**
|
|
175
268
|
* Callback when the websocket is opened and ready.
|
|
@@ -194,31 +287,24 @@ class RealtimeAPI {
|
|
|
194
287
|
}
|
|
195
288
|
}
|
|
196
289
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @
|
|
290
|
+
* Open the websocket connection.
|
|
291
|
+
*
|
|
292
|
+
* @public
|
|
200
293
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (this.
|
|
205
|
-
this.
|
|
294
|
+
open() {
|
|
295
|
+
this.wsApi.connect(this.url, this.onOpen.bind(this));
|
|
296
|
+
// Register reconnection on close.
|
|
297
|
+
if (this.wsApi.websocket) {
|
|
298
|
+
this.wsApi.websocket.onclose = () => {
|
|
299
|
+
this.onClose();
|
|
300
|
+
};
|
|
206
301
|
}
|
|
207
302
|
}
|
|
208
303
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* @param {string | WebSocketAPIParameters} channelOrParams Name of the websocket channel to send GET or an object representing parameters to send
|
|
212
|
-
* @return {Promise<WebSocketAPIMessageEventData<?>>} A websocket response.
|
|
304
|
+
* Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
|
|
213
305
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (typeof channelOrParams === 'string') {
|
|
217
|
-
params = { channel: channelOrParams };
|
|
218
|
-
}
|
|
219
|
-
return new Promise((resolve, reject) => {
|
|
220
|
-
this.wsApi.get(params, resolve, reject);
|
|
221
|
-
});
|
|
306
|
+
reset() {
|
|
307
|
+
this.wsApi.send('RESET');
|
|
222
308
|
}
|
|
223
309
|
/**
|
|
224
310
|
* Subscribe to a channel.
|
|
@@ -227,7 +313,7 @@ class RealtimeAPI {
|
|
|
227
313
|
* @param {function} onSuccess Callback when the subscription succeeds.
|
|
228
314
|
* @param {function} onError Callback when the subscription fails.
|
|
229
315
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
230
|
-
* @
|
|
316
|
+
* @public
|
|
231
317
|
*/
|
|
232
318
|
subscribe(channel, onSuccess, onError = () => { }, quiet = false) {
|
|
233
319
|
if (!channel || !onSuccess) {
|
|
@@ -236,87 +322,93 @@ class RealtimeAPI {
|
|
|
236
322
|
this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
|
|
237
323
|
}
|
|
238
324
|
/**
|
|
239
|
-
*
|
|
325
|
+
* Subscribe to deleted_vhicles channel.
|
|
240
326
|
*
|
|
241
|
-
* @param {
|
|
242
|
-
* @param {
|
|
243
|
-
* @param {function}
|
|
244
|
-
* @
|
|
327
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
328
|
+
* @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
329
|
+
* @param {function} onError Callback when the subscription fails.
|
|
330
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
331
|
+
* @public
|
|
245
332
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
this.
|
|
250
|
-
|
|
333
|
+
subscribeDeletedVehicles(mode, onMessage, onError = () => { }, quiet = false) {
|
|
334
|
+
this.unsubscribeDeletedVehicles(onMessage);
|
|
335
|
+
let suffix = '';
|
|
336
|
+
if (this.version === '1') {
|
|
337
|
+
suffix = getModeSuffix(mode, RealtimeModes);
|
|
338
|
+
}
|
|
339
|
+
this.subscribe(`deleted_vehicles${suffix}`, onMessage, onError, quiet);
|
|
251
340
|
}
|
|
252
341
|
/**
|
|
253
342
|
* Subscribe to departures channel of a given station.
|
|
254
343
|
*
|
|
255
344
|
* @param {number} stationId UIC of the station.
|
|
256
|
-
* @param {
|
|
257
|
-
* @param {function(departures:Departure[])} onMessage Function called on each message of the channel.
|
|
345
|
+
* @param {function(departures: RealtimeDeparture[])} onMessage Function called on each message of the channel.
|
|
258
346
|
* @param {function} onError Callback when the subscription fails.
|
|
259
347
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
260
|
-
* @
|
|
348
|
+
* @deprecated Use subscribeTimetable instead.
|
|
261
349
|
*/
|
|
262
350
|
subscribeDepartures(stationId, onMessage, onError = () => { }, quiet = false) {
|
|
263
|
-
this.
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Unsubscribe from current departures channel.
|
|
267
|
-
* @param {RealtimeStationId} id Station's id
|
|
268
|
-
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
269
|
-
* @public
|
|
270
|
-
*/
|
|
271
|
-
unsubscribeDepartures(id, onMessage) {
|
|
272
|
-
this.unsubscribe(`timetable_${id}`, '', onMessage);
|
|
351
|
+
this.subscribeTimetable(stationId, onMessage, onError, quiet);
|
|
273
352
|
}
|
|
274
353
|
/**
|
|
275
354
|
* Subscribe to the disruptions channel for tenant.
|
|
276
355
|
*
|
|
356
|
+
* @param {RealtimeTenant} tenant Tenant's id
|
|
277
357
|
* @param {function(data: { content: RealtimeNews[] })} onMessage Function called on each message of the channel.
|
|
278
358
|
* @param {function} onError Callback when the subscription fails.
|
|
279
359
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
280
|
-
* @
|
|
360
|
+
* @deprecated Use subscribeNewsticker instead.
|
|
281
361
|
*/
|
|
282
362
|
subscribeDisruptions(tenant, onMessage, onError = () => { }, quiet = false) {
|
|
283
|
-
this.
|
|
363
|
+
this.subscribeNewsticker(tenant, onMessage, onError, quiet);
|
|
284
364
|
}
|
|
285
365
|
/**
|
|
286
|
-
*
|
|
366
|
+
* Subscribe to extra_geoms channel.
|
|
287
367
|
*
|
|
288
|
-
* @param {function(data: { content:
|
|
289
|
-
* @
|
|
368
|
+
* @param {function(data: { content: RealtimeExtraGeom })} onMessage Function called on each message of the channel.
|
|
369
|
+
* @param {function} onError Callback when the subscription fails.
|
|
370
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
290
371
|
*/
|
|
291
|
-
|
|
292
|
-
this.
|
|
372
|
+
subscribeExtraGeoms(onMessage, onError = () => { }, quiet = false) {
|
|
373
|
+
this.subscribe('extra_geoms', onMessage, onError, quiet);
|
|
293
374
|
}
|
|
294
375
|
/**
|
|
295
|
-
*
|
|
376
|
+
* Subscribe to full_trajectory channel of a given vehicle.
|
|
296
377
|
*
|
|
297
|
-
* @param {
|
|
378
|
+
* @param {string} id A vehicle id.
|
|
298
379
|
* @param {RealtimeMode} mode Realtime mode.
|
|
299
|
-
* @
|
|
380
|
+
* @param {function(data:{content: RealtimeFullTrajectory})} onMessage Function called on each message of the channel.
|
|
381
|
+
* @param {function} onError Callback when the subscription fails.
|
|
382
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
300
383
|
* @public
|
|
301
384
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
385
|
+
subscribeFullTrajectory(id, mode, onMessage, onError = () => { }, quiet = false) {
|
|
386
|
+
let suffix = '';
|
|
387
|
+
if (this.version === '1') {
|
|
388
|
+
suffix = getModeSuffix(mode, RealtimeModes);
|
|
389
|
+
}
|
|
390
|
+
this.subscribe(`full_trajectory${suffix}_${id}`, onMessage, onError, quiet);
|
|
308
391
|
}
|
|
309
392
|
/**
|
|
310
|
-
*
|
|
311
|
-
* @param {
|
|
312
|
-
* @param {
|
|
313
|
-
* @
|
|
393
|
+
* Subscribe to healthcheck channel.
|
|
394
|
+
* @param {function(data: { content: string })} onMessage Callback when the subscribe to healthcheck channel succeeds.
|
|
395
|
+
* @param {function} onError Callback when the subscription fails.
|
|
396
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
397
|
+
*/
|
|
398
|
+
subscribeHealthCheck(onMessage, onError = () => { }, quiet = false) {
|
|
399
|
+
this.subscribe('healthcheck', onMessage, onError, quiet);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Subscribe to the newsticker channel for tenant.
|
|
403
|
+
*
|
|
404
|
+
* @param {RealtimeTenant} tenant Tenant's id
|
|
405
|
+
* @param {function(data: { content: RealtimeNews[] })} onMessage Function called on each message of the channel.
|
|
406
|
+
* @param {function} onError Callback when the subscription fails.
|
|
407
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
314
408
|
* @public
|
|
315
409
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.get(`station${getModeSuffix(mode, RealtimeModes)}`).then(debounceWebsocketMessages(resolve, undefined, timeout));
|
|
319
|
-
});
|
|
410
|
+
subscribeNewsticker(tenant, onMessage, onError = () => { }, quiet = false) {
|
|
411
|
+
this.subscribe(`${tenant}_newsticker`, onMessage, onError, quiet);
|
|
320
412
|
}
|
|
321
413
|
/**
|
|
322
414
|
* Subscribe to stations channel.
|
|
@@ -332,46 +424,34 @@ class RealtimeAPI {
|
|
|
332
424
|
this.subscribe(`station${getModeSuffix(mode, RealtimeModes)}`, onMessage, onError, quiet);
|
|
333
425
|
}
|
|
334
426
|
/**
|
|
335
|
-
*
|
|
336
|
-
* @param {function(data: { content: RealtimeStation })} onMessage The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
|
|
337
|
-
* @public
|
|
338
|
-
*/
|
|
339
|
-
unsubscribeStations(onMessage) {
|
|
340
|
-
this.unsubscribe('station', '', onMessage);
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Subscribe to extra_geoms channel.
|
|
427
|
+
* Subscribe to stopsequence channel of a given vehicle.
|
|
344
428
|
*
|
|
345
|
-
* @param {
|
|
429
|
+
* @param {string} id A vehicle id.
|
|
430
|
+
* @param {function(data: { content: RealtimeStopSequence[] })} onMessage Function called on each message of the channel.
|
|
346
431
|
* @param {function} onError Callback when the subscription fails.
|
|
347
432
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
433
|
+
* @public
|
|
348
434
|
*/
|
|
349
|
-
|
|
350
|
-
this.subscribe(
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Unsubscribe to extra_geoms channel.
|
|
354
|
-
* @param {function(data: { content: RealtimeExtraGeom })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
355
|
-
*/
|
|
356
|
-
unsubscribeExtraGeoms(onMessage) {
|
|
357
|
-
this.unsubscribe('extra_geoms', '', onMessage);
|
|
435
|
+
subscribeStopSequence(id, onMessage, onError = () => { }, quiet = false) {
|
|
436
|
+
this.subscribe(`stopsequence_${id}`, onMessage, onError, quiet);
|
|
358
437
|
}
|
|
359
438
|
/**
|
|
360
|
-
*
|
|
439
|
+
* Subscribe to timetable channel of a given station.
|
|
361
440
|
*
|
|
362
|
-
* @param {number}
|
|
363
|
-
* @param {
|
|
364
|
-
* @
|
|
441
|
+
* @param {number} stationId UIC of the station.
|
|
442
|
+
* @param {function(departures: RealtimeDeparture[])} onMessage Function called on each message of the channel.
|
|
443
|
+
* @param {function} onError Callback when the subscription fails.
|
|
444
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
365
445
|
* @public
|
|
366
446
|
*/
|
|
367
|
-
|
|
368
|
-
|
|
447
|
+
subscribeTimetable(stationId, onMessage, onError = () => { }, quiet = false) {
|
|
448
|
+
this.subscribe(`timetable_${stationId}`, onMessage, onError, quiet);
|
|
369
449
|
}
|
|
370
450
|
/**
|
|
371
451
|
* Subscribe to trajectory channel.
|
|
372
452
|
*
|
|
373
453
|
* @param {RealtimeMode} mode Realtime mode.
|
|
374
|
-
* @param {function(data: { content:
|
|
454
|
+
* @param {function(data: { content: RealtimeTrajectory })} onMessage Function called on each message of the channel.
|
|
375
455
|
* @param {function} onError Callback when the subscription fails.
|
|
376
456
|
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
377
457
|
* @public
|
|
@@ -385,133 +465,112 @@ class RealtimeAPI {
|
|
|
385
465
|
this.subscribe(`trajectory${suffix}`, onMessage, onError, quiet);
|
|
386
466
|
}
|
|
387
467
|
/**
|
|
388
|
-
* Unsubscribe
|
|
389
|
-
* @param {function(data: { content: RealtimeTrajectoryResponse[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
390
|
-
* @public
|
|
391
|
-
*/
|
|
392
|
-
unsubscribeTrajectory(onMessage) {
|
|
393
|
-
this.unsubscribe(`trajectory`, '', onMessage);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Subscribe to deleted_vhicles channel.
|
|
468
|
+
* Unsubscribe both modes of a channel.
|
|
397
469
|
*
|
|
398
|
-
* @param {
|
|
399
|
-
* @param {
|
|
400
|
-
* @param {function}
|
|
401
|
-
* @
|
|
470
|
+
* @param {string} channel Name of the websocket channel to unsubscribe.
|
|
471
|
+
* @param {string} suffix Suffix to add to the channel name.
|
|
472
|
+
* @param {function} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
473
|
+
* @public
|
|
402
474
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
this.subscribe(`deleted_vehicles${suffix}`, onMessage, onError, quiet);
|
|
475
|
+
unsubscribe(channel, suffix = '', onMessage) {
|
|
476
|
+
const suffixSchenatic = getModeSuffix(RealtimeModes.SCHEMATIC, RealtimeModes);
|
|
477
|
+
const suffixTopographic = getModeSuffix(RealtimeModes.TOPOGRAPHIC, RealtimeModes);
|
|
478
|
+
this.wsApi.unsubscribe(`${channel}${suffixSchenatic}${suffix || ''}`, onMessage);
|
|
479
|
+
this.wsApi.unsubscribe(`${channel}${suffixTopographic}${suffix || ''}`, onMessage);
|
|
410
480
|
}
|
|
411
481
|
/**
|
|
412
482
|
* Unsubscribe to deleted_vhicles channels.
|
|
413
483
|
* @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
484
|
+
* @public
|
|
414
485
|
*/
|
|
415
486
|
unsubscribeDeletedVehicles(onMessage) {
|
|
416
487
|
this.unsubscribe('deleted_vehicles', '', onMessage);
|
|
417
488
|
}
|
|
418
489
|
/**
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* @param {
|
|
422
|
-
* @
|
|
423
|
-
* @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
|
|
424
|
-
* @return {Promise<{ data: { content: RealtimeFullTrajectory } }>} Return a full trajectory.
|
|
425
|
-
* @public
|
|
490
|
+
* Unsubscribe from current departures channel.
|
|
491
|
+
* @param {number} stationId UIC of the station.
|
|
492
|
+
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
493
|
+
* @deprecated Use RealtimeAPI.unsubscribeTimetabe instead.
|
|
426
494
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (this.version === '1') {
|
|
430
|
-
suffix = getModeSuffix(mode, RealtimeModes);
|
|
431
|
-
}
|
|
432
|
-
const channel = [`full_trajectory${suffix}`];
|
|
433
|
-
if (id) {
|
|
434
|
-
channel.push(id);
|
|
435
|
-
}
|
|
436
|
-
if ((!mode || mode === RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
|
|
437
|
-
channel.push(`gen${generalizationLevel}`);
|
|
438
|
-
}
|
|
439
|
-
return this.get(channel.join('_'));
|
|
495
|
+
unsubscribeDepartures(stationId, onMessage) {
|
|
496
|
+
this.unsubscribeTimetable(stationId, onMessage);
|
|
440
497
|
}
|
|
441
498
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* @param {
|
|
445
|
-
* @
|
|
446
|
-
* @param {function(data: { content: RealtimeFullTrajectory })} onMessage Function called on each message of the channel.
|
|
447
|
-
* @param {function} onError Callback when the subscription fails.
|
|
448
|
-
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
449
|
-
* @public
|
|
499
|
+
* Unsubscribe disruptions.
|
|
500
|
+
* @param {RealtimeTenant} tenant Tenant's id
|
|
501
|
+
* @param {Function(data: { content: RealtimeNews[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
502
|
+
* @deprecated Use unsubscribeNewsticker instead.
|
|
450
503
|
*/
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
504
|
+
unsubscribeDisruptions(tenant, onMessage) {
|
|
505
|
+
this.unsubscribeNewsticker(tenant, onMessage);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Unsubscribe to extra_geoms channel.
|
|
509
|
+
* @param {function(data: { content: RealtimeExtraGeom })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
510
|
+
*/
|
|
511
|
+
unsubscribeExtraGeoms(onMessage) {
|
|
512
|
+
this.unsubscribe('extra_geoms', '', onMessage);
|
|
457
513
|
}
|
|
458
514
|
/**
|
|
459
515
|
* Unsubscribe from full_trajectory channel
|
|
460
516
|
*
|
|
461
517
|
* @param {string} id A vehicle id.
|
|
462
|
-
* @param {
|
|
518
|
+
* @param {onFullTrajectoryMessageCallback} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
463
519
|
* @public
|
|
464
520
|
*/
|
|
465
521
|
unsubscribeFullTrajectory(id, onMessage) {
|
|
466
522
|
this.unsubscribe('full_trajectory', `_${id}`, onMessage);
|
|
467
523
|
}
|
|
468
524
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
|
|
472
|
-
|
|
525
|
+
* Unsubscribe to healthcheck channel.
|
|
526
|
+
* @param {function(data: { content: string })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
527
|
+
*/
|
|
528
|
+
unsubscribeHealthCheck(onMessage) {
|
|
529
|
+
this.unsubscribe('healthcheck', '', onMessage);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Unsubscribe disruptions.
|
|
533
|
+
* @param {RealtimeTenant} tenant Tenant's id
|
|
534
|
+
* @param {Function(data: { content: RealtimeNews[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
473
535
|
* @public
|
|
474
536
|
*/
|
|
475
|
-
|
|
476
|
-
|
|
537
|
+
unsubscribeNewsticker(tenant, onMessage) {
|
|
538
|
+
this.unsubscribe(`${tenant}_newsticker`, '', onMessage);
|
|
477
539
|
}
|
|
478
540
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* @param {string} id A vehicle id.
|
|
482
|
-
* @param {function(data: { content: StopSequence[] })} onMessage Function called on each message of the channel.
|
|
483
|
-
* @param {function} onError Callback when the subscription fails.
|
|
484
|
-
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
541
|
+
* Unsubscribe to stations channel.
|
|
542
|
+
* @param {function(data: { content: RealtimeStation })} onMessage The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
|
|
485
543
|
* @public
|
|
486
544
|
*/
|
|
487
|
-
|
|
488
|
-
this.
|
|
545
|
+
unsubscribeStations(onMessage) {
|
|
546
|
+
this.unsubscribe('station', '', onMessage);
|
|
489
547
|
}
|
|
490
548
|
/**
|
|
491
549
|
* Unsubscribe from stopsequence channel
|
|
492
550
|
*
|
|
493
551
|
* @param {string} id A vehicle id.
|
|
494
|
-
* @param {function(data: { content:
|
|
552
|
+
* @param {function(data: { content: RealtimeStopSequence[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
495
553
|
* @public
|
|
496
554
|
*/
|
|
497
555
|
unsubscribeStopSequence(id, onMessage) {
|
|
498
556
|
this.unsubscribe(`stopsequence`, `_${id}`, onMessage);
|
|
499
557
|
}
|
|
500
558
|
/**
|
|
501
|
-
*
|
|
502
|
-
* @param {
|
|
503
|
-
* @param {function}
|
|
504
|
-
* @
|
|
559
|
+
* Unsubscribe from current departures channel.
|
|
560
|
+
* @param {number} stationId UIC of the station.
|
|
561
|
+
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
562
|
+
* @public
|
|
505
563
|
*/
|
|
506
|
-
|
|
507
|
-
this.
|
|
564
|
+
unsubscribeTimetable(stationId, onMessage) {
|
|
565
|
+
this.unsubscribe(`timetable_${stationId}`, '', onMessage);
|
|
508
566
|
}
|
|
509
567
|
/**
|
|
510
|
-
* Unsubscribe to
|
|
511
|
-
* @param {function(data: { content:
|
|
568
|
+
* Unsubscribe to trajectory channels.
|
|
569
|
+
* @param {function(data: { content: RealtimeTrajectory })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
570
|
+
* @public
|
|
512
571
|
*/
|
|
513
|
-
|
|
514
|
-
this.unsubscribe(
|
|
572
|
+
unsubscribeTrajectory(onMessage) {
|
|
573
|
+
this.unsubscribe(`trajectory`, '', onMessage);
|
|
515
574
|
}
|
|
516
575
|
}
|
|
517
576
|
export default RealtimeAPI;
|