mobility-toolbox-js 3.0.0-beta.8 → 3.0.0-beta.9

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 (81) hide show
  1. package/api/HttpAPI.d.ts +31 -0
  2. package/api/RealtimeAPI.d.ts +359 -0
  3. package/api/RoutingAPI.d.ts +37 -0
  4. package/api/StopsAPI.d.ts +38 -0
  5. package/api/WebSocketAPI.d.ts +153 -0
  6. package/api/index.d.ts +3 -0
  7. package/api/typedefs.d.ts +178 -0
  8. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  9. package/common/index.d.ts +2 -0
  10. package/common/mixins/RealtimeLayerMixin.d.ts +273 -0
  11. package/common/styles/index.d.ts +4 -0
  12. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  13. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  14. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  15. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  16. package/common/typedefs.d.ts +212 -0
  17. package/common/utils/compareDepartures.d.ts +10 -0
  18. package/common/utils/constants.d.ts +5 -0
  19. package/common/utils/createCanvas.d.ts +10 -0
  20. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  21. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  22. package/common/utils/createRealtimeFilters.d.ts +12 -0
  23. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  24. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  25. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  26. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  27. package/common/utils/getRealtimeModeSuffix.d.ts +9 -0
  28. package/common/utils/getUrlWithParams.d.ts +8 -0
  29. package/common/utils/getVehiclePosition.d.ts +16 -0
  30. package/common/utils/index.d.ts +16 -0
  31. package/common/utils/realtimeConfig.d.ts +64 -0
  32. package/common/utils/removeDuplicate.d.ts +9 -0
  33. package/common/utils/renderTrajectories.d.ts +16 -0
  34. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  35. package/common/utils/sortByDelay.d.ts +3 -0
  36. package/common/utils/timeUtils.d.ts +23 -0
  37. package/common/utils/toMercatorExtent.d.ts +5 -0
  38. package/iife.d.ts +2 -0
  39. package/index.d.ts +9 -0
  40. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  41. package/maplibre/controls/index.d.ts +1 -0
  42. package/maplibre/index.d.ts +5 -0
  43. package/maplibre/layers/Layer.d.ts +28 -0
  44. package/maplibre/layers/RealtimeLayer.d.ts +160 -0
  45. package/maplibre/layers/index.d.ts +2 -0
  46. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  47. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  48. package/maplibre/utils/index.d.ts +2 -0
  49. package/mbt.js +32 -24
  50. package/mbt.js.map +2 -2
  51. package/mbt.min.js +1 -1
  52. package/mbt.min.js.map +3 -3
  53. package/ol/controls/CopyrightControl.d.ts +31 -0
  54. package/ol/controls/RoutingControl.d.ts +209 -0
  55. package/ol/controls/StopFinderControl.d.ts +37 -0
  56. package/ol/controls/index.d.ts +3 -0
  57. package/ol/index.d.ts +6 -0
  58. package/ol/layers/MapGlLayer.d.ts +144 -0
  59. package/ol/layers/MapGlLayer.js +3 -1
  60. package/ol/layers/MaplibreLayer.d.ts +63 -0
  61. package/ol/layers/MaplibreStyleLayer.d.ts +235 -0
  62. package/ol/layers/MaplibreStyleLayer.js +1 -1
  63. package/ol/layers/RealtimeLayer.d.ts +285 -0
  64. package/ol/layers/RealtimeLayer.js +11 -5
  65. package/ol/layers/index.d.ts +3 -0
  66. package/ol/mixins/MobilityLayerMixin.d.ts +98 -0
  67. package/ol/mixins/MobilityLayerMixin.js +1 -4
  68. package/ol/mixins/PropertiesLayerMixin.d.ts +127 -0
  69. package/ol/mixins/PropertiesLayerMixin.js +5 -4
  70. package/ol/renderers/MaplibreLayerRenderer.d.ts +20 -0
  71. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  72. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  73. package/ol/renderers/RealtimeLayerRenderer.js +9 -9
  74. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  75. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  76. package/ol/styles/index.d.ts +3 -0
  77. package/ol/styles/routingStyle.d.ts +4 -0
  78. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  79. package/ol/utils/index.d.ts +1 -0
  80. package/package.json +1 -1
  81. package/setupTests.d.ts +1 -0
