mobility-toolbox-js 2.0.0-beta.3 → 2.0.0-beta.33

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 (220) hide show
  1. package/README.md +4 -1
  2. package/api/RealtimeAPI.d.ts +268 -0
  3. package/api/RealtimeAPI.d.ts.map +1 -0
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/StopsAPI.d.ts +36 -0
  7. package/api/StopsAPI.d.ts.map +1 -0
  8. package/api/index.d.ts +5 -0
  9. package/api/index.d.ts.map +1 -0
  10. package/api/typedefs.d.ts +105 -0
  11. package/api/typedefs.d.ts.map +1 -0
  12. package/common/api/HttpAPI.d.ts +31 -0
  13. package/common/api/HttpAPI.d.ts.map +1 -0
  14. package/common/api/WebSocketAPI.d.ts +95 -0
  15. package/common/api/WebSocketAPI.d.ts.map +1 -0
  16. package/common/controls/Control.d.ts +74 -0
  17. package/common/controls/Control.d.ts.map +1 -0
  18. package/common/index.d.ts +3 -0
  19. package/common/index.d.ts.map +1 -0
  20. package/common/layers/Layer.d.ts +80 -0
  21. package/common/layers/Layer.d.ts.map +1 -0
  22. package/common/mixins/CopyrightMixin.d.ts +22 -0
  23. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  24. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  25. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  26. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  27. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  28. package/common/mixins/StopFinderMixin.d.ts +40 -0
  29. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  30. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  31. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  32. package/common/styles/index.d.ts +5 -0
  33. package/common/styles/index.d.ts.map +1 -0
  34. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  35. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  36. package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +3 -9
  37. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  38. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  39. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  40. package/common/typedefs.d.ts +50 -0
  41. package/common/typedefs.d.ts.map +1 -0
  42. package/common/utils/cleanStopTime.d.ts +7 -0
  43. package/common/utils/cleanStopTime.d.ts.map +1 -0
  44. package/common/utils/compareDepartures.d.ts +9 -0
  45. package/common/utils/compareDepartures.d.ts.map +1 -0
  46. package/common/utils/createCanvas.d.ts +9 -0
  47. package/common/utils/createCanvas.d.ts.map +1 -0
  48. package/common/utils/createTrackerFilters.d.ts +12 -0
  49. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  50. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  51. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  52. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  53. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  54. package/common/utils/getMapboxRender.d.ts +5 -0
  55. package/common/utils/getMapboxRender.d.ts.map +1 -0
  56. package/common/utils/getMaplibreRender.d.ts +5 -0
  57. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  58. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  59. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  60. package/common/utils/getUrlWithParams.d.ts +9 -0
  61. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  62. package/common/utils/getVehiclePosition.d.ts +14 -0
  63. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  64. package/common/utils/index.d.ts +12 -0
  65. package/common/utils/index.d.ts.map +1 -0
  66. package/common/utils/removeDuplicate.d.ts +10 -0
  67. package/common/utils/removeDuplicate.d.ts.map +1 -0
  68. package/common/utils/renderTrajectories.d.ts +20 -0
  69. package/common/utils/renderTrajectories.d.ts.map +1 -0
  70. package/common/utils/sortByDelay.d.ts +3 -0
  71. package/common/utils/sortByDelay.d.ts.map +1 -0
  72. package/common/utils/timeUtils.d.ts +5 -0
  73. package/common/utils/timeUtils.d.ts.map +1 -0
  74. package/common/utils/trackerConfig.d.ts +24 -0
  75. package/common/utils/trackerConfig.d.ts.map +1 -0
  76. package/iife.d.ts +3 -0
  77. package/iife.d.ts.map +1 -0
  78. package/index.d.ts +6 -0
  79. package/index.d.ts.map +1 -0
  80. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  81. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  82. package/mapbox/controls/index.d.ts +2 -0
  83. package/mapbox/controls/index.d.ts.map +1 -0
  84. package/mapbox/index.d.ts +5 -0
  85. package/mapbox/index.d.ts.map +1 -0
  86. package/mapbox/layers/Layer.d.ts +47 -0
  87. package/mapbox/layers/Layer.d.ts.map +1 -0
  88. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  89. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  90. package/mapbox/layers/index.d.ts +3 -0
  91. package/mapbox/layers/index.d.ts.map +1 -0
  92. package/mapbox/utils.d.ts +8 -0
  93. package/mapbox/utils.d.ts.map +1 -0
  94. package/mbt.js +50042 -0
  95. package/mbt.js.map +7 -0
  96. package/mbt.min.js +1008 -0
  97. package/mbt.min.js.map +7 -0
  98. package/ol/controls/CopyrightControl.d.ts +31 -0
  99. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  100. package/ol/controls/RoutingControl.d.ts +180 -0
  101. package/ol/controls/RoutingControl.d.ts.map +1 -0
  102. package/ol/controls/StopFinderControl.d.ts +32 -0
  103. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  104. package/ol/controls/index.d.ts +4 -0
  105. package/ol/controls/index.d.ts.map +1 -0
  106. package/ol/index.d.ts +6 -0
  107. package/ol/index.d.ts.map +1 -0
  108. package/ol/layers/Layer.d.ts +49 -0
  109. package/ol/layers/Layer.d.ts.map +1 -0
  110. package/ol/layers/MapboxLayer.d.ts +42 -0
  111. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  112. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  113. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  114. package/ol/layers/MaplibreLayer.d.ts +27 -0
  115. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  116. package/ol/layers/RealtimeLayer.d.ts +119 -0
  117. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  118. package/ol/layers/RoutingLayer.d.ts +24 -0
  119. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  120. package/ol/layers/VectorLayer.d.ts +23 -0
  121. package/ol/layers/VectorLayer.d.ts.map +1 -0
  122. package/ol/layers/WMSLayer.d.ts +38 -0
  123. package/ol/layers/WMSLayer.d.ts.map +1 -0
  124. package/ol/layers/index.d.ts +9 -0
  125. package/ol/layers/index.d.ts.map +1 -0
  126. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  127. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  128. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  129. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  130. package/ol/styles/index.d.ts +3 -0
  131. package/ol/styles/index.d.ts.map +1 -0
  132. package/package.json +56 -95
  133. package/setupTests.d.ts +2 -0
  134. package/setupTests.d.ts.map +1 -0
  135. package/types/index.d.ts +10 -0
  136. package/types/realtime.d.ts +24 -0
  137. package/types/routing.d.ts +206 -0
  138. package/types/stops.d.ts +143 -0
  139. package/api/index.js +0 -3
  140. package/api/routing/RoutingAPI.js +0 -44
  141. package/api/routing/RoutingAPI.test.js +0 -41
  142. package/api/stops/StopsAPI.js +0 -41
  143. package/api/stops/StopsAPI.test.js +0 -34
  144. package/api/tralis/TralisAPI.js +0 -731
  145. package/api/tralis/TralisAPI.test.js +0 -75
  146. package/api/tralis/TralisAPIUtils.js +0 -73
  147. package/api/tralis/WebSocketConnector.js +0 -338
  148. package/api/tralis/WebSocketConnector.test.js +0 -356
  149. package/api/tralis/typedefs.js +0 -81
  150. package/common/Tracker.js +0 -197
  151. package/common/api/api.js +0 -64
  152. package/common/api/api.test.js +0 -68
  153. package/common/controls/Control.js +0 -146
  154. package/common/controls/Control.test.js +0 -98
  155. package/common/layers/Layer.js +0 -404
  156. package/common/layers/Layer.test.js +0 -585
  157. package/common/mixins/CopyrightMixin.js +0 -48
  158. package/common/mixins/SearchMixin.js +0 -176
  159. package/common/mixins/TralisLayerMixin.js +0 -930
  160. package/common/styles/index.js +0 -4
  161. package/common/styles/trackerDefaultStyle.js +0 -333
  162. package/common/styles/trackerSimpleStyle.js +0 -22
  163. package/common/trackerConfig.js +0 -190
  164. package/common/trackerConfig.test.js +0 -25
  165. package/common/typedefs.js +0 -23
  166. package/common/utils/createTrackerFilters.js +0 -87
  167. package/common/utils/createTrackerFilters.test.js +0 -95
  168. package/common/utils/getMapboxMapCopyrights.js +0 -32
  169. package/common/utils/getMapboxMapCopyrights.test.js +0 -47
  170. package/common/utils/getMapboxStyleUrl.js +0 -32
  171. package/common/utils/getVehiclePosition.js +0 -72
  172. package/common/utils/index.js +0 -6
  173. package/common/utils/removeDuplicate.js +0 -22
  174. package/common/utils/removeDuplicate.test.js +0 -22
  175. package/common/utils/sortByDelay.js +0 -23
  176. package/common/utils/timeUtils.js +0 -44
  177. package/common/utils/timeUtils.test.js +0 -16
  178. package/index.js +0 -2
  179. package/index.js.map +0 -1
  180. package/mapbox/controls/CopyrightControl.js +0 -58
  181. package/mapbox/index.js +0 -3
  182. package/mapbox/layers/Layer.js +0 -118
  183. package/mapbox/layers/Layer.test.js +0 -202
  184. package/mapbox/layers/TralisLayer.js +0 -329
  185. package/mapbox/layers/TralisLayer.test.js +0 -40
  186. package/mapbox/utils.js +0 -46
  187. package/module.js +0 -23
  188. package/ol/README.md +0 -0
  189. package/ol/controls/CopyrightControl.js +0 -80
  190. package/ol/controls/CopyrightControl.test.js +0 -211
  191. package/ol/controls/RoutingControl.js +0 -752
  192. package/ol/controls/RoutingControl.test.js +0 -216
  193. package/ol/controls/StopFinderControl.js +0 -38
  194. package/ol/controls/StopFinderControl.test.js +0 -59
  195. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  196. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  197. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  198. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  199. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  200. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  201. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  202. package/ol/index.js +0 -13
  203. package/ol/layers/Layer.js +0 -193
  204. package/ol/layers/Layer.test.js +0 -197
  205. package/ol/layers/MapboxLayer.js +0 -378
  206. package/ol/layers/MapboxLayer.test.js +0 -186
  207. package/ol/layers/MapboxStyleLayer.js +0 -417
  208. package/ol/layers/MapboxStyleLayer.test.js +0 -262
  209. package/ol/layers/MaplibreLayer.js +0 -280
  210. package/ol/layers/RoutingLayer.js +0 -91
  211. package/ol/layers/RoutingLayer.test.js +0 -49
  212. package/ol/layers/TralisLayer.js +0 -359
  213. package/ol/layers/TralisLayer.test.js +0 -97
  214. package/ol/layers/VectorLayer.js +0 -43
  215. package/ol/layers/VectorLayer.test.js +0 -98
  216. package/ol/layers/WMSLayer.js +0 -80
  217. package/ol/layers/WMSLayer.test.js +0 -84
  218. package/ol/styles/fullTrajectoryDelayStyle.js +0 -35
  219. package/ol/styles/fullTrajectoryStyle.js +0 -51
  220. package/ol/styles/index.js +0 -2
