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.
Files changed (130) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +20 -0
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +404 -0
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +47 -0
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +44 -0
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +147 -0
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.d.ts +3 -0
  13. package/api/index.js +1 -1
  14. package/api/typedefs.d.ts +76 -0
  15. package/api/typedefs.js +27 -42
  16. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  17. package/common/controls/StopFinderControlCommon.js +32 -32
  18. package/common/index.d.ts +2 -0
  19. package/common/index.js +1 -1
  20. package/common/styles/index.d.ts +4 -0
  21. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  22. package/common/styles/realtimeDefaultStyle.js +6 -11
  23. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  24. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.js +5 -10
  26. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  27. package/common/styles/realtimeSimpleStyle.js +0 -1
  28. package/common/typedefs.d.ts +102 -0
  29. package/common/typedefs.js +6 -31
  30. package/common/utils/RealtimeEngine.d.ts +214 -0
  31. package/common/utils/RealtimeEngine.js +554 -0
  32. package/common/utils/compareDepartures.d.ts +10 -0
  33. package/common/utils/compareDepartures.js +2 -2
  34. package/common/utils/constants.d.ts +5 -0
  35. package/common/utils/createCanvas.d.ts +10 -0
  36. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  37. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  38. package/common/utils/createRealtimeFilters.d.ts +12 -0
  39. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  40. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  41. package/common/utils/getLayersAsFlatArray.d.ts +2 -0
  42. package/common/utils/getLayersAsFlatArray.js +0 -1
  43. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  44. package/common/utils/getMapGlCopyrights.js +3 -3
  45. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  46. package/common/utils/getRealtimeModeSuffix.js +1 -0
  47. package/common/utils/getUrlWithParams.d.ts +8 -0
  48. package/common/utils/getVehiclePosition.d.ts +17 -0
  49. package/common/utils/getVehiclePosition.js +6 -3
  50. package/common/utils/index.d.ts +16 -0
  51. package/common/utils/realtimeConfig.d.ts +64 -0
  52. package/common/utils/realtimeConfig.js +0 -1
  53. package/common/utils/removeDuplicate.d.ts +9 -0
  54. package/common/utils/renderTrajectories.d.ts +17 -0
  55. package/common/utils/renderTrajectories.js +7 -6
  56. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  57. package/common/utils/sortAndFilterDepartures.js +2 -1
  58. package/common/utils/sortByDelay.d.ts +3 -0
  59. package/common/utils/sortByDelay.js +5 -1
  60. package/common/utils/timeUtils.d.ts +23 -0
  61. package/common/utils/toMercatorExtent.d.ts +5 -0
  62. package/iife.d.ts +2 -0
  63. package/index.d.ts +9 -0
  64. package/maplibre/controls/CopyrightControl.d.ts +38 -0
  65. package/maplibre/controls/CopyrightControl.js +11 -8
  66. package/maplibre/controls/index.d.ts +1 -0
  67. package/maplibre/index.d.ts +5 -0
  68. package/maplibre/layers/Layer.d.ts +29 -0
  69. package/maplibre/layers/Layer.js +2 -3
  70. package/maplibre/layers/RealtimeLayer.d.ts +124 -0
  71. package/maplibre/layers/RealtimeLayer.js +154 -118
  72. package/maplibre/layers/index.d.ts +2 -0
  73. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  74. package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
  75. package/maplibre/utils/getSourceCoordinates.js +6 -5
  76. package/maplibre/utils/index.d.ts +2 -0
  77. package/mbt.js +14585 -14557
  78. package/mbt.js.map +4 -4
  79. package/mbt.min.js +75 -75
  80. package/mbt.min.js.map +4 -4
  81. package/ol/controls/CopyrightControl.d.ts +39 -0
  82. package/ol/controls/CopyrightControl.js +13 -5
  83. package/ol/controls/RoutingControl.d.ts +213 -0
  84. package/ol/controls/RoutingControl.js +250 -264
  85. package/ol/controls/StopFinderControl.d.ts +56 -0
  86. package/ol/controls/StopFinderControl.js +24 -5
  87. package/ol/controls/index.d.ts +3 -0
  88. package/ol/index.d.ts +6 -0
  89. package/ol/layers/Layer.d.ts +26 -0
  90. package/ol/layers/Layer.js +39 -0
  91. package/ol/layers/MaplibreLayer.d.ts +91 -0
  92. package/ol/layers/MaplibreLayer.js +154 -31
  93. package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
  94. package/ol/layers/MaplibreStyleLayer.js +281 -210
  95. package/ol/layers/RealtimeLayer.d.ts +150 -0
  96. package/ol/layers/RealtimeLayer.js +210 -206
  97. package/ol/layers/VectorLayer.d.ts +17 -0
  98. package/ol/layers/VectorLayer.js +33 -0
  99. package/ol/layers/index.d.ts +5 -0
  100. package/ol/layers/index.js +3 -0
  101. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  102. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  103. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  104. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  105. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  106. package/ol/renderers/RealtimeLayerRenderer.js +50 -70
  107. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  108. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  109. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  110. package/ol/styles/fullTrajectoryStyle.js +5 -7
  111. package/ol/styles/index.d.ts +3 -0
  112. package/ol/styles/routingStyle.d.ts +3 -0
  113. package/ol/styles/routingStyle.js +13 -10
  114. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  115. package/ol/utils/defineDeprecatedProperties.js +180 -0
  116. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  117. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  118. package/ol/utils/index.d.ts +1 -0
  119. package/package.json +44 -44
  120. package/setupTests.d.ts +1 -0
  121. package/setupTests.js +17 -4
  122. package/types/common.d.ts +53 -69
  123. package/types/index.d.ts +1 -1
  124. package/types/realtime.d.ts +98 -95
  125. package/types/routing.d.ts +60 -60
  126. package/types/stops.d.ts +62 -62
  127. package/common/mixins/RealtimeLayerMixin.js +0 -743
  128. package/ol/layers/MapGlLayer.js +0 -142
  129. package/ol/mixins/MobilityLayerMixin.js +0 -9
  130. package/ol/mixins/PropertiesLayerMixin.js +0 -142
