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