mobility-toolbox-js 2.0.0-beta.30 → 2.0.0-beta.34

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 (225) hide show
  1. package/api/RealtimeAPI.d.ts +268 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +626 -343
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +65 -15
  7. package/api/StopsAPI.d.ts +36 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +70 -12
  10. package/api/index.d.ts +5 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +10 -3
  13. package/api/typedefs.d.ts +105 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +72 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +82 -30
  19. package/common/api/WebSocketAPI.d.ts +95 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +313 -168
  22. package/common/controls/Control.d.ts +74 -0
  23. package/common/controls/Control.d.ts.map +1 -0
  24. package/common/controls/Control.js +167 -78
  25. package/common/index.d.ts +3 -0
  26. package/common/index.d.ts.map +1 -0
  27. package/common/index.js +18 -2
  28. package/common/layers/Layer.d.ts +80 -0
  29. package/common/layers/Layer.d.ts.map +1 -0
  30. package/common/layers/Layer.js +251 -134
  31. package/common/mixins/CopyrightMixin.d.ts +22 -0
  32. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  33. package/common/mixins/CopyrightMixin.js +70 -22
  34. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  35. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  36. package/common/mixins/MapboxLayerMixin.js +240 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +698 -429
  40. package/common/mixins/StopFinderMixin.d.ts +40 -0
  41. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  42. package/common/mixins/StopFinderMixin.js +195 -107
  43. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  44. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  45. package/common/mixins/UserInteractionsLayerMixin.js +222 -121
  46. package/common/styles/index.d.ts +5 -0
  47. package/common/styles/index.d.ts.map +1 -0
  48. package/common/styles/index.js +24 -4
  49. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  50. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDefaultStyle.js +236 -190
  52. package/common/styles/realtimeDelayStyle.d.ts +11 -0
  53. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeDelayStyle.js +25 -7
  55. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -17
  58. package/common/typedefs.d.ts +50 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +21 -0
  61. package/common/utils/cleanStopTime.d.ts +7 -0
  62. package/common/utils/cleanStopTime.d.ts.map +1 -0
  63. package/common/utils/cleanStopTime.js +28 -17
  64. package/common/utils/compareDepartures.d.ts +9 -0
  65. package/common/utils/compareDepartures.d.ts.map +1 -0
  66. package/common/utils/compareDepartures.js +34 -22
  67. package/common/utils/createCanvas.d.ts +9 -0
  68. package/common/utils/createCanvas.d.ts.map +1 -0
  69. package/common/utils/createCanvas.js +28 -16
  70. package/common/utils/createTrackerFilters.d.ts +12 -0
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  72. package/common/utils/createTrackerFilters.js +75 -54
  73. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  74. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  75. package/common/utils/getLayersAsFlatArray.js +15 -13
  76. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  77. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  78. package/common/utils/getMapboxMapCopyrights.js +24 -17
  79. package/common/utils/getMapboxRender.d.ts +5 -0
  80. package/common/utils/getMapboxRender.d.ts.map +1 -0
  81. package/common/utils/getMapboxRender.js +77 -0
  82. package/common/utils/getMaplibreRender.d.ts +5 -0
  83. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  84. package/common/utils/getMaplibreRender.js +38 -0
  85. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  86. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  87. package/common/utils/getRealtimeModeSuffix.js +11 -2
  88. package/common/utils/getUrlWithParams.d.ts +9 -0
  89. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  90. package/common/utils/getUrlWithParams.js +20 -10
  91. package/common/utils/getVehiclePosition.d.ts +14 -0
  92. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  93. package/common/utils/getVehiclePosition.js +63 -39
  94. package/common/utils/index.d.ts +12 -0
  95. package/common/utils/index.d.ts.map +1 -0
  96. package/common/utils/index.js +37 -9
  97. package/common/utils/removeDuplicate.d.ts +10 -0
  98. package/common/utils/removeDuplicate.d.ts.map +1 -0
  99. package/common/utils/removeDuplicate.js +29 -7
  100. package/common/utils/renderTrajectories.d.ts +20 -0
  101. package/common/utils/renderTrajectories.d.ts.map +1 -0
  102. package/common/utils/renderTrajectories.js +111 -78
  103. package/common/utils/sortByDelay.d.ts +3 -0
  104. package/common/utils/sortByDelay.d.ts.map +1 -0
  105. package/common/utils/sortByDelay.js +21 -17
  106. package/common/utils/timeUtils.d.ts +5 -0
  107. package/common/utils/timeUtils.d.ts.map +1 -0
  108. package/common/utils/timeUtils.js +47 -18
  109. package/common/utils/trackerConfig.d.ts +24 -0
  110. package/common/utils/trackerConfig.d.ts.map +1 -0
  111. package/common/utils/trackerConfig.js +171 -118
  112. package/iife.d.ts +3 -0
  113. package/iife.d.ts.map +1 -0
  114. package/iife.js +7 -0
  115. package/index.d.ts +6 -0
  116. package/index.d.ts.map +1 -0
  117. package/index.js +10 -7
  118. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  119. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  120. package/mapbox/controls/CopyrightControl.js +72 -28
  121. package/mapbox/controls/index.d.ts +2 -0
  122. package/mapbox/controls/index.d.ts.map +1 -0
  123. package/mapbox/controls/index.js +6 -1
  124. package/mapbox/index.d.ts +5 -0
  125. package/mapbox/index.d.ts.map +1 -0
  126. package/mapbox/index.js +20 -4
  127. package/mapbox/layers/Layer.d.ts +47 -0
  128. package/mapbox/layers/Layer.d.ts.map +1 -0
  129. package/mapbox/layers/Layer.js +137 -54
  130. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  131. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  132. package/mapbox/layers/RealtimeLayer.js +310 -183
  133. package/mapbox/layers/index.d.ts +3 -0
  134. package/mapbox/layers/index.d.ts.map +1 -0
  135. package/mapbox/layers/index.js +7 -2
  136. package/mapbox/utils.d.ts +8 -0
  137. package/mapbox/utils.d.ts.map +1 -0
  138. package/mapbox/utils.js +54 -29
  139. package/mbt.js +2052 -2109
  140. package/mbt.js.map +3 -3
  141. package/mbt.min.js +18 -18
  142. package/mbt.min.js.map +3 -3
  143. package/ol/controls/CopyrightControl.d.ts +31 -0
  144. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  145. package/ol/controls/CopyrightControl.js +89 -41
  146. package/ol/controls/RoutingControl.d.ts +180 -0
  147. package/ol/controls/RoutingControl.d.ts.map +1 -0
  148. package/ol/controls/RoutingControl.js +666 -371
  149. package/ol/controls/StopFinderControl.d.ts +32 -0
  150. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  151. package/ol/controls/StopFinderControl.js +59 -10
  152. package/ol/controls/index.d.ts +4 -0
  153. package/ol/controls/index.d.ts.map +1 -0
  154. package/ol/controls/index.js +9 -3
  155. package/ol/index.d.ts +6 -0
  156. package/ol/index.d.ts.map +1 -0
  157. package/ol/index.js +21 -5
  158. package/ol/layers/Layer.d.ts +49 -0
  159. package/ol/layers/Layer.d.ts.map +1 -0
  160. package/ol/layers/Layer.js +178 -81
  161. package/ol/layers/MapboxLayer.d.ts +42 -0
  162. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  163. package/ol/layers/MapboxLayer.js +131 -198
  164. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  165. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  166. package/ol/layers/MapboxStyleLayer.js +382 -186
  167. package/ol/layers/MaplibreLayer.d.ts +27 -0
  168. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  169. package/ol/layers/MaplibreLayer.js +67 -138
  170. package/ol/layers/RealtimeLayer.d.ts +119 -0
  171. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  172. package/ol/layers/RealtimeLayer.js +327 -184
  173. package/ol/layers/RoutingLayer.d.ts +24 -0
  174. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  175. package/ol/layers/RoutingLayer.js +111 -56
  176. package/ol/layers/VectorLayer.d.ts +23 -0
  177. package/ol/layers/VectorLayer.d.ts.map +1 -0
  178. package/ol/layers/VectorLayer.js +71 -21
  179. package/ol/layers/WMSLayer.d.ts +38 -0
  180. package/ol/layers/WMSLayer.d.ts.map +1 -0
  181. package/ol/layers/WMSLayer.js +105 -37
  182. package/ol/layers/index.d.ts +9 -0
  183. package/ol/layers/index.d.ts.map +1 -0
  184. package/ol/layers/index.js +19 -8
  185. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  186. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  187. package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
  188. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  189. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  190. package/ol/styles/fullTrajectoryStyle.js +44 -40
  191. package/ol/styles/index.d.ts +3 -0
  192. package/ol/styles/index.d.ts.map +1 -0
  193. package/ol/styles/index.js +7 -2
  194. package/package.json +14 -36
  195. package/setupTests.d.ts +2 -0
  196. package/setupTests.d.ts.map +1 -0
  197. package/setupTests.js +15 -0
  198. package/types/index.d.ts +7 -6
  199. package/types/routing.d.ts +25 -25
  200. package/types/stops.d.ts +19 -19
  201. package/api/RealtimeAPI.test.js +0 -67
  202. package/api/RoutingAPI.test.js +0 -25
  203. package/api/StopsAPI.test.js +0 -22
  204. package/common/api/HttpAPI.test.js +0 -50
  205. package/common/api/WebSocketAPI.test.js +0 -311
  206. package/common/controls/Control.test.js +0 -87
  207. package/common/layers/Layer.test.js +0 -134
  208. package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
  209. package/common/utils/createTrackerFilters.test.js +0 -79
  210. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  211. package/common/utils/removeDuplicate.test.js +0 -19
  212. package/common/utils/timeUtils.test.js +0 -10
  213. package/common/utils/trackerConfig.test.js +0 -23
  214. package/mapbox/layers/Layer.test.js +0 -182
  215. package/mapbox/layers/RealtimeLayer.test.js +0 -10
  216. package/ol/controls/CopyrightControl.test.js +0 -165
  217. package/ol/controls/RoutingControl.test.js +0 -146
  218. package/ol/controls/StopFinderControl.test.js +0 -48
  219. package/ol/layers/Layer.test.js +0 -175
  220. package/ol/layers/MapboxLayer.test.js +0 -160
  221. package/ol/layers/MapboxStyleLayer.test.js +0 -226
  222. package/ol/layers/RealtimeLayer.test.js +0 -67
  223. package/ol/layers/RoutingLayer.test.js +0 -39
  224. package/ol/layers/VectorLayer.test.js +0 -76
  225. package/ol/layers/WMSLayer.test.js +0 -57