@@ -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 realtime API](https://developer.geops.io/apis/realtime/).
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
- get url() {
42
- return this._url;
43
- }
44
- set url(newUrl) {
45
- if (this._url !== newUrl) {
46
- this._url = newUrl;
47
- // Update the websocket only if the url has changed and the websocket is already open or is opening.
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 A string representing the url of the service or an object containing the url and the apiKey.
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
- * Open the websocket connection.
161
+ * Close the websocket connection without reconnection.
148
162
  *
149
163
  * @public
150
164
  */
151
- open() {
152
- this.wsApi.connect(this.url, this.onOpen.bind(this));
153
- // Register reconnection on close.
154
- if (this.wsApi.websocket) {
155
- this.wsApi.websocket.onclose = () => {
156
- this.onClose();
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
- * Close the websocket connection without reconnection.
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
- close() {
166
- this.wsApi.close();
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
- * Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
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
- reset() {
172
- this.wsApi.send('RESET');
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
- * Callback when the websocket is closed by the server.
198
- * It auto reconnects after a timeout.
199
- * @private
290
+ * Open the websocket connection.
291
+ *
292
+ * @public
200
293
  */
201
- onClose() {
202
- window.clearTimeout(this.pingInterval);
203
- window.clearTimeout(this.reconnectTimeout);
204
- if (this.reconnectTimeoutMs) {
205
- this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
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
- * Send GET to a channel.
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
- get(channelOrParams) {
215
- let params = channelOrParams;
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
- * @private
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
- * Unsubscribe both modes of a channel.
325
+ * Subscribe to deleted_vhicles channel.
240
326
  *
241
- * @param {string} channel Name of the websocket channel to unsubscribe.
242
- * @param {string} suffix Suffix to add to the channel name.
243
- * @param {function} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
244
- * @private
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
- unsubscribe(channel, suffix = '', onMessage) {
247
- const suffixSchenatic = getModeSuffix(RealtimeModes.SCHEMATIC, RealtimeModes);
248
- const suffixTopographic = getModeSuffix(RealtimeModes.TOPOGRAPHIC, RealtimeModes);
249
- this.wsApi.unsubscribe(`${channel}${suffixSchenatic}${suffix || ''}`, onMessage);
250
- this.wsApi.unsubscribe(`${channel}${suffixTopographic}${suffix || ''}`, onMessage);
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 {Boolean} sortByMinArrivalTime Sort by minimum arrival time
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
- * @public
348
+ * @deprecated Use subscribeTimetable instead.
261
349
  */
262
350
  subscribeDepartures(stationId, onMessage, onError = () => { }, quiet = false) {
263
- this.subscribe(`timetable_${stationId}`, onMessage, onError, quiet);
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
- * @public
360
+ * @deprecated Use subscribeNewsticker instead.
281
361
  */
282
362
  subscribeDisruptions(tenant, onMessage, onError = () => { }, quiet = false) {
283
- this.subscribe(`${tenant}_newsticker`, onMessage, onError, quiet);
363
+ this.subscribeNewsticker(tenant, onMessage, onError, quiet);
284
364
  }
285
365
  /**
286
- * Unsubscribe disruptions.
366
+ * Subscribe to extra_geoms channel.
287
367
  *
288
- * @param {function(data: { content: RealtimeNews[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
289
- * @public
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
- unsubscribeDisruptions(tenant, onMessage) {
292
- this.unsubscribe(`${tenant}_newsticker`, '', onMessage);
372
+ subscribeExtraGeoms(onMessage, onError = () => { }, quiet = false) {
373
+ this.subscribe('extra_geoms', onMessage, onError, quiet);
293
374
  }
294
375
  /**
295
- * Return a station with a given uic number and a mode.
376
+ * Subscribe to full_trajectory channel of a given vehicle.
296
377
  *
297
- * @param {number} uic UIC of the station.
378
+ * @param {string} id A vehicle id.
298
379
  * @param {RealtimeMode} mode Realtime mode.
299
- * @return {Promise<{data: { content: RealtimeStation }}>} A station.
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
- getStation(uic, mode) {
303
- const params = {
304
- channel: `station${getModeSuffix(mode, RealtimeModes)}`,
305
- args: uic,
306
- };
307
- return this.get(params);
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
- * Get the list of ststions available for a specifc mode. The promise is resolved every 100ms
311
- * @param {RealtimeMode} mode Realtime mode.
312
- * @param {number} timeout = 100 Duration in ms between each promise resolve calls.
313
- * @return {Promise<RealtimeStation[]>} An array of stations.
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
- getStations(mode, timeout = 100) {
317
- return new Promise((resolve) => {
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
- * Unsubscribe to stations channel.
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 {function(data: { content: RealtimeExtraGeom })} onMessage Function called on each message of the channel.
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
- subscribeExtraGeoms(onMessage, onError = () => { }, quiet = false) {
350
- this.subscribe('extra_geoms', onMessage, onError, quiet);
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
- * Return a partial trajectory with a given id and a mode.
439
+ * Subscribe to timetable channel of a given station.
361
440
  *
362
- * @param {number} trainId The identifier of a trajectory.
363
- * @param {RealtimeMode} mode Realtime mode.
364
- * @return {Promise<{data: { content: RealtimeTrajectory }}>} A trajectory.
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
- getTrajectory(id, mode) {
368
- return this.get(`partial_trajectory${getModeSuffix(mode, RealtimeModes)}_${id}`);
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: RealtimeTrajectoryResponse[] })} onMessage Function called on each message of the channel.
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 to trajectory channels.
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 {RealtimeMode} mode Realtime mode.
399
- * @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
400
- * @param {function} onError Callback when the subscription fails.
401
- * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
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
- subscribeDeletedVehicles(mode, onMessage, onError = () => { }, quiet = false) {
404
- this.unsubscribeDeletedVehicles(onMessage);
405
- let suffix = '';
406
- if (this.version === '1') {
407
- suffix = getModeSuffix(mode, RealtimeModes);
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
- * Get a full trajectory of a vehicule .
420
- *
421
- * @param {string} id A vehicle id.
422
- * @param {RealtimeMode} mode Realtime mode.
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
- getFullTrajectory(id, mode, generalizationLevel) {
428
- let suffix = '';
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
- * Subscribe to full_trajectory channel of a given vehicle.
443
- *
444
- * @param {string} id A vehicle id.
445
- * @param {RealtimeMode} mode Realtime mode.
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
- subscribeFullTrajectory(id, mode, onMessage, onError = () => { }, quiet = false) {
452
- let suffix = '';
453
- if (this.version === '1') {
454
- suffix = getModeSuffix(mode, RealtimeModes);
455
- }
456
- this.subscribe(`full_trajectory${suffix}_${id}`, onMessage, onError, quiet);
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 {function(data: { content: RealtimeFullTrajectory })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
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
- * Get the list of stops for this vehicle.
470
- *
471
- * @param {string} id A vehicle id.
472
- * @return {Promise<{ data: { content: StopSequence[] } }>} Returns a stop sequence object.
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
- getStopSequence(id) {
476
- return this.get(`stopsequence_${id}`);
537
+ unsubscribeNewsticker(tenant, onMessage) {
538
+ this.unsubscribe(`${tenant}_newsticker`, '', onMessage);
477
539
  }
478
540
  /**
479
- * Subscribe to stopsequence channel of a given vehicle.
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
- subscribeStopSequence(id, onMessage, onError = () => { }, quiet = false) {
488
- this.subscribe(`stopsequence_${id}`, onMessage, onError, quiet);
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: StopSequence[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
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
- * Subscribe to healthcheck channel.
502
- * @param {function(data: { content: string })} onMessage Callback when the subscribe to healthcheck channel succeeds.
503
- * @param {function} onError Callback when the subscription fails.
504
- * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
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
- subscribeHealthCheck(onMessage, onError = () => { }, quiet = false) {
507
- this.subscribe('healthcheck', onMessage, onError, quiet);
564
+ unsubscribeTimetable(stationId, onMessage) {
565
+ this.unsubscribe(`timetable_${stationId}`, '', onMessage);
508
566
  }
509
567
  /**
510
- * Unsubscribe to healthcheck channel.
511
- * @param {function(data: { content: string })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
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
- unsubscribeHealthCheck(onMessage) {
514
- this.unsubscribe('healthcheck', '', onMessage);
572
+ unsubscribeTrajectory(onMessage) {
573
+ this.unsubscribe(`trajectory`, '', onMessage);
515
574
  }
516
575
  }
517
576
  export default RealtimeAPI;