@@ -1,356 +0,0 @@
1
- import WS from 'jest-websocket-mock';
2
- import Connector from './WebSocketConnector';
3
-
4
- describe('WebSocketConnector', () => {
5
- describe('#constructor', () => {
6
- let server;
7
- let server2;
8
-
9
- beforeEach(() => {
10
- server = new WS(`ws://foo:1234`);
11
- server2 = new WS(`ws://foo:12345`);
12
- });
13
-
14
- afterEach(() => {
15
- server.close();
16
- server2.close();
17
- WS.clean();
18
- });
19
-
20
- describe('#constructor', () => {
21
- test("doesn't connect.", async () => {
22
- const client = new Connector();
23
- expect(client.websocket).toBe();
24
- expect(client.closed).toBe(false);
25
- expect(client.closing).toBe(false);
26
- expect(client.connecting).toBe(false);
27
- expect(client.open).toBe(false);
28
- });
29
- });
30
-
31
- describe('#close', () => {
32
- test('should close the websocket and clear some property', async () => {
33
- // eslint-disable-next-line no-unused-vars
34
- const client = new Connector();
35
- const subsc2 = {
36
- params: 'foo',
37
- cb: () => {},
38
- errorCb: () => {},
39
- quiet: false,
40
- };
41
- client.subscriptions = [subsc2];
42
- client.messagesOnOpen = ['GET foo'];
43
- client.connect(`ws://foo:1234`);
44
- client.websocket.addEventListener = jest.fn();
45
- client.websocket.removeEventListener = jest.fn();
46
- client.websocket.close = jest.fn();
47
- await server.connected;
48
- expect(client.websocket).toBeDefined();
49
- expect(client.messagesOnOpen).toEqual(['GET foo']);
50
- client.close();
51
- expect(client.messagesOnOpen).toEqual([]);
52
- expect(client.websocket).toBeNull();
53
- });
54
- });
55
-
56
- describe('#connect', () => {
57
- test('create a new WebSocket.', async () => {
58
- const client = new Connector();
59
- client.connect(`ws://foo:1234`);
60
- await server.connected;
61
- client.send('hello');
62
- await expect(server).toReceiveMessage('hello');
63
- expect(server).toHaveReceivedMessages(['hello']);
64
- });
65
-
66
- test('close previous connection.', async () => {
67
- const client = new Connector();
68
- client.connect(`ws://foo:1234`);
69
- await server.connected;
70
- expect(client.websocket).toBeDefined();
71
- const old = client.websocket;
72
- expect(old.readyState).toBe(WebSocket.OPEN);
73
- client.connect(`ws://foo:12345`);
74
- expect(old.readyState).toBe(WebSocket.CLOSING);
75
- expect(client.websocket.readyState).toBe(WebSocket.CONNECTING);
76
- });
77
-
78
- test('call onOpen function', async () => {
79
- const onOpen = jest.fn();
80
- const client = new Connector();
81
- client.subscribe = jest.fn();
82
- client.connect(`ws://foo:1234`, onOpen);
83
- await server.connected;
84
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
85
- expect(onOpen).toHaveBeenCalledTimes(1);
86
- });
87
-
88
- test('subscribe previous subscriptions on open (quiet or not)', async () => {
89
- const client = new Connector();
90
- client.subscribe = jest.fn();
91
- client.send = jest.fn();
92
- const subsc = {
93
- params: 'foo',
94
- cb: () => {},
95
- errorCb: () => {},
96
- quiet: true,
97
- };
98
- const subsc2 = {
99
- params: 'foo',
100
- cb: () => {},
101
- errorCb: () => {},
102
- quiet: false,
103
- };
104
- client.subscriptions = [subsc, subsc2];
105
-
106
- client.connect(`ws://foo:1234`);
107
- await server.connected;
108
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
109
- expect(client.subscribe).toHaveBeenCalledTimes(2);
110
- client.subscribe.mockReset();
111
-
112
- client.connect(`ws://foo:12345`);
113
- await server2.connected;
114
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
115
- expect(client.subscribe).toHaveBeenCalledTimes(2);
116
- expect(client.subscribe).toHaveBeenCalledWith(
117
- subsc.params,
118
- subsc.cb,
119
- subsc.errorCb,
120
- subsc.quiet,
121
- );
122
- });
123
-
124
- test('send GET and SUB for not quiet previous subscriptions', async () => {
125
- const client = new Connector();
126
- client.send = jest.fn();
127
- const subsc = {
128
- params: { channel: 'foo' },
129
- cb: () => {},
130
- errorCb: () => {},
131
- quiet: false,
132
- };
133
- client.subscriptions = [subsc];
134
-
135
- client.connect(`ws://foo:1234`);
136
- client.websocket.addEventListener = jest.fn();
137
- client.websocket.removeEventListener = jest.fn();
138
- await server.connected;
139
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
140
- expect(client.send).toHaveBeenCalledTimes(2);
141
- expect(client.send.mock.calls[0]).toEqual(['GET foo']);
142
- expect(client.send.mock.calls[1]).toEqual(['SUB foo']);
143
- client.send.mockReset();
144
-
145
- client.connect(`ws://foo:12345`);
146
- client.websocket.addEventListener = jest.fn();
147
- client.websocket.removeEventListener = jest.fn();
148
- await server2.connected;
149
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
150
- // not quiet subscriptions will send GET and SUB requests.
151
- expect(client.send).toHaveBeenCalledTimes(2);
152
- expect(client.send.mock.calls[0]).toEqual(['GET foo']);
153
- expect(client.send.mock.calls[1]).toEqual(['SUB foo']);
154
- });
155
-
156
- test('doesn\t send GET and SUB for quiet previous subscriptions', async () => {
157
- const client = new Connector();
158
- client.send = jest.fn();
159
- const subsc = {
160
- params: { channel: 'foo' },
161
- cb: () => {},
162
- errorCb: () => {},
163
- quiet: true,
164
- };
165
- client.subscriptions = [subsc];
166
-
167
- client.connect(`ws://foo:1234`);
168
- client.websocket.addEventListener = jest.fn();
169
- client.websocket.removeEventListener = jest.fn();
170
- await server.connected;
171
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
172
- expect(client.send).toHaveBeenCalledTimes(0);
173
- client.send.mockReset();
174
-
175
- client.connect(`ws://foo:12345`);
176
- client.websocket.addEventListener = jest.fn();
177
- client.websocket.removeEventListener = jest.fn();
178
- await server2.connected;
179
- expect(client.websocket.readyState).toBe(WebSocket.OPEN);
180
- // not quiet subscriptions will send GET and SUB requests.
181
- expect(client.send).toHaveBeenCalledTimes(0);
182
- });
183
- });
184
-
185
- describe('#subscribe', () => {
186
- test('adds subscription to subscriptions array', async () => {
187
- // eslint-disable-next-line no-unused-vars
188
- const client = new Connector();
189
- client.connect(`ws://foo:1234`);
190
- await server.connected;
191
- const params = { channel: 'bar', args: ['baz'], id: 'id' };
192
- const cb = jest.fn();
193
- const errorCb = jest.fn();
194
- client.subscribe(params, cb, errorCb);
195
- expect(client.subscriptions.length).toBe(1);
196
- expect(client.subscriptions[0].params).toBe(params);
197
- expect(client.subscriptions[0].cb).toBe(cb);
198
- expect(client.subscriptions[0].errorCb).toBe(errorCb);
199
- expect(client.subscriptions[0].quiet).toBe(false);
200
-
201
- const obj = { source: 'bar baz', client_reference: 'id' };
202
- server.send(JSON.stringify(obj));
203
-
204
- expect(cb).toHaveBeenCalledTimes(1);
205
- expect(cb).toHaveBeenCalledWith(obj);
206
- });
207
-
208
- test("doesn't duplicate subscriptions", async () => {
209
- // eslint-disable-next-line no-unused-vars
210
- const client = new Connector();
211
- client.connect(`ws://foo:1234`);
212
- await server.connected;
213
- const params = { channel: 'bar', args: ['baz'], id: 'id' };
214
- const cb = jest.fn();
215
- const errorCb = jest.fn();
216
- client.subscribe(params, cb, errorCb, true);
217
- client.subscribe(params, cb, errorCb, true);
218
- expect(client.subscriptions.length).toBe(1);
219
-
220
- const obj = { source: 'bar baz', client_reference: 'id' };
221
- server.send(JSON.stringify(obj));
222
-
223
- expect(cb).toHaveBeenCalledTimes(1);
224
- expect(cb).toHaveBeenCalledWith(obj);
225
- });
226
-
227
- test('send GET and SUB requests.', async () => {
228
- // eslint-disable-next-line no-unused-vars
229
- const client = new Connector();
230
- client.connect(`ws://foo:1234`);
231
- client.send = jest.fn();
232
- const params = { channel: 'bar', args: ['baz'], id: 'id' };
233
- const cb = jest.fn();
234
- const errorCb = jest.fn();
235
- client.subscribe(params, cb, errorCb);
236
- expect(client.send).toHaveBeenCalledTimes(2);
237
- expect(client.send).toHaveBeenCalledWith('GET bar baz id');
238
- expect(client.send).toHaveBeenCalledWith('SUB bar baz id');
239
- client.send.mockRestore();
240
- });
241
-
242
- test('should register callback without sending GET and SUB requests (quiet=true).', async () => {
243
- // eslint-disable-next-line no-unused-vars
244
- const client = new Connector();
245
- client.connect(`ws://foo:1234`);
246
- await server.connected;
247
- const params = { channel: 'bar', args: ['baz'], id: 'id' };
248
- const cb = jest.fn();
249
- const errorCb = jest.fn();
250
- client.send = jest.fn();
251
- client.subscribe(params, cb, errorCb, true);
252
- expect(client.subscriptions.length).toBe(1);
253
- expect(client.subscriptions[0].params).toBe(params);
254
- expect(client.subscriptions[0].cb).toBe(cb);
255
- expect(client.subscriptions[0].errorCb).toBe(errorCb);
256
- expect(client.subscriptions[0].quiet).toBe(true);
257
- expect(client.send).toBeCalledTimes(0);
258
- client.send.mockRestore();
259
- });
260
- });
261
-
262
- describe('#unsubscribe', () => {
263
- test('should only unsubscribe the subscription using the good cb', async () => {
264
- // eslint-disable-next-line no-unused-vars
265
- const client = new Connector();
266
- client.connect(`ws://foo:1234`);
267
- await server.connected;
268
- const params = { channel: 'foo', id: 'id' };
269
- const cb = jest.fn();
270
- const cb2 = jest.fn();
271
- client.subscribe(params, cb);
272
- client.subscribe(params, cb2);
273
- expect(client.subscriptions.length).toBe(2);
274
- expect(client.subscriptions[0].params).toBe(params);
275
- expect(client.subscriptions[0].cb).toBe(cb);
276
- expect(client.subscriptions[1].params).toBe(params);
277
- expect(client.subscriptions[1].cb).toBe(cb2);
278
-
279
- client.unsubscribe('foo', cb);
280
- expect(client.subscriptions.length).toBe(1);
281
-
282
- expect(cb).toHaveBeenCalledTimes(0);
283
- expect(cb2).toHaveBeenCalledTimes(0);
284
- const obj = { source: 'foo', client_reference: 'id' };
285
- server.send(JSON.stringify(obj));
286
-
287
- expect(cb2).toHaveBeenCalledTimes(1);
288
- expect(cb).toHaveBeenCalledTimes(0);
289
- });
290
-
291
- test('should unsubscribe all subscriptions related to a channel', () => {
292
- // eslint-disable-next-line no-unused-vars
293
- const client = new Connector();
294
- client.connect(`ws://foo:1234`);
295
- client.websocket.removeEventListener = jest.fn();
296
- client.websocket.addEventListener = jest.fn();
297
- const params = { channel: 'foo' };
298
- const params2 = { channel: 'bar' };
299
- const cb = jest.fn();
300
- const cb2 = jest.fn();
301
- client.subscribe(params, cb);
302
- client.subscribe(params, cb);
303
- client.subscribe(params, cb);
304
- client.subscribe(params, cb2);
305
- client.subscribe(params2, cb2);
306
- expect(client.subscriptions.length).toBe(3);
307
- expect(client.websocket.removeEventListener).toBeCalledTimes(2);
308
- expect(
309
- client.websocket.addEventListener.mock.calls.filter(
310
- (c) => c[0] === 'message',
311
- ).length,
312
- ).toBe(5);
313
-
314
- client.unsubscribe('foo');
315
- expect(client.subscriptions.length).toBe(1);
316
- expect(client.subscriptions[0].params).toBe(params2);
317
- expect(client.subscriptions[0].cb).toBe(cb2);
318
- });
319
-
320
- test('send DEL when there is no more unquiet subscriptions on the channel', async () => {
321
- // eslint-disable-next-line no-unused-vars
322
- const client = new Connector();
323
- client.connect(`ws://foo:1234`);
324
- await server.connected;
325
- client.send = jest.fn();
326
- client.websocket.removeEventListener = jest.fn();
327
- client.websocket.addEventListener = jest.fn();
328
- const params = { channel: 'foo' };
329
- const cb = jest.fn();
330
- client.subscribe(params, cb);
331
- expect(client.send).toHaveBeenCalledWith('GET foo');
332
- expect(client.send).toHaveBeenCalledWith('SUB foo');
333
-
334
- client.unsubscribe('foo');
335
- expect(client.send).toHaveBeenCalledWith('DEL foo');
336
- });
337
-
338
- test("doesn't send DEL when we unsubscribe a quiet channel", () => {
339
- // eslint-disable-next-line no-unused-vars
340
- const client = new Connector();
341
- client.connect(`ws://foo:1234`);
342
- client.send = jest.fn();
343
- client.websocket.removeEventListener = jest.fn();
344
- client.websocket.addEventListener = jest.fn();
345
- const params = { channel: 'foo' };
346
- const cb = jest.fn();
347
- client.subscribe(params, cb, null, true);
348
- expect(cb).toHaveBeenCalledTimes(0);
349
-
350
- client.unsubscribe('foo');
351
- expect(cb).toHaveBeenCalledTimes(0);
352
- client.send.mockRestore();
353
- });
354
- });
355
- });
356
- });
@@ -1,81 +0,0 @@
1
- /**
2
- * @typedef {Object} Departure
3
- * @property {number} time Timestamp in ms.
4
- * @property {boolean} no_stop_between
5
- * @property {number} train_number
6
- * @property {string[]} to
7
- * @property {number} ris_aimed_time Timestamp in ms.
8
- * @property {number} updated_at Timestamp in ms.
9
- * @property {boolean} new_to
10
- * @property {number} min_arrival_time Timestamp in ms.
11
- * @property {string[]} next_stoppoints List of next stops. Like value in at_station_ds100.
12
- * @property {number} ris_estimated_time Timestamp in ms.
13
- * @property {NetworkLine} line
14
- * @property {boolean} has_fzo if true this departure has realtime data.
15
- * @property {number} train_id
16
- * @property {string} platform
17
- * @property {?*} state
18
- * @property {number} fzo_estimated_time Timestamp in ms.
19
- * @property {?*} formation
20
- * @property {?*} no_stop_till
21
- * @property {number} train_type
22
- * @property {number} call_id
23
- * @property {string} created_at Timestamp in ms.
24
- * @property {string} at_station_ds100
25
- * @property {number} timediff Timestamp in ms.
26
- *
27
- */
28
-
29
- /**
30
- * @typedef {GeoJSONFeature} Station
31
- * @property {StationProperties} properties Returns the station's properties.
32
- * @property {GeoJSONPoint} geometry Returns a point.
33
- */
34
-
35
- /**
36
- * @typedef {Object} StationProperties
37
- * @property {Transfer[]} transfers
38
- * @property {boolean} elevatorOutOfOrder
39
- * @property {number} uic
40
- * @property {string} name
41
- * @property {NetworkLine[]} networkLines
42
- * @property {boolean} hasElevator
43
- * @property {boolean} hasZOB
44
- * @property {boolean} hasAccessibility
45
- * @property {string} type
46
- */
47
-
48
- /**
49
- * @typedef {Object} NetworkLine
50
- * @property {number} id Identifier of the line.
51
- * @property {string} color Color of the line (CSS color string).
52
- * @property {string} stroke Stroke color of the line (CSS color string).
53
- * @property {string} name Name of the line.
54
- * @property {string} text_color Text color of the line (CSS color string).
55
- */
56
-
57
- /**
58
- * @typedef {Object} Transfer
59
- * @property {string} mot Mode of transportation (ex: U-Bahn).
60
- * @property {string[]} lines Array of lines name (ex: ["U4", "U5"]).
61
- */
62
-
63
- /**
64
- * @typedef {GeoJSONFeature} StopSequence
65
- */
66
-
67
- /**
68
- * @typedef {GeoJSONFeature} TralisTrajectory
69
- */
70
-
71
- /**
72
- * @typedef {GeoJSONFeature} FullTrajectory
73
- */
74
-
75
- /**
76
- * @typedef {GeoJSONFeature} Vehicle
77
- */
78
-
79
- /**
80
- * @typedef {GeoJSONFeature} ExtraGeom
81
- */
package/common/Tracker.js DELETED
@@ -1,197 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- import { compose, apply, create } from 'ol/transform';
3
- import getVehiclePosition from './utils/getVehiclePosition';
4
-
5
- /**
6
- * Tracker. This class stores and allows to draw trajectories on a canvas.
7
- * @class
8
- * @param {Object} options
9
- * @private
10
- */
11
- export default class Tracker {
12
- /**
13
- * @private
14
- */
15
- constructor(options) {
16
- /**
17
- * Function use to style the features displayed.
18
- * @type {function}
19
- */
20
- this.style = options.style;
21
-
22
- // we draw directly on the canvas since openlayers is too slow.
23
- /**
24
- * HTML <canvas> element.
25
- * @type {Canvas}
26
- */
27
- this.canvas = options.canvas || document.createElement('canvas');
28
- }
29
-
30
- /**
31
- * Draw all the trajectories available to the canvas.
32
- * @param {ViewState} trajectories An array of trajectories.
33
- * @param {ViewState} viewState The view state of the map.
34
- * @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
35
- * @param {boolean} options.selectedVehicleId The id of the vehicle to select.
36
- * @param {boolean} options.noInterpolate If true trajectories are not interpolated but
37
- * drawn at the last known coordinate. Use this for performance optimization
38
- * during map navigation.
39
- * @private
40
- */
41
- renderTrajectories(trajectories, viewState, options) {
42
- const {
43
- time = Date.now(),
44
- size = [],
45
- center,
46
- resolution,
47
- rotation = 0,
48
- pixelRatio,
49
- } = viewState;
50
- const {
51
- noInterpolate = false,
52
- hoverVehicleId,
53
- selectedVehicleId,
54
- } = options;
55
-
56
- const { canvas } = this;
57
- const context = canvas.getContext('2d');
58
- context.clearRect(0, 0, canvas.width, canvas.height);
59
-
60
- const [width, height] = size;
61
- if (
62
- width &&
63
- height &&
64
- (canvas.width !== width || canvas.height !== height)
65
- ) {
66
- [canvas.width, canvas.height] = [width * pixelRatio, height * pixelRatio];
67
- }
68
-
69
- const coordinateToPixelTransform = compose(
70
- create(),
71
- size[0] / 2,
72
- size[1] / 2,
73
- 1 / resolution,
74
- -1 / resolution,
75
- -rotation,
76
- -center[0],
77
- -center[1],
78
- );
79
-
80
- // Offscreen canvas has not style attribute
81
- if (canvas.style) {
82
- canvas.style.width = `${canvas.width / pixelRatio}px`;
83
- canvas.style.height = `${canvas.height / pixelRatio}px`;
84
- }
85
-
86
- let hoverVehicleImg;
87
- let hoverVehiclePx;
88
- let hoverVehicleWidth;
89
- let hoverVehicleHeight;
90
- let selectedVehicleImg;
91
- let selectedVehiclePx;
92
- let selectedVehicleWidth;
93
- let selectedVehicleHeight;
94
- let nbRendered = 0;
95
-
96
- for (let i = trajectories.length - 1; i >= 0; i -= 1) {
97
- const trajectory = trajectories[i];
98
-
99
- // We simplify the trajectory object
100
- const { train_id: id, timeOffset } = trajectory.properties;
101
- // We set the rotation and the timeFraction of the trajectory (used by tralis).
102
- // if rotation === null that seems there is no rotation available.
103
- const { coord, rotation: rotationIcon } = getVehiclePosition(
104
- time - (timeOffset || 0),
105
- trajectory,
106
- noInterpolate,
107
- );
108
-
109
- // We store the current vehicle position to the trajectory.
110
- trajectories[i].properties.coordinate = coord;
111
- trajectories[i].properties.rotation = rotationIcon;
112
-
113
- if (!coord) {
114
- // eslint-disable-next-line no-continue
115
- continue;
116
- }
117
-
118
- let px = apply(coordinateToPixelTransform, [...coord]);
119
- if (!px) {
120
- // eslint-disable-next-line no-continue
121
- continue;
122
- }
123
-
124
- px = px.map((p) => p * pixelRatio);
125
-
126
- if (
127
- px[0] < 0 ||
128
- px[0] > canvas.width ||
129
- px[1] < 0 ||
130
- px[1] > canvas.height
131
- ) {
132
- // eslint-disable-next-line no-continue
133
- continue;
134
- }
135
-
136
- const vehicleImg = this.style(trajectory, viewState, options);
137
- if (!vehicleImg) {
138
- // eslint-disable-next-line no-continue
139
- continue;
140
- }
141
-
142
- nbRendered += 1;
143
-
144
- const imgWidth = vehicleImg.width;
145
- const imgHeight = vehicleImg.height;
146
-
147
- if (hoverVehicleId !== id && selectedVehicleId !== id) {
148
- context.drawImage(
149
- vehicleImg,
150
- px[0] - imgWidth / 2,
151
- px[1] - imgHeight / 2,
152
- imgWidth,
153
- imgHeight,
154
- );
155
- }
156
-
157
- if (hoverVehicleId && hoverVehicleId === id) {
158
- // Store the canvas to draw it at the end
159
- hoverVehicleImg = vehicleImg;
160
- hoverVehiclePx = px;
161
- hoverVehicleWidth = imgWidth;
162
- hoverVehicleHeight = imgHeight;
163
- }
164
-
165
- if (selectedVehicleId && selectedVehicleId === id) {
166
- // Store the canvas to draw it at the end
167
- selectedVehicleImg = vehicleImg;
168
- selectedVehiclePx = px;
169
- selectedVehicleWidth = imgWidth;
170
- selectedVehicleHeight = imgHeight;
171
- }
172
- }
173
-
174
- if (selectedVehicleImg) {
175
- context.drawImage(
176
- selectedVehicleImg,
177
- selectedVehiclePx[0] - selectedVehicleWidth / 2,
178
- selectedVehiclePx[1] - selectedVehicleHeight / 2,
179
- selectedVehicleWidth,
180
- selectedVehicleHeight,
181
- );
182
- }
183
-
184
- if (hoverVehicleImg) {
185
- context.drawImage(
186
- hoverVehicleImg,
187
- hoverVehiclePx[0] - hoverVehicleWidth / 2,
188
- hoverVehiclePx[1] - hoverVehicleHeight / 2,
189
- hoverVehicleWidth,
190
- hoverVehicleHeight,
191
- );
192
- }
193
- return {
194
- nbTrajectoriesRendered: nbRendered,
195
- };
196
- }
197
- }
package/common/api/api.js DELETED
@@ -1,64 +0,0 @@
1
- import qs from 'query-string';
2
- import BaseObject from 'ol/Object';
3
-
4
- /**
5
- * Common class to access to a geOps api.
6
- *
7
- * @example
8
- * import { API } from 'mobility-toolbox-js/api';
9
- *
10
- * const api = new API({
11
- * url: [yourUrl],
12
- * apiKey: [yourApiKey]
13
- * });
14
- *
15
- * @classproperty {string} url Url of the service.
16
- * @classproperty {string} apiKey Api key to access the service.
17
- */
18
- class API extends BaseObject {
19
- constructor(options = {}) {
20
- super();
21
- /** @ignore */
22
- this.url = options.url;
23
-
24
- /** @ignore */
25
- this.apiKey = options.apiKey;
26
- }
27
-
28
- /**
29
- * Append the apiKey before sending the request.
30
- * @ignore
31
- */
32
- fetch(path, params, config) {
33
- // Clean requets parameters, removing undefined and null values.
34
- const urlParams = { ...(params || {}), key: this.apiKey };
35
- const clone = { ...urlParams };
36
- Object.keys(urlParams).forEach(
37
- (key) =>
38
- (clone[key] === undefined || clone[key] === null) && delete clone[key],
39
- );
40
- if (!this.apiKey) {
41
- // eslint-disable-next-line no-console
42
- return Promise.reject(
43
- new Error(`No apiKey defined for request to ${this.url}`),
44
- );
45
- }
46
- return fetch(
47
- `${this.url}${path || ''}?${qs.stringify(clone)}`,
48
- config,
49
- ).then((response) => {
50
- try {
51
- return response.json().then((data) => {
52
- if (data.error) {
53
- throw new Error(data.error);
54
- }
55
- return data;
56
- });
57
- } catch (err) {
58
- return Promise.reject(new Error(err));
59
- }
60
- });
61
- }
62
- }
63
-
64
- export default API;