@@ -1,357 +1,640 @@
1
- import WebSocketAPI from "../common/api/WebSocketAPI";
2
- import cleanStopTime from "../common/utils/cleanStopTime";
3
- import getModeSuffix from "../common/utils/getRealtimeModeSuffix";
4
- import compareDepartures from "../common/utils/compareDepartures";
5
- export const RealtimeModes = {
6
- RAW: "raw",
7
- TOPOGRAPHIC: "topographic",
8
- SCHEMATIC: "schematic"
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RealtimeModes = void 0;
4
+ var WebSocketAPI_1 = require("../common/api/WebSocketAPI");
5
+ var cleanStopTime_1 = require("../common/utils/cleanStopTime");
6
+ var getRealtimeModeSuffix_1 = require("../common/utils/getRealtimeModeSuffix");
7
+ var compareDepartures_1 = require("../common/utils/compareDepartures");
8
+ /**
9
+ * Enum for Realtime modes.
10
+ * @readonly
11
+ * @typedef {string} RealtimeMode
12
+ * @property {string} RAW "raw"
13
+ * @property {string} SCHEMATIC "schematic"
14
+ * @property {string} TOPOGRAPHIC "topographic"
15
+ * @enum {RealtimeMode}
16
+ */
17
+ exports.RealtimeModes = {
18
+ RAW: 'raw',
19
+ TOPOGRAPHIC: 'topographic',
20
+ SCHEMATIC: 'schematic',
9
21
  };
10
- class RealtimeAPI {
11
- constructor(options = {}) {
12
- this.defineProperties(options);
13
- this.subscribedStationUic = null;
14
- this.departureUpdateTimeout = null;
15
- this.maxDepartureAge = 30;
16
- this.extraGeoms = {};
17
- this.prefix = options.prefix || "";
18
- this.onOpen = this.onOpen.bind(this);
19
- }
20
- defineProperties(options) {
21
- let opt = options;
22
- if (typeof options === "string") {
23
- opt = { url: options };
22
+ /**
23
+ * This class provides convenience methods to access to the [geOps realtime api](https://developer.geops.io/apis/realtime/).
24
+ *
25
+ * @example
26
+ * import { RealtimeAPI } from 'mobility-toolbox-js/api';
27
+ *
28
+ * const api = new RealtimeAPI({
29
+ * url: "yourUrl",
30
+ * apiKey: "yourApiKey"
31
+ * });
32
+ *
33
+ * @example
34
+ * import { RealtimeAPI } from 'mobility-toolbox-js/api';
35
+ *
36
+ * const api = new RealtimeAPI("yourUrl");
37
+ */
38
+ var RealtimeAPI = /** @class */ (function () {
39
+ /**
40
+ * Constructor
41
+ *
42
+ * @param {Object|string} options A string representing the url of the service or an object containing the url and the apiKey.
43
+ * @param {string} options.url Url to the [geOps realtime api](https://developer.geops.io/apis/realtime/).
44
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
45
+ * @param {string} [options.prefix=''] Service prefix to specify tenant.
46
+ * @param {string} [options.projection] The epsg code of the projection for features. Default to EPSG:3857.
47
+ * @param {number[4]} [options.bbox=[minX, minY, maxX, maxY, zoom, tenant] The bounding box to receive data from.
48
+ */
49
+ function RealtimeAPI(options) {
50
+ if (options === void 0) { options = {}; }
51
+ this.defineProperties(options);
52
+ /** @ignore */
53
+ this.subscribedStationUic = null;
54
+ /** @ignore */
55
+ this.departureUpdateTimeout = null;
56
+ /** @ignore */
57
+ this.maxDepartureAge = 30;
58
+ /** @ignore */
59
+ this.extraGeoms = {};
60
+ /** @ignore */
61
+ this.prefix = options.prefix || '';
62
+ /** @ignore */
63
+ this.onOpen = this.onOpen.bind(this);
24
64
  }
25
- const { apiKey } = opt;
26
- let { url, projection, bbox, buffer = [100, 100] } = opt;
27
- const wsApi = new WebSocketAPI();
28
- if (apiKey) {
29
- url = `${url || "wss://api.geops.io/tracker-ws/v1/"}?key=${apiKey}`;
30
- }
31
- Object.defineProperties(this, {
32
- url: {
33
- get: () => url,
34
- set: (newUrl) => {
35
- url = newUrl;
36
- this.open();
37
- }
38
- },
39
- projection: {
40
- get: () => projection,
41
- set: (newProjection) => {
42
- if (newProjection !== projection) {
43
- projection = newProjection;
44
- if (this.wsApi) {
45
- this.wsApi.send(`PROJECTION ${projection}`);
46
- }
47
- }
65
+ RealtimeAPI.prototype.defineProperties = function (options) {
66
+ var _this = this;
67
+ var opt = options;
68
+ if (typeof options === 'string') {
69
+ opt = { url: options };
48
70
  }
49
- },
50
- bbox: {
51
- get: () => bbox,
52
- set: (newBbox) => {
53
- if (JSON.stringify(newBbox) !== JSON.stringify(bbox)) {
54
- bbox = newBbox;
55
- if (this.wsApi) {
56
- this.wsApi.send(`BBOX ${bbox.join(" ")}`);
57
- }
58
- }
71
+ var apiKey = opt.apiKey;
72
+ var url = opt.url, projection = opt.projection, bbox = opt.bbox, _a = opt.buffer, buffer = _a === void 0 ? [100, 100] : _a;
73
+ var wsApi = new WebSocketAPI_1.default();
74
+ if (apiKey) {
75
+ url = "".concat(url || 'wss://api.geops.io/tracker-ws/v1/', "?key=").concat(apiKey);
59
76
  }
60
- },
61
- buffer: {
62
- get: () => buffer,
63
- set: (newBuffer) => {
64
- if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
65
- buffer = newBuffer;
66
- if (this.wsApi) {
67
- this.wsApi.send(`BUFFER ${buffer.join(" ")}`);
68
- }
69
- }
77
+ Object.defineProperties(this, {
78
+ url: {
79
+ get: function () { return url; },
80
+ set: function (newUrl) {
81
+ url = newUrl;
82
+ _this.open();
83
+ },
84
+ },
85
+ projection: {
86
+ get: function () { return projection; },
87
+ set: function (newProjection) {
88
+ if (newProjection !== projection) {
89
+ projection = newProjection;
90
+ if (_this.wsApi) {
91
+ _this.wsApi.send("PROJECTION ".concat(projection));
92
+ }
93
+ }
94
+ },
95
+ },
96
+ bbox: {
97
+ get: function () { return bbox; },
98
+ set: function (newBbox) {
99
+ if (JSON.stringify(newBbox) !== JSON.stringify(bbox)) {
100
+ bbox = newBbox;
101
+ if (_this.wsApi) {
102
+ _this.wsApi.send("BBOX ".concat(bbox.join(' ')));
103
+ }
104
+ }
105
+ },
106
+ },
107
+ buffer: {
108
+ get: function () { return buffer; },
109
+ set: function (newBuffer) {
110
+ if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
111
+ buffer = newBuffer;
112
+ if (_this.wsApi) {
113
+ _this.wsApi.send("BUFFER ".concat(buffer.join(' ')));
114
+ }
115
+ }
116
+ },
117
+ },
118
+ /**
119
+ * The websocket helper class to connect the websocket.
120
+ *
121
+ * @private
122
+ */
123
+ wsApi: {
124
+ value: wsApi,
125
+ writable: true,
126
+ },
127
+ /**
128
+ * Interval between PING request in ms.
129
+ * If equal to 0, no PING request are sent.
130
+ * @type {number}
131
+ * @private
132
+ */
133
+ pingIntervalMs: {
134
+ value: options.pingIntervalMs || 10000,
135
+ writable: true,
136
+ },
137
+ /**
138
+ * Timeout in ms after an automatic reconnection when the websoscket has been closed by the server.
139
+ * @type {number}
140
+ */
141
+ reconnectTimeoutMs: {
142
+ value: options.pingIntervalMs || 100,
143
+ writable: true,
144
+ },
145
+ });
146
+ };
147
+ RealtimeAPI.prototype.open = function () {
148
+ var _this = this;
149
+ this.close();
150
+ // Register BBOX and PROJECTION messages must be send before previous subscriptions.
151
+ this.wsApi.connect(this.url, this.onOpen);
152
+ // Register reconnection on close.
153
+ this.wsApi.websocket.onclose = function () {
154
+ _this.onClose();
155
+ };
156
+ };
157
+ /**
158
+ * Close the websocket connection without reconnection.
159
+ */
160
+ RealtimeAPI.prototype.close = function () {
161
+ this.wsApi.close();
162
+ };
163
+ /**
164
+ * Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
165
+ */
166
+ // eslint-disable-next-line class-methods-use-this
167
+ RealtimeAPI.prototype.reset = function () {
168
+ this.wsApi.send('RESET');
169
+ };
170
+ /**
171
+ * Callback when the websocket is opened and ready.
172
+ * It applies the bbox and the projection.
173
+ */
174
+ RealtimeAPI.prototype.onOpen = function () {
175
+ var _this = this;
176
+ if (this.projection) {
177
+ this.wsApi.send("PROJECTION ".concat(this.projection));
70
178
  }
71
- },
72
- wsApi: {
73
- value: wsApi,
74
- writable: true
75
- },
76
- pingIntervalMs: {
77
- value: options.pingIntervalMs || 1e4,
78
- writable: true
79
- },
80
- reconnectTimeoutMs: {
81
- value: options.pingIntervalMs || 100,
82
- writable: true
83
- }
84
- });
85
- }
86
- open() {
87
- this.close();
88
- this.wsApi.connect(this.url, this.onOpen);
89
- this.wsApi.websocket.onclose = () => {
90
- this.onClose();
91
- };
92
- }
93
- close() {
94
- this.wsApi.close();
95
- }
96
- reset() {
97
- this.wsApi.send("RESET");
98
- }
99
- onOpen() {
100
- if (this.projection) {
101
- this.wsApi.send(`PROJECTION ${this.projection}`);
102
- }
103
- if (this.bbox) {
104
- this.wsApi.send(`BBOX ${this.bbox.join(" ")}`);
105
- }
106
- if (this.buffer) {
107
- this.wsApi.send(`BUFFER ${this.buffer.join(" ")}`);
108
- }
109
- if (this.pingIntervalMs) {
110
- window.clearInterval(this.pingInterval);
111
- this.pingInterval = setInterval(() => {
112
- this.wsApi.send("PING");
113
- }, this.pingIntervalMs);
114
- }
115
- }
116
- onClose() {
117
- window.clearTimeout(this.pingInterval);
118
- window.clearTimeout(this.reconnectTimeout);
119
- if (this.reconnectTimeoutMs) {
120
- this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
121
- }
122
- }
123
- subscribe(channel, onSuccess, onError, quiet = false) {
124
- this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
125
- }
126
- unsubscribe(channel, suffix, cb) {
127
- this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.SCHEMATIC, RealtimeModes)}${suffix}`, cb);
128
- this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.TOPOGRAPHIC, RealtimeModes)}${suffix || ""}`, cb);
129
- }
130
- filterDepartures(depObject, sortByMinArrivalTime = false) {
131
- const departures = Object.keys(depObject).map((k) => depObject[k]);
132
- departures.sort((a, b) => compareDepartures(a, b, sortByMinArrivalTime));
133
- let future = new Date();
134
- future.setMinutes(future.getMinutes() + this.maxDepartureAge);
135
- future = future.getTime();
136
- let past = new Date();
137
- past.setMinutes(past.getMinutes() - this.maxDepartureAge);
138
- past = past.getTime();
139
- const departureArray = [];
140
- const platformsBoarding = [];
141
- let previousDeparture = null;
142
- for (let i = departures.length - 1; i >= 0; i -= 1) {
143
- const d = departures[i];
144
- const t = new Date(d.time).getTime();
145
- if (t > past && t < future) {
146
- if (d.state === "BOARDING") {
147
- if (platformsBoarding.indexOf(d.platform) === -1) {
148
- platformsBoarding.push(d.platform);
149
- } else {
150
- d.state = "HIDDEN";
151
- }
179
+ if (this.bbox) {
180
+ this.wsApi.send("BBOX ".concat(this.bbox.join(' ')));
152
181
  }
153
- if (previousDeparture && d.to[0] === previousDeparture.to[0] && Math.abs(t - previousDeparture.time) < 1e3 && d.line.name === previousDeparture.line.name) {
154
- d.state = "HIDDEN";
182
+ if (this.buffer) {
183
+ this.wsApi.send("BUFFER ".concat(this.buffer.join(' ')));
155
184
  }
156
- if (/(STOP_CANCELLED|JOURNEY_CANCELLED)/.test(d.state)) {
157
- d.cancelled = true;
185
+ /**
186
+ * Keep websocket alive
187
+ */
188
+ if (this.pingIntervalMs) {
189
+ window.clearInterval(this.pingInterval);
190
+ /** @ignore */
191
+ this.pingInterval = setInterval(function () {
192
+ _this.wsApi.send('PING');
193
+ }, this.pingIntervalMs);
158
194
  }
159
- previousDeparture = d;
160
- previousDeparture.time = t;
161
- departureArray.unshift(d);
162
- }
163
- }
164
- return departureArray;
165
- }
166
- subscribeDepartures(stationId, sortByMinArrivalTime, onMessage) {
167
- window.clearTimeout(this.departureUpdateTimeout);
168
- this.unsubscribeDepartures();
169
- this.subscribedStationUic = stationId;
170
- const channel = stationId ? `timetable_${stationId}` : null;
171
- const departureObject = {};
172
- this.subscribe(channel, (data) => {
173
- if (data.source === channel) {
174
- const content = data.content || {};
175
- const tDiff = new Date(content.timestamp).getTime() - Date.now();
176
- content.timediff = tDiff;
177
- departureObject[content.call_id] = content;
178
- window.clearTimeout(this.departureUpdateTimeout);
179
- this.departureUpdateTimeout = window.setTimeout(() => {
180
- const departures = this.filterDepartures(departureObject, sortByMinArrivalTime || false);
181
- onMessage(departures);
182
- }, 100);
183
- }
184
- }, () => {
185
- onMessage([]);
186
- });
187
- }
188
- unsubscribeDepartures(cb) {
189
- if (this.subscribedStationUic) {
190
- this.unsubscribe(`timetable_${this.subscribedStationUic}`, "", cb);
191
- this.subscribedStationUic = null;
192
- }
193
- }
194
- subscribeDisruptions(onMessage) {
195
- this.subscribe(`${this.prefix}newsticker`, (data) => {
196
- onMessage(data.content);
197
- });
198
- }
199
- unsubscribeDisruptions(cb) {
200
- this.unsubscribe(`${this.prefix}newsticker`, "", cb);
201
- }
202
- getStation(uic, mode) {
203
- const params = {
204
- channel: `station${getModeSuffix(mode, RealtimeModes)}`,
205
- args: uic
206
- };
207
- return new Promise((resolve, reject) => {
208
- this.wsApi.get(params, (data) => {
209
- if (data.content) {
210
- resolve(data.content);
211
- } else {
212
- reject();
195
+ };
196
+ /**
197
+ * Callback when the websocket is closed by the server.
198
+ * It auto reconnects after a timeout.
199
+ */
200
+ RealtimeAPI.prototype.onClose = function () {
201
+ var _this = this;
202
+ window.clearTimeout(this.pingInterval);
203
+ window.clearTimeout(this.reconnectTimeout);
204
+ if (this.reconnectTimeoutMs) {
205
+ /** @ignore */
206
+ this.reconnectTimeout = window.setTimeout(function () { return _this.open(); }, this.reconnectTimeoutMs);
213
207
  }
214
- });
215
- });
216
- }
217
- getStations(mode) {
218
- const stations = [];
219
- const params = {
220
- channel: `station${getModeSuffix(mode, RealtimeModes)}`
221
- };
222
- window.clearTimeout(this.stationUpdateTimeout);
223
- return new Promise((resolve, reject) => {
224
- this.wsApi.get(params, (data) => {
225
- if (data.content) {
226
- stations.push(data.content);
227
- window.clearTimeout(this.stationUpdateTimeout);
228
- this.stationUpdateTimeout = window.setTimeout(() => {
229
- resolve(stations);
230
- }, 50);
231
- } else {
232
- reject(data.content);
208
+ };
209
+ /**
210
+ * Subscribe to a channel.
211
+ *
212
+ * @param {string} channel Name of the websocket channel to subscribe.
213
+ * @param {function} onSuccess Callback when the subscription succeeds.
214
+ * @param {function} onError Callback when the subscription fails.
215
+ * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
216
+ * @private
217
+ */
218
+ RealtimeAPI.prototype.subscribe = function (channel, onSuccess, onError, quiet) {
219
+ if (quiet === void 0) { quiet = false; }
220
+ this.wsApi.subscribe({ channel: channel }, onSuccess, onError, quiet);
221
+ };
222
+ /**
223
+ * Unsubscribe both modes of a channel.
224
+ *
225
+ * @param {string} channel Name of the websocket channel to unsubscribe.
226
+ * @param {string} suffix Suffix to add to the channel name.
227
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
228
+ * @private
229
+ */
230
+ RealtimeAPI.prototype.unsubscribe = function (channel, suffix, cb) {
231
+ this.wsApi.unsubscribe("".concat(channel).concat((0, getRealtimeModeSuffix_1.default)(exports.RealtimeModes.SCHEMATIC, exports.RealtimeModes)).concat(suffix), cb);
232
+ this.wsApi.unsubscribe("".concat(channel).concat((0, getRealtimeModeSuffix_1.default)(exports.RealtimeModes.TOPOGRAPHIC, exports.RealtimeModes)).concat(suffix || ''), cb);
233
+ };
234
+ /**
235
+ * Filter departures and return an array.
236
+ *
237
+ * @param {Object} depObject The object containing departures by id.
238
+ * @param {boolean} [sortByMinArrivalTime=false] If true sort departures by arrival time.
239
+ * @return {Array<departure>} Return departures array.
240
+ * @private
241
+ */
242
+ RealtimeAPI.prototype.filterDepartures = function (depObject, sortByMinArrivalTime) {
243
+ if (sortByMinArrivalTime === void 0) { sortByMinArrivalTime = false; }
244
+ var departures = Object.keys(depObject).map(function (k) { return depObject[k]; });
245
+ departures.sort(function (a, b) { return (0, compareDepartures_1.default)(a, b, sortByMinArrivalTime); });
246
+ var future = new Date();
247
+ future.setMinutes(future.getMinutes() + this.maxDepartureAge);
248
+ future = future.getTime();
249
+ var past = new Date();
250
+ past.setMinutes(past.getMinutes() - this.maxDepartureAge);
251
+ past = past.getTime();
252
+ var departureArray = [];
253
+ var platformsBoarding = [];
254
+ var previousDeparture = null;
255
+ for (var i = departures.length - 1; i >= 0; i -= 1) {
256
+ var d = departures[i];
257
+ var t = new Date(d.time).getTime();
258
+ // Only show departures within the next 30 minutes
259
+ if (t > past && t < future) {
260
+ // If 2 trains are boarding at the same platform,
261
+ // remove the older one.
262
+ if (d.state === 'BOARDING') {
263
+ if (platformsBoarding.indexOf(d.platform) === -1) {
264
+ platformsBoarding.push(d.platform);
265
+ }
266
+ else {
267
+ d.state = 'HIDDEN';
268
+ }
269
+ }
270
+ // If two trains with the same line number and destinatin
271
+ // and a departure difference < 1 minute, hide the second one.
272
+ if (previousDeparture &&
273
+ d.to[0] === previousDeparture.to[0] &&
274
+ Math.abs(t - previousDeparture.time) < 1000 &&
275
+ d.line.name === previousDeparture.line.name) {
276
+ d.state = 'HIDDEN';
277
+ }
278
+ if (/(STOP_CANCELLED|JOURNEY_CANCELLED)/.test(d.state)) {
279
+ d.cancelled = true;
280
+ }
281
+ previousDeparture = d;
282
+ previousDeparture.time = t;
283
+ departureArray.unshift(d);
284
+ }
233
285
  }
234
- });
235
- });
236
- }
237
- subscribeStations(mode, onMessage) {
238
- this.unsubscribeStations();
239
- this.subscribe(`station${getModeSuffix(mode, RealtimeModes)}`, (data) => {
240
- if (data.content) {
241
- onMessage(data.content);
242
- }
243
- });
244
- }
245
- unsubscribeStations(cb) {
246
- window.clearTimeout(this.stationUpdateTimeout);
247
- this.unsubscribe("station", "", cb);
248
- }
249
- subscribeExtraGeoms(onMessage) {
250
- this.subscribe("extra_geoms", (data) => {
251
- const extraGeom = data.content;
252
- if (extraGeom) {
253
- const { ref } = extraGeom.properties;
254
- if (extraGeom.type === "Feature") {
255
- this.extraGeoms[ref] = extraGeom;
256
- } else {
257
- delete this.extraGeoms[ref];
286
+ return departureArray;
287
+ };
288
+ /**
289
+ * Subscribe to departures channel of a given station.
290
+ *
291
+ * @param {number} stationId UIC of the station.
292
+ * @param {Boolean} sortByMinArrivalTime Sort by minimum arrival time
293
+ * @param {function(departures:Departure[])} onMessage Function called on each message of the channel.
294
+ */
295
+ RealtimeAPI.prototype.subscribeDepartures = function (stationId, sortByMinArrivalTime, onMessage) {
296
+ var _this = this;
297
+ window.clearTimeout(this.departureUpdateTimeout);
298
+ this.unsubscribeDepartures();
299
+ this.subscribedStationUic = stationId;
300
+ var channel = stationId ? "timetable_".concat(stationId) : null;
301
+ var departureObject = {};
302
+ this.subscribe(channel, function (data) {
303
+ if (data.source === channel) {
304
+ var content = data.content || {};
305
+ var tDiff = new Date(content.timestamp).getTime() - Date.now();
306
+ content.timediff = tDiff;
307
+ departureObject[content.call_id] = content;
308
+ window.clearTimeout(_this.departureUpdateTimeout);
309
+ _this.departureUpdateTimeout = window.setTimeout(function () {
310
+ var departures = _this.filterDepartures(departureObject, sortByMinArrivalTime || false);
311
+ onMessage(departures);
312
+ }, 100);
313
+ }
314
+ }, function () {
315
+ onMessage([]);
316
+ });
317
+ };
318
+ /**
319
+ * Unsubscribe from current departures channel.
320
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
321
+ */
322
+ RealtimeAPI.prototype.unsubscribeDepartures = function (cb) {
323
+ if (this.subscribedStationUic) {
324
+ this.unsubscribe("timetable_".concat(this.subscribedStationUic), '', cb);
325
+ this.subscribedStationUic = null;
258
326
  }
259
- onMessage(Object.keys(this.extraGeoms).map((key) => this.extraGeoms[key]));
260
- }
261
- });
262
- }
263
- unsubscribeExtraGeoms(cb) {
264
- this.unsubscribe("extra_geoms", "", cb);
265
- }
266
- subscribeTrajectory(mode, onMessage, quiet = false) {
267
- this.unsubscribeTrajectory(onMessage);
268
- this.subscribe(`trajectory${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
269
- }
270
- unsubscribeTrajectory(cb) {
271
- this.unsubscribe(`trajectory`, "", cb);
272
- }
273
- subscribeDeletedVehicles(mode, onMessage, quiet = false) {
274
- this.unsubscribeDeletedVehicles(onMessage);
275
- this.subscribe(`deleted_vehicles${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
276
- }
277
- unsubscribeDeletedVehicles(cb) {
278
- this.unsubscribe("deleted_vehicles", "", cb);
279
- }
280
- getFullTrajectory(id, mode, generalizationLevel) {
281
- const channel = [`full_trajectory${getModeSuffix(mode, RealtimeModes)}`];
282
- if (id) {
283
- channel.push(id);
284
- }
285
- if ((!mode || mode === RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
286
- channel.push(`gen${generalizationLevel}`);
287
- }
288
- const params = {
289
- channel: channel.join("_")
290
327
  };
291
- return new Promise((resolve) => {
292
- this.wsApi.get(params, (data) => {
293
- if (data.content) {
294
- resolve(data.content);
328
+ /**
329
+ * Subscribe to the disruptions channel for tenant.
330
+ *
331
+ * @param {function} onMessage Function called on each message of the channel.
332
+ */
333
+ RealtimeAPI.prototype.subscribeDisruptions = function (onMessage) {
334
+ this.subscribe("".concat(this.prefix, "newsticker"), function (data) {
335
+ onMessage(data.content);
336
+ });
337
+ };
338
+ /**
339
+ * Unsubscribe disruptions.
340
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
341
+ */
342
+ RealtimeAPI.prototype.unsubscribeDisruptions = function (cb) {
343
+ this.unsubscribe("".concat(this.prefix, "newsticker"), '', cb);
344
+ };
345
+ /**
346
+ * Return a station with a given uic number and a mode.
347
+ *
348
+ * @param {number} uic UIC of the station.
349
+ * @param {RealtimeMode} mode Realtime mode.
350
+ * @return {Promise<Station>} A station.
351
+ */
352
+ RealtimeAPI.prototype.getStation = function (uic, mode) {
353
+ var _this = this;
354
+ var params = {
355
+ channel: "station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)),
356
+ args: uic,
357
+ };
358
+ return new Promise(function (resolve, reject) {
359
+ _this.wsApi.get(params, function (data) {
360
+ if (data.content) {
361
+ resolve(data.content);
362
+ }
363
+ else {
364
+ reject();
365
+ }
366
+ });
367
+ });
368
+ };
369
+ /**
370
+ * Update the model's station list for a given mode and a bbox.
371
+ *
372
+ * @param {RealtimeMode} mode Realtime mode.
373
+ * @return {Promise<Array<Station>>} An array of stations.
374
+ */
375
+ RealtimeAPI.prototype.getStations = function (mode) {
376
+ var _this = this;
377
+ var stations = [];
378
+ var params = {
379
+ channel: "station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)),
380
+ };
381
+ window.clearTimeout(this.stationUpdateTimeout);
382
+ return new Promise(function (resolve, reject) {
383
+ _this.wsApi.get(params, function (data) {
384
+ if (data.content) {
385
+ stations.push(data.content);
386
+ window.clearTimeout(_this.stationUpdateTimeout);
387
+ /** @ignore */
388
+ _this.stationUpdateTimeout = window.setTimeout(function () {
389
+ resolve(stations);
390
+ }, 50);
391
+ }
392
+ else {
393
+ reject(data.content);
394
+ }
395
+ });
396
+ });
397
+ };
398
+ /**
399
+ * Subscribe to stations channel.
400
+ * One message pro station.
401
+ *
402
+ * @param {RealtimeMode} mode Realtime mode.
403
+ * @param {function(station: Station)} onMessage Function called on each message of the channel.
404
+ */
405
+ RealtimeAPI.prototype.subscribeStations = function (mode, onMessage) {
406
+ this.unsubscribeStations();
407
+ this.subscribe("station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), function (data) {
408
+ if (data.content) {
409
+ onMessage(data.content);
410
+ }
411
+ });
412
+ };
413
+ /**
414
+ * Unsubscribe to stations channel.
415
+ * @param {function} cb The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
416
+ */
417
+ RealtimeAPI.prototype.unsubscribeStations = function (cb) {
418
+ window.clearTimeout(this.stationUpdateTimeout);
419
+ this.unsubscribe('station', '', cb);
420
+ };
421
+ /**
422
+ * Subscribe to extra_geoms channel.
423
+ *
424
+ * @param {function(extraGeoms: GeosJSONFeature[])} onMessage Function called on each message of the channel.
425
+ */
426
+ RealtimeAPI.prototype.subscribeExtraGeoms = function (onMessage) {
427
+ var _this = this;
428
+ this.subscribe('extra_geoms', function (data) {
429
+ var extraGeom = data.content;
430
+ if (extraGeom) {
431
+ var ref = extraGeom.properties.ref;
432
+ if (extraGeom.type === 'Feature') {
433
+ _this.extraGeoms[ref] = extraGeom;
434
+ }
435
+ else {
436
+ delete _this.extraGeoms[ref];
437
+ }
438
+ onMessage(Object.keys(_this.extraGeoms).map(function (key) { return _this.extraGeoms[key]; }));
439
+ }
440
+ });
441
+ };
442
+ /**
443
+ * Unsubscribe to extra_geoms channel.
444
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
445
+ */
446
+ RealtimeAPI.prototype.unsubscribeExtraGeoms = function (cb) {
447
+ this.unsubscribe('extra_geoms', '', cb);
448
+ };
449
+ /**
450
+ * Subscribe to trajectory channel.
451
+ *
452
+ * @param {RealtimeMode} mode Realtime mode.
453
+ * @param {function(trajectory: RealtimeTrajectory)} onMessage Function called on each message of the channel.
454
+ * @param {boolean} quiet If true, the subscription will not send GET and SUB requests to the websocket.
455
+ */
456
+ RealtimeAPI.prototype.subscribeTrajectory = function (mode, onMessage, quiet) {
457
+ if (quiet === void 0) { quiet = false; }
458
+ this.unsubscribeTrajectory(onMessage);
459
+ this.subscribe("trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), onMessage, null, quiet);
460
+ };
461
+ /**
462
+ * Unsubscribe to trajectory channels.
463
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
464
+ */
465
+ RealtimeAPI.prototype.unsubscribeTrajectory = function (cb) {
466
+ this.unsubscribe("trajectory", '', cb);
467
+ };
468
+ /**
469
+ * Subscribe to deleted_vhicles channel.
470
+ *
471
+ * @param {RealtimeMode} mode Realtime mode.
472
+ * @param {function(response: { content: Vehicle })} onMessage Function called on each message of the channel.
473
+ * @param {boolean} quiet If true, the subscription will not send GET and SUB requests to the websocket.
474
+ */
475
+ RealtimeAPI.prototype.subscribeDeletedVehicles = function (mode, onMessage, quiet) {
476
+ if (quiet === void 0) { quiet = false; }
477
+ this.unsubscribeDeletedVehicles(onMessage);
478
+ this.subscribe("deleted_vehicles".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), onMessage, null, quiet);
479
+ };
480
+ /**
481
+ * Unsubscribe to deleted_vhicles channels.
482
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
483
+ */
484
+ RealtimeAPI.prototype.unsubscribeDeletedVehicles = function (cb) {
485
+ this.unsubscribe('deleted_vehicles', '', cb);
486
+ };
487
+ /**
488
+ * Get a full trajectory of a vehicule .
489
+ *
490
+ * @param {string} id A vehicle id.
491
+ * @param {RealtimeMode} mode Realtime mode.
492
+ * @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
493
+ * @return {Promise<FullTrajectory>} Return a full trajectory.
494
+ */
495
+ RealtimeAPI.prototype.getFullTrajectory = function (id, mode, generalizationLevel) {
496
+ var _this = this;
497
+ var channel = ["full_trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes))];
498
+ if (id) {
499
+ channel.push(id);
295
500
  }
296
- });
297
- });
298
- }
299
- getFullTrajectories(ids, mode, generalizationLevel) {
300
- const promises = ids.map((id) => this.getFullTrajectory(id, mode, generalizationLevel));
301
- return Promise.all(promises);
302
- }
303
- subscribeFullTrajectory(id, mode) {
304
- this.unsubscribeFullTrajectory(id);
305
- this.subscribe(`full_trajectory${getModeSuffix(mode, RealtimeModes)}_${id}`, (data) => {
306
- console.log("subscribe full_trajectory", data);
307
- }, (err) => {
308
- console.log("subscribe full_trajectory error", err);
309
- });
310
- }
311
- unsubscribeFullTrajectory(id, cb) {
312
- this.unsubscribe("full_trajectory", `_${id}`, cb);
313
- }
314
- getStopSequence(id) {
315
- const params = {
316
- channel: `stopsequence_${id}`
317
- };
318
- return new Promise((resolve, reject) => {
319
- this.wsApi.get(params, (data) => {
320
- if (data.content && data.content.length) {
321
- const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
322
- resolve(content);
501
+ if ((!mode || mode === exports.RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
502
+ channel.push("gen".concat(generalizationLevel));
323
503
  }
324
- resolve([]);
325
- }, (err) => {
326
- reject(err);
327
- });
328
- });
329
- }
330
- getStopSequences(ids) {
331
- const promises = ids.map((id) => this.getStopSequence(id));
332
- return Promise.all(promises);
333
- }
334
- subscribeStopSequence(id, onMessage) {
335
- window.clearTimeout(this.fullTrajectoryUpdateTimeout);
336
- this.unsubscribeStopSequence(id);
337
- this.subscribe(`stopsequence_${id}`, (data) => {
338
- if (data.content && data.content.length) {
339
- const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
340
- onMessage(content);
341
- }
342
- }, (err) => {
343
- console.log("subscribe stopsequence error", err);
344
- });
345
- }
346
- unsubscribeStopSequence(id, cb) {
347
- this.unsubscribe(`stopsequence`, `_${id}`, cb);
348
- }
349
- subscribeHealthCheck(onMessage) {
350
- this.unsubscribeHealthCheck();
351
- this.subscribe("healthcheck", onMessage);
352
- }
353
- unsubscribeHealthCheck() {
354
- this.unsubscribe("healthcheck");
355
- }
356
- }
357
- export default RealtimeAPI;
504
+ var params = {
505
+ channel: channel.join('_'),
506
+ };
507
+ return new Promise(function (resolve) {
508
+ _this.wsApi.get(params, function (data) {
509
+ if (data.content) {
510
+ resolve(data.content);
511
+ }
512
+ });
513
+ });
514
+ };
515
+ /**
516
+ * Get full trajectories of a vehicules .
517
+ *
518
+ * @param {string[]} ids List of vehicles ids.
519
+ * @param {RealtimeMode} mode Realtime mode.
520
+ * @param {string} generalizationLevel The generalization level to request. Can be one of '', 'gen5', 'gen10', 'gen30', 'gen100'.
521
+ * @return {Promise<Array<FullTrajectory>>} Return an array of full trajectories.
522
+ */
523
+ RealtimeAPI.prototype.getFullTrajectories = function (ids, mode, generalizationLevel) {
524
+ var _this = this;
525
+ var promises = ids.map(function (id) {
526
+ return _this.getFullTrajectory(id, mode, generalizationLevel);
527
+ });
528
+ return Promise.all(promises);
529
+ };
530
+ /**
531
+ * Subscribe to full_trajectory channel of a given vehicle.
532
+ *
533
+ * @param {string} id A vehicle id.
534
+ * @param {RealtimeMode} mode Realtime mode.
535
+ */
536
+ RealtimeAPI.prototype.subscribeFullTrajectory = function (id, mode) {
537
+ // window.clearTimeout(this.fullTrajectoryUpdateTimeout);
538
+ this.unsubscribeFullTrajectory(id);
539
+ this.subscribe("full_trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes), "_").concat(id), function (data) {
540
+ // eslint-disable-next-line no-console
541
+ console.log('subscribe full_trajectory', data);
542
+ }, function (err) {
543
+ // eslint-disable-next-line no-console
544
+ console.log('subscribe full_trajectory error', err);
545
+ });
546
+ };
547
+ /**
548
+ * Unsubscribe from full_trajectory channel
549
+ *
550
+ * @param {string} id A vehicle id.
551
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
552
+ */
553
+ RealtimeAPI.prototype.unsubscribeFullTrajectory = function (id, cb) {
554
+ this.unsubscribe('full_trajectory', "_".concat(id), cb);
555
+ };
556
+ /**
557
+ * Get the list of stops for this vehicle.
558
+ *
559
+ * @param {string} id A vehicle id.
560
+ * @return {Promise<StopSequence>} Returns a stop sequence object.
561
+ */
562
+ RealtimeAPI.prototype.getStopSequence = function (id) {
563
+ var _this = this;
564
+ var params = {
565
+ channel: "stopsequence_".concat(id),
566
+ };
567
+ return new Promise(function (resolve, reject) {
568
+ _this.wsApi.get(params, function (data) {
569
+ if (data.content && data.content.length) {
570
+ var content = data.content.map(function (stopSequence) {
571
+ return (0, cleanStopTime_1.default)(stopSequence);
572
+ });
573
+ // Remove the delay from arrivalTime and departureTime
574
+ resolve(content);
575
+ }
576
+ resolve([]);
577
+ }, function (err) {
578
+ reject(err);
579
+ });
580
+ });
581
+ };
582
+ /**
583
+ * Get a list of stops for a list of vehicles.
584
+ *
585
+ * @param {string[]} ids List of vehicles ids.
586
+ * @return {Promise<Array<StopSequence>>} Return an array of stop sequences.
587
+ */
588
+ RealtimeAPI.prototype.getStopSequences = function (ids) {
589
+ var _this = this;
590
+ var promises = ids.map(function (id) { return _this.getStopSequence(id); });
591
+ return Promise.all(promises);
592
+ };
593
+ /**
594
+ * Subscribe to stopsequence channel of a given vehicle.
595
+ *
596
+ * @param {string} id A vehicle id.
597
+ * @param {function(stopSequence: StopSequence)} onMessage Function called on each message of the channel.
598
+ */
599
+ RealtimeAPI.prototype.subscribeStopSequence = function (id, onMessage) {
600
+ window.clearTimeout(this.fullTrajectoryUpdateTimeout);
601
+ this.unsubscribeStopSequence(id);
602
+ this.subscribe("stopsequence_".concat(id), function (data) {
603
+ if (data.content && data.content.length) {
604
+ var content = data.content.map(function (stopSequence) {
605
+ return (0, cleanStopTime_1.default)(stopSequence);
606
+ });
607
+ // Remove the delay from arrivalTime and departureTime
608
+ onMessage(content);
609
+ }
610
+ }, function (err) {
611
+ // eslint-disable-next-line no-console
612
+ console.log('subscribe stopsequence error', err);
613
+ });
614
+ };
615
+ /**
616
+ * Unsubscribe from stopsequence channel
617
+ *
618
+ * @param {string} id A vehicle id.
619
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
620
+ */
621
+ RealtimeAPI.prototype.unsubscribeStopSequence = function (id, cb) {
622
+ this.unsubscribe("stopsequence", "_".concat(id), cb);
623
+ };
624
+ /**
625
+ * Subscribe to healthcheck channel.
626
+ * @param {function} onMessage Callback when the subscribe to healthcheck channel succeeds.
627
+ */
628
+ RealtimeAPI.prototype.subscribeHealthCheck = function (onMessage) {
629
+ this.unsubscribeHealthCheck();
630
+ this.subscribe('healthcheck', onMessage);
631
+ };
632
+ /**
633
+ * Unsubscribe to healthcheck channel.
634
+ */
635
+ RealtimeAPI.prototype.unsubscribeHealthCheck = function () {
636
+ this.unsubscribe('healthcheck');
637
+ };
638
+ return RealtimeAPI;
639
+ }());
640
+ exports.default = RealtimeAPI;