@@ -0,0 +1,31 @@
1
+ export type HttpAPIOptions = {
2
+ url: string;
3
+ apiKey?: string;
4
+ };
5
+ /**
6
+ * Common class to access to a geOps api using http.
7
+ *
8
+ * @example
9
+ * import { API } from 'mobility-toolbox-js/api';
10
+ *
11
+ * const api = new HttpApi({
12
+ * url: [yourUrl],
13
+ * apiKey: [yourApiKey]
14
+ * });
15
+ *
16
+ * @classproperty {string} url Url of the service.
17
+ * @classproperty {string} apiKey Api key to access the service.
18
+ * @private
19
+ */
20
+ declare class HttpAPI {
21
+ url: string;
22
+ apiKey?: string;
23
+ constructor(options: HttpAPIOptions);
24
+ /**
25
+ * Append the apiKey before sending the request.
26
+ *
27
+ * @private
28
+ */
29
+ fetch(path: string, params: Object, config: RequestInit): Promise<any>;
30
+ }
31
+ export default HttpAPI;
@@ -0,0 +1,359 @@
1
+ import WebSocketAPI, { WebSocketAPIMessageCallback, WebSocketAPIMessageEventData, WebSocketAPIParameters } from './WebSocketAPI';
2
+ import type { RealtimeMode, RealtimeDeparture, RealtimeNews, RealtimeStation, RealtimeExtraGeom, RealtimeTrainId, RealtimeGeneralizationLevel, RealtimeFullTrajectory, RealtimeTrajectoryResponse, RealtimeStationId, RealtimeVersion, RealtimeTrajectory, RealtimeTenant, RealtimeBbox } from '../types';
3
+ import { StopSequence } from './typedefs';
4
+ /**
5
+ * @typedef RealtimeAPIOptions
6
+ */
7
+ export type RealtimeAPIOptions = {
8
+ url?: string;
9
+ apiKey?: string;
10
+ version?: RealtimeVersion;
11
+ bbox?: RealtimeBbox;
12
+ buffer?: number[];
13
+ pingIntervalMs?: number;
14
+ reconnectTimeoutMs?: number;
15
+ };
16
+ export declare type RealtimeAPIExtraGeomsById = {
17
+ [index: string]: RealtimeExtraGeom;
18
+ };
19
+ export type RealtimeAPIDeparturesById = {
20
+ [index: string]: RealtimeDeparture;
21
+ };
22
+ export type RealtimeModesType = {
23
+ RAW: RealtimeMode;
24
+ TOPOGRAPHIC: RealtimeMode;
25
+ SCHEMATIC: RealtimeMode;
26
+ };
27
+ /**
28
+ * Enum for Realtime modes.
29
+ * @readonly
30
+ * @typedef {string} RealtimeMode
31
+ * @property {string} RAW "raw"
32
+ * @property {string} SCHEMATIC "schematic"
33
+ * @property {string} TOPOGRAPHIC "topographic"
34
+ * @enum {RealtimeMode}
35
+ */
36
+ export declare const RealtimeModes: {
37
+ RAW: RealtimeMode;
38
+ TOPOGRAPHIC: RealtimeMode;
39
+ SCHEMATIC: RealtimeMode;
40
+ };
41
+ /**
42
+ * This class provides convenience methods to use to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
43
+ *
44
+ * @example
45
+ * import { RealtimeAPI } from 'mobility-toolbox-js/api';
46
+ *
47
+ * const api = new RealtimeAPI({
48
+ * apiKey: "yourApiKey",
49
+ * bbox: [782001, 5888803, 923410, 5923660, 11, "mots=rail"],
50
+ * // url: "wss://api.geops.io/tracker-ws/v1/",
51
+ * });
52
+ *
53
+ * api.open();
54
+ *
55
+ * api.subscribeTrajectory('topographic', (data) => {
56
+ * console.log('Log trajectories:', JSON.stringify(data.content));
57
+ * });
58
+ *
59
+ * @public
60
+ */
61
+ declare class RealtimeAPI {
62
+ _url: string;
63
+ get url(): string;
64
+ set url(newUrl: string);
65
+ _bbox?: RealtimeBbox;
66
+ /**
67
+ * The bounding box to receive data from.\
68
+ * Example: [minX, minY, maxX, maxY, zoom, mots , gen_level, tenant, ...]\
69
+ * &nbsp;\
70
+ * Where:
71
+ * - **minX**: a string representation of an integer (not a float) representing the minimal X coordinate (in EPSG:3857) of a bounding box\
72
+ * &nbsp;
73
+ * - **minY**: a string representation of an integer (not a float) representing the minimal Y coordinate (in EPSG:3857) of a bounding box\
74
+ * &nbsp;
75
+ * - **maxX**: a string representation of an integer (not a float) representing the maximal X coordinate (in EPSG:3857) of a bounding box\
76
+ * &nbsp;
77
+ * - **maxY**: a string representation of an integer (not a float) representing the maximal Y coordinate (in EPSG:3857) of a bounding box\
78
+ * &nbsp;
79
+ * - **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.\
80
+ * &nbsp;
81
+ * - **mots**: A comma separated list of modes of transport. **Optional**.\
82
+ * Example: "mots=rail,subway".\
83
+ * &nbsp;
84
+ * - **gen_level**: An integer representing the generalization level. **Optional**.\
85
+ * Example: "gen_level=5"\
86
+ * &nbsp;
87
+ * - **tenant**: A string representing the tenant. **Optional**.\
88
+ * Example: "tenant=sbb"\
89
+ * &nbsp;
90
+ * - ...: Any other values added to the bbox will be send to the server
91
+ *
92
+ * @type {string[]}
93
+ *
94
+ * @public
95
+ */
96
+ get bbox(): RealtimeBbox | undefined;
97
+ set bbox(newBbox: RealtimeBbox | undefined);
98
+ _buffer?: number[];
99
+ get buffer(): number[] | undefined;
100
+ set buffer(newBuffer: number[] | undefined);
101
+ version: RealtimeVersion;
102
+ wsApi: WebSocketAPI;
103
+ private pingInterval;
104
+ private pingIntervalMs;
105
+ private reconnectTimeout?;
106
+ private reconnectTimeoutMs?;
107
+ /**
108
+ * Constructor
109
+ *
110
+ * @param {Object} options A string representing the url of the service or an object containing the url and the apiKey.
111
+ * @param {string} options.url Url to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
112
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
113
+ * @param {string[]} options.bbox The bounding box to receive data from.
114
+ * @public
115
+ */
116
+ constructor(options?: RealtimeAPIOptions);
117
+ /**
118
+ * Open the websocket connection.
119
+ *
120
+ * @public
121
+ */
122
+ open(): void;
123
+ /**
124
+ * Close the websocket connection without reconnection.
125
+ *
126
+ * @public
127
+ */
128
+ close(): void;
129
+ /**
130
+ * Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
131
+ */
132
+ reset(): void;
133
+ /**
134
+ * Callback when the websocket is opened and ready.
135
+ * It applies the bbox and the projection.
136
+ * @private
137
+ */
138
+ onOpen(): void;
139
+ /**
140
+ * Callback when the websocket is closed by the server.
141
+ * It auto reconnects after a timeout.
142
+ * @private
143
+ */
144
+ onClose(): void;
145
+ /**
146
+ * Send GET to a channel.
147
+ *
148
+ * @param {string | WebSocketAPIParameters} channelOrParams Name of the websocket channel to send GET or an object representing parameters to send
149
+ * @return {Promise<WebSocketAPIMessageEventData<?>>} A websocket response.
150
+ */
151
+ get(channelOrParams: string | WebSocketAPIParameters): Promise<WebSocketAPIMessageEventData<any>>;
152
+ /**
153
+ * Subscribe to a channel.
154
+ *
155
+ * @param {string} channel Name of the websocket channel to subscribe.
156
+ * @param {function} onSuccess Callback when the subscription succeeds.
157
+ * @param {function} onError Callback when the subscription fails.
158
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
159
+ * @private
160
+ */
161
+ subscribe(channel: string, onSuccess: WebSocketAPIMessageCallback<any>, onError?: EventListener, quiet?: boolean): void;
162
+ /**
163
+ * Unsubscribe both modes of a channel.
164
+ *
165
+ * @param {string} channel Name of the websocket channel to unsubscribe.
166
+ * @param {string} suffix Suffix to add to the channel name.
167
+ * @param {function} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
168
+ * @private
169
+ */
170
+ unsubscribe(channel: string, suffix?: string, onMessage?: WebSocketAPIMessageCallback<any>): void;
171
+ /**
172
+ * Subscribe to departures channel of a given station.
173
+ *
174
+ * @param {number} stationId UIC of the station.
175
+ * @param {Boolean} sortByMinArrivalTime Sort by minimum arrival time
176
+ * @param {function(departures:Departure[])} onMessage Function called on each message of the channel.
177
+ * @param {function} onError Callback when the subscription fails.
178
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
179
+ * @public
180
+ */
181
+ subscribeDepartures(stationId: number, onMessage: WebSocketAPIMessageCallback<RealtimeDeparture>, onError?: EventListener, quiet?: boolean): void;
182
+ /**
183
+ * Unsubscribe from current departures channel.
184
+ * @param {RealtimeStationId} id Station's id
185
+ * @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
186
+ * @public
187
+ */
188
+ unsubscribeDepartures(id: RealtimeStationId, onMessage?: WebSocketAPIMessageCallback<RealtimeDeparture>): void;
189
+ /**
190
+ * Subscribe to the disruptions channel for tenant.
191
+ *
192
+ * @param {function(data: { content: RealtimeNews[] })} onMessage Function called on each message of the channel.
193
+ * @param {function} onError Callback when the subscription fails.
194
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
195
+ * @public
196
+ */
197
+ subscribeDisruptions(tenant: RealtimeTenant, onMessage: WebSocketAPIMessageCallback<RealtimeNews>, onError?: EventListener, quiet?: boolean): void;
198
+ /**
199
+ * Unsubscribe disruptions.
200
+ *
201
+ * @param {function(data: { content: RealtimeNews[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
202
+ * @public
203
+ */
204
+ unsubscribeDisruptions(tenant: RealtimeTenant, onMessage?: WebSocketAPIMessageCallback<RealtimeNews>): void;
205
+ /**
206
+ * Return a station with a given uic number and a mode.
207
+ *
208
+ * @param {number} uic UIC of the station.
209
+ * @param {RealtimeMode} mode Realtime mode.
210
+ * @return {Promise<{data: { content: RealtimeStation }}>} A station.
211
+ * @public
212
+ */
213
+ getStation(uic: RealtimeStationId, mode: RealtimeMode): Promise<WebSocketAPIMessageEventData<RealtimeStation>>;
214
+ /**
215
+ * Get the list of ststions available for a specifc mode. The promise is resolved every 100ms
216
+ * @param {RealtimeMode} mode Realtime mode.
217
+ * @param {number} timeout = 100 Duration in ms between each promise resolve calls.
218
+ * @return {Promise<RealtimeStation[]>} An array of stations.
219
+ * @public
220
+ */
221
+ getStations(mode: RealtimeMode, timeout?: number): Promise<RealtimeStation[]>;
222
+ /**
223
+ * Subscribe to stations channel.
224
+ * One message pro station.
225
+ *
226
+ * @param {RealtimeMode} mode Realtime mode.
227
+ * @param {function(data: { content: RealtimeStation })} onMessage Function called on each message of the channel.
228
+ * @param {function} onError Callback when the subscription fails.
229
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
230
+ * @public
231
+ */
232
+ subscribeStations(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeStation>, onError?: EventListener, quiet?: boolean): void;
233
+ /**
234
+ * Unsubscribe to stations channel.
235
+ * @param {function(data: { content: RealtimeStation })} onMessage The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
236
+ * @public
237
+ */
238
+ unsubscribeStations(onMessage?: WebSocketAPIMessageCallback<RealtimeStation>): void;
239
+ /**
240
+ * Subscribe to extra_geoms channel.
241
+ *
242
+ * @param {function(data: { content: RealtimeExtraGeom })} onMessage Function called on each message of the channel.
243
+ * @param {function} onError Callback when the subscription fails.
244
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
245
+ */
246
+ subscribeExtraGeoms(onMessage: WebSocketAPIMessageCallback<RealtimeExtraGeom>, onError?: EventListener, quiet?: boolean): void;
247
+ /**
248
+ * Unsubscribe to extra_geoms channel.
249
+ * @param {function(data: { content: RealtimeExtraGeom })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
250
+ */
251
+ unsubscribeExtraGeoms(onMessage: WebSocketAPIMessageCallback<RealtimeExtraGeom>): void;
252
+ /**
253
+ * Return a partial trajectory with a given id and a mode.
254
+ *
255
+ * @param {number} trainId The identifier of a trajectory.
256
+ * @param {RealtimeMode} mode Realtime mode.
257
+ * @return {Promise<{data: { content: RealtimeTrajectory }}>} A trajectory.
258
+ * @public
259
+ */
260
+ getTrajectory(id: RealtimeTrainId, mode: RealtimeMode): Promise<WebSocketAPIMessageEventData<RealtimeTrajectory>>;
261
+ /**
262
+ * Subscribe to trajectory channel.
263
+ *
264
+ * @param {RealtimeMode} mode Realtime mode.
265
+ * @param {function(data: { content: RealtimeTrajectoryResponse[] })} onMessage Function called on each message of the channel.
266
+ * @param {function} onError Callback when the subscription fails.
267
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
268
+ * @public
269
+ */
270
+ subscribeTrajectory(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeTrajectoryResponse[] | RealtimeTrajectoryResponse>, onError?: EventListener, quiet?: boolean): void;
271
+ /**
272
+ * Unsubscribe to trajectory channels.
273
+ * @param {function(data: { content: RealtimeTrajectoryResponse[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
274
+ * @public
275
+ */
276
+ unsubscribeTrajectory(onMessage: WebSocketAPIMessageCallback<RealtimeTrajectoryResponse[]>): void;
277
+ /**
278
+ * Subscribe to deleted_vhicles channel.
279
+ *
280
+ * @param {RealtimeMode} mode Realtime mode.
281
+ * @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
282
+ * @param {function} onError Callback when the subscription fails.
283
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
284
+ */
285
+ subscribeDeletedVehicles(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeTrainId>, onError?: EventListener, quiet?: boolean): void;
286
+ /**
287
+ * Unsubscribe to deleted_vhicles channels.
288
+ * @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
289
+ */
290
+ unsubscribeDeletedVehicles(onMessage: WebSocketAPIMessageCallback<RealtimeTrainId>): void;
291
+ /**
292
+ * Get a full trajectory of a vehicule .
293
+ *
294
+ * @param {string} id A vehicle id.
295
+ * @param {RealtimeMode} mode Realtime mode.
296
+ * @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
297
+ * @return {Promise<{ data: { content: RealtimeFullTrajectory } }>} Return a full trajectory.
298
+ * @public
299
+ */
300
+ getFullTrajectory(id: RealtimeTrainId, mode: RealtimeMode, generalizationLevel: RealtimeGeneralizationLevel | undefined): Promise<WebSocketAPIMessageEventData<RealtimeFullTrajectory>>;
301
+ /**
302
+ * Subscribe to full_trajectory channel of a given vehicle.
303
+ *
304
+ * @param {string} id A vehicle id.
305
+ * @param {RealtimeMode} mode Realtime mode.
306
+ * @param {function(data: { content: RealtimeFullTrajectory })} onMessage Function called on each message of the channel.
307
+ * @param {function} onError Callback when the subscription fails.
308
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
309
+ * @public
310
+ */
311
+ subscribeFullTrajectory(id: RealtimeTrainId, mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeFullTrajectory>, onError?: EventListener, quiet?: boolean): void;
312
+ /**
313
+ * Unsubscribe from full_trajectory channel
314
+ *
315
+ * @param {string} id A vehicle id.
316
+ * @param {function(data: { content: RealtimeFullTrajectory })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
317
+ * @public
318
+ */
319
+ unsubscribeFullTrajectory(id: RealtimeTrainId, onMessage?: WebSocketAPIMessageCallback<RealtimeFullTrajectory>): void;
320
+ /**
321
+ * Get the list of stops for this vehicle.
322
+ *
323
+ * @param {string} id A vehicle id.
324
+ * @return {Promise<{ data: { content: StopSequence[] } }>} Returns a stop sequence object.
325
+ * @public
326
+ */
327
+ getStopSequence(id: RealtimeTrainId): Promise<WebSocketAPIMessageEventData<StopSequence[]>>;
328
+ /**
329
+ * Subscribe to stopsequence channel of a given vehicle.
330
+ *
331
+ * @param {string} id A vehicle id.
332
+ * @param {function(data: { content: StopSequence[] })} onMessage Function called on each message of the channel.
333
+ * @param {function} onError Callback when the subscription fails.
334
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
335
+ * @public
336
+ */
337
+ subscribeStopSequence(id: RealtimeTrainId, onMessage: WebSocketAPIMessageCallback<StopSequence[]>, onError?: EventListener, quiet?: boolean): void;
338
+ /**
339
+ * Unsubscribe from stopsequence channel
340
+ *
341
+ * @param {string} id A vehicle id.
342
+ * @param {function(data: { content: StopSequence[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
343
+ * @public
344
+ */
345
+ unsubscribeStopSequence(id: RealtimeTrainId, onMessage?: WebSocketAPIMessageCallback<StopSequence[]>): void;
346
+ /**
347
+ * Subscribe to healthcheck channel.
348
+ * @param {function(data: { content: string })} onMessage Callback when the subscribe to healthcheck channel succeeds.
349
+ * @param {function} onError Callback when the subscription fails.
350
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
351
+ */
352
+ subscribeHealthCheck(onMessage: WebSocketAPIMessageCallback<string>, onError?: EventListener, quiet?: boolean): void;
353
+ /**
354
+ * Unsubscribe to healthcheck channel.
355
+ * @param {function(data: { content: string })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
356
+ */
357
+ unsubscribeHealthCheck(onMessage?: WebSocketAPIMessageCallback<string>): void;
358
+ }
359
+ export default RealtimeAPI;
@@ -0,0 +1,37 @@
1
+ import HttpAPI from './HttpAPI';
2
+ import { RoutingParameters, RoutingResponse } from '../types';
3
+ export type RoutingAPIOptions = {
4
+ url?: string;
5
+ apiKey?: string;
6
+ };
7
+ /**
8
+ * Access to the [geOps Routing API](https://developer.geops.io/apis/routing).
9
+ *
10
+ * @example
11
+ * import { RoutingAPI } from 'mobility-toolbox-js';
12
+ *
13
+ * const api = new RoutingAPI({
14
+ * apiKey: [yourApiKey]
15
+ * });
16
+ *
17
+ * @public
18
+ */
19
+ declare class RoutingAPI extends HttpAPI {
20
+ /**
21
+ * Constructor
22
+ *
23
+ * @param {RoutingAPIOptions} options Options.
24
+ * @param {string} [options.url='https://api.geops.io/routing/v1/'] Service url.
25
+ * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/).
26
+ */
27
+ constructor(options?: RoutingAPIOptions);
28
+ /**
29
+ * Route.
30
+ *
31
+ * @param {RoutingParameters} params Request parameters. See [Routing service documentation](https://developer.geops.io/apis/routing/).
32
+ * @param {RequestInit} config Options for the fetch request.
33
+ * @return {Promise<RoutingResponse>} An GeoJSON feature collection with coordinates in [EPSG:4326](http://epsg.io/4326).
34
+ */
35
+ route(params: RoutingParameters, config: RequestInit): Promise<RoutingResponse>;
36
+ }
37
+ export default RoutingAPI;
@@ -0,0 +1,38 @@
1
+ import HttpAPI from './HttpAPI';
2
+ import { StopsParameters, StopsResponse } from '../types';
3
+ export type StopsAPIOptions = {
4
+ url?: string;
5
+ apiKey?: string;
6
+ };
7
+ /**
8
+ * Access to the [geOps Stops api](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
9
+ *
10
+ * @example
11
+ * import { StopsAPI } from 'mobility-toolbox-js/api';
12
+ *
13
+ * const api = new StopsAPI({
14
+ * url: 'https://api.geops.io/stops/v1/',
15
+ * apiKey: [yourApiKey]
16
+ * });
17
+ *
18
+ * @public
19
+ */
20
+ declare class StopsAPI extends HttpAPI {
21
+ /**
22
+ * Constructor
23
+ *
24
+ * @param {StopsAPIOptions} options Options.
25
+ * @param {string} [options.url='https://api.geops.io/stops/v1/'] Service url.
26
+ * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/).
27
+ */
28
+ constructor(options?: StopsAPIOptions);
29
+ /**
30
+ * Search fo stops.
31
+ *
32
+ * @param {StopsParameters} params Request parameters. See [Stops service documentation](https://developer.geops.io/apis/stops).
33
+ * @param {RequestInit} config Options for the fetch request.
34
+ * @return {Promise<StopsResponse>} An GeoJSON feature collection with coordinates in [EPSG:4326](http://epsg.io/4326).
35
+ */
36
+ search(params: StopsParameters, config: RequestInit): Promise<StopsResponse>;
37
+ }
38
+ export default StopsAPI;
@@ -0,0 +1,153 @@
1
+ import { RealtimeTrajectoryResponse } from '../types';
2
+ export declare type WebSocketAPIParameters = {
3
+ channel?: string;
4
+ args?: string | number;
5
+ id?: string | number;
6
+ };
7
+ export declare type WebSocketAPIMessageEventData<T> = {
8
+ timestamp: number;
9
+ source: string;
10
+ content: T;
11
+ client_reference: string | number | null;
12
+ };
13
+ export type WebSocketAPIBufferMessageEventData = WebSocketAPIMessageEventData<RealtimeTrajectoryResponse[]> & {
14
+ source: 'buffer';
15
+ };
16
+ export type WebSocketAPIMessageEvent = Event & {
17
+ data: string;
18
+ };
19
+ export interface WebSocketAPIMessageEventListener {
20
+ (evt: WebSocketAPIMessageEvent): void;
21
+ }
22
+ /**
23
+ * This type represents a function that has been call with each feature returned by the websocket.
24
+ */
25
+ export interface WebSocketAPIMessageCallback<T> {
26
+ (data: WebSocketAPIMessageEventData<T>): void;
27
+ }
28
+ export declare type WebSocketAPISubscription = {
29
+ params: WebSocketAPIParameters;
30
+ cb: WebSocketAPIMessageCallback<any>;
31
+ errorCb?: EventListener;
32
+ onMessageCb: WebSocketAPIMessageEventListener;
33
+ onErrorCb?: EventListener;
34
+ quiet: boolean;
35
+ };
36
+ export declare type WebSocketAPISubscribed = {
37
+ [index: string]: boolean;
38
+ };
39
+ export declare type WebSocketAPIRequest = {
40
+ params: WebSocketAPIParameters;
41
+ cb: WebSocketAPIMessageCallback<any>;
42
+ errorCb?: EventListener;
43
+ onMessageCb: WebSocketAPIMessageEventListener;
44
+ onErrorCb?: EventListener;
45
+ requestString: String;
46
+ };
47
+ /**
48
+ * Class used to facilitate connection to a WebSocketAPI and
49
+ * also to manage properly messages send to the WebSocketAPI.
50
+ * This class must not contain any specific implementation.
51
+ * @private
52
+ */
53
+ declare class WebSocketAPI {
54
+ websocket?: WebSocket;
55
+ closed?: boolean;
56
+ closing?: boolean;
57
+ connecting?: boolean;
58
+ open?: boolean;
59
+ messagesOnOpen: Array<string>;
60
+ subscriptions: Array<WebSocketAPISubscription>;
61
+ subscribed: WebSocketAPISubscribed;
62
+ requests: Array<WebSocketAPIRequest>;
63
+ constructor();
64
+ defineProperties(): void;
65
+ /**
66
+ * Get the websocket request string.
67
+ *
68
+ * @param {string} method Request mehtod {GET, SUB}.
69
+ * @param {WebSocketParameters} params Request parameters.
70
+ * @param {string} params.channel Channel name
71
+ * @param {string} [params.args] Request arguments
72
+ * @param {Number|string} [params.id] Request identifier
73
+ * @return {string} request string
74
+ * @private
75
+ */
76
+ static getRequestString(method: string, params?: WebSocketAPIParameters): string;
77
+ /**
78
+ * (Re)connect the websocket.
79
+ *
80
+ * @param {string} url Websocket url.
81
+ * @param {function} onOpen Callback called when the websocket connection is opened and before subscriptions of previous subscriptions.
82
+ * @private
83
+ */
84
+ connect(url: string, onOpen?: () => void): void;
85
+ /**
86
+ * Close the websocket definitively.
87
+ *
88
+ * @private
89
+ */
90
+ close(): void;
91
+ /**
92
+ * Sends a message to the websocket.
93
+ *
94
+ * @param {message} message Message to send.
95
+ * @private
96
+ */
97
+ send(message: string): void;
98
+ addEvents(onMessage: WebSocketAPIMessageEventListener, onError?: EventListener): void;
99
+ removeEvents(onMessage: WebSocketAPIMessageEventListener, onError?: EventListener): void;
100
+ /**
101
+ * Listen to websocket messages.
102
+ *
103
+ * @param {WebSocketParameters} params Parameters for the websocket get request
104
+ * @param {function} cb callback on listen
105
+ * @param {function} errorCb Callback on error
106
+ * @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
107
+ * @private
108
+ */
109
+ listen(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener): {
110
+ onMessageCb: WebSocketAPIMessageEventListener;
111
+ onErrorCb?: EventListener;
112
+ };
113
+ /**
114
+ * Unlisten websocket messages.
115
+ *
116
+ * @param {Object} params Parameters for the websocket get request.
117
+ * @param {function} cb Callback used when listen.
118
+ * @private
119
+ */
120
+ unlisten(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>): void;
121
+ /**
122
+ * Sends a get request to the websocket.
123
+ * The callback is called only once, when the response is received or when the call returns an error.
124
+ *
125
+ * @param {Object} params Parameters for the websocket get request
126
+ * @param {function} onMessage callback on message event
127
+ * @param {function} onError Callback on error and close event
128
+ * @private
129
+ */
130
+ get(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener): void;
131
+ /**
132
+ * Subscribe to a given channel.
133
+ *
134
+ * @param {Object} params Parameters for the websocket get request
135
+ * @param {function} cb callback on listen
136
+ * @param {function} errorCb Callback on error
137
+ * @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
138
+ * @private
139
+ */
140
+ subscribe(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener, quiet?: boolean): void;
141
+ /**
142
+ * Unsubscribe from a channel.
143
+ * @param {string} source source to unsubscribe from
144
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
145
+ * @private
146
+ */
147
+ unsubscribe(source: string, cb?: WebSocketAPIMessageCallback<any>): void;
148
+ /**
149
+ * After an auto reconnection we need to re-subscribe to the channels.
150
+ */
151
+ subscribePreviousSubscriptions(): void;
152
+ }
153
+ export default WebSocketAPI;
package/api/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as RoutingAPI } from "./RoutingAPI";
2
+ export { default as StopsAPI } from "./StopsAPI";
3
+ export { default as RealtimeAPI, RealtimeModes } from "./RealtimeAPI";