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.
- package/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +626 -343
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +65 -15
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +70 -12
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +10 -3
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +72 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +82 -30
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +313 -168
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/controls/Control.js +167 -78
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +18 -2
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/layers/Layer.js +251 -134
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.js +70 -22
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.js +240 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +698 -429
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.js +195 -107
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +222 -121
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +24 -4
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +236 -190
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +25 -7
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -17
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +21 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/cleanStopTime.js +28 -17
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +34 -22
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +28 -16
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.js +75 -54
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -13
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +24 -17
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +77 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +11 -2
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +20 -10
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +63 -39
- package/common/utils/index.d.ts +12 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +37 -9
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +29 -7
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +111 -78
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +21 -17
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +47 -18
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/common/utils/trackerConfig.js +171 -118
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +7 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -7
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +72 -28
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +6 -1
- package/mapbox/index.d.ts +5 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +20 -4
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +137 -54
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +310 -183
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +7 -2
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mapbox/utils.js +54 -29
- package/mbt.js +2052 -2109
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +89 -41
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +666 -371
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +59 -10
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +9 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +21 -5
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +178 -81
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +131 -198
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +382 -186
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +67 -138
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +327 -184
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +111 -56
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +71 -21
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +105 -37
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +19 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +44 -40
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +7 -2
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +15 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.test.js +0 -23
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.test.js +0 -57
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export default WebSocketAPI;
|
|
2
|
+
/**
|
|
3
|
+
* Class used to facilitate connection to a WebSocket and
|
|
4
|
+
* also to manage properly messages send to the WebSocket.
|
|
5
|
+
* This class must not contain any specific implementation.
|
|
6
|
+
*/
|
|
7
|
+
declare class WebSocketAPI {
|
|
8
|
+
/**
|
|
9
|
+
* Get the websocket request string.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} method Request mehtod {GET, SUB}.
|
|
12
|
+
* @param {Object} params Request parameters.
|
|
13
|
+
* @param {string} params.channel Channel name
|
|
14
|
+
* @param {string} [params.args] Request arguments
|
|
15
|
+
* @param {Number} [params.id] Request identifier
|
|
16
|
+
* @return {string} request string
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private static getRequestString;
|
|
20
|
+
defineProperties(): void;
|
|
21
|
+
/**
|
|
22
|
+
* (Re)connect the websocket.
|
|
23
|
+
*
|
|
24
|
+
* @param {strin} url Websocket url.
|
|
25
|
+
* @param {function} onOpen Callback called when the websocket connection is opened and before subscriptions of previous subscriptions.
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
private connect;
|
|
29
|
+
/** @ignore */
|
|
30
|
+
websocket: WebSocket;
|
|
31
|
+
/**
|
|
32
|
+
* Close the websocket definitively.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private close;
|
|
37
|
+
messagesOnOpen: any[];
|
|
38
|
+
/**
|
|
39
|
+
* Sends a message to the websocket.
|
|
40
|
+
*
|
|
41
|
+
* @param {message} message Message to send.
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
private send;
|
|
45
|
+
/**
|
|
46
|
+
* Listen to websocket messages.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} params Parameters for the websocket get request
|
|
49
|
+
* @param {function} cb callback on listen
|
|
50
|
+
* @param {function} errorCb Callback on error
|
|
51
|
+
* @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
private listen;
|
|
55
|
+
/**
|
|
56
|
+
* Unlisten websocket messages.
|
|
57
|
+
*
|
|
58
|
+
* @param {Object} params Parameters for the websocket get request.
|
|
59
|
+
* @param {function} cb Callback used when listen.
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
private unlisten;
|
|
63
|
+
/**
|
|
64
|
+
* Sends a get request to the websocket.
|
|
65
|
+
*
|
|
66
|
+
* @param {Object} params Parameters for the websocket get request
|
|
67
|
+
* @param {function} cb callback on listen
|
|
68
|
+
* @param {function} errorCb Callback on error
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private get;
|
|
72
|
+
/**
|
|
73
|
+
* Subscribe to a given channel.
|
|
74
|
+
*
|
|
75
|
+
* @param {Object} params Parameters for the websocket get request
|
|
76
|
+
* @param {function} cb callback on listen
|
|
77
|
+
* @param {function} errorCb Callback on error
|
|
78
|
+
* @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private subscribe;
|
|
82
|
+
/**
|
|
83
|
+
* Unsubscribe from a channel.
|
|
84
|
+
* @param {string} source source to unsubscribe from
|
|
85
|
+
* @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
private unsubscribe;
|
|
89
|
+
subscriptions: any;
|
|
90
|
+
/**
|
|
91
|
+
* After an auto reconnection we need to re-subscribe to the channels.
|
|
92
|
+
*/
|
|
93
|
+
subscribePreviousSubscriptions(): void;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=WebSocketAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketAPI.d.ts","sourceRoot":"","sources":["../../../src/common/api/WebSocketAPI.js"],"names":[],"mappings":";AAAA;;;;GAIG;AACH;IAiEE;;;;;;;;;;OAUG;IACH,gCAKC;IA5ED,yBA0DC;IAoBD;;;;;;OAMG;IACH,gBAiBC;IAZC,cAAc;IACd,qBAAmC;IAarC;;;;OAIG;IACH,cAOC;IAFG,sBAAwB;IAI5B;;;;;OAKG;IACH,aAsBC;IAED;;;;;;;;OAQG;IACH,eAsCC;IAED;;;;;;OAMG;IACH,iBAiBC;IAED;;;;;;;OAOG;IACH,YAIC;IAED;;;;;;;;OAQG;IACH,kBAqBC;IAED;;;;;OAKG;IACH,oBA8BC;IAfC,mBAEC;IAeH;;OAEG;IACH,uCAYC;CACF"}
|
|
@@ -1,175 +1,320 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CLOSED)
|
|
9
|
-
},
|
|
10
|
-
closing: {
|
|
11
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CLOSING)
|
|
12
|
-
},
|
|
13
|
-
connecting: {
|
|
14
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CONNECTING)
|
|
15
|
-
},
|
|
16
|
-
open: {
|
|
17
|
-
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN)
|
|
18
|
-
},
|
|
19
|
-
messagesOnOpen: {
|
|
20
|
-
value: [],
|
|
21
|
-
writable: true
|
|
22
|
-
},
|
|
23
|
-
subscriptions: {
|
|
24
|
-
value: [],
|
|
25
|
-
writable: true
|
|
26
|
-
},
|
|
27
|
-
subscribed: {
|
|
28
|
-
value: {},
|
|
29
|
-
writable: true
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
static getRequestString(method, params) {
|
|
34
|
-
let reqStr = `${method} ${params.channel}`;
|
|
35
|
-
reqStr += params.args ? ` ${params.args}` : "";
|
|
36
|
-
reqStr += params.id ? ` ${params.id}` : "";
|
|
37
|
-
return reqStr.trim();
|
|
38
|
-
}
|
|
39
|
-
connect(url, onOpen = () => {
|
|
40
|
-
}) {
|
|
41
|
-
if (this.websocket && !this.closed) {
|
|
42
|
-
this.websocket.close();
|
|
43
|
-
}
|
|
44
|
-
this.websocket = new WebSocket(url);
|
|
45
|
-
if (!this.open) {
|
|
46
|
-
this.websocket.addEventListener("open", () => {
|
|
47
|
-
onOpen();
|
|
48
|
-
this.subscribePreviousSubscriptions();
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
onOpen();
|
|
52
|
-
this.subscribePreviousSubscriptions();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
close() {
|
|
56
|
-
if (this.websocket) {
|
|
57
|
-
this.websocket.onclose = null;
|
|
58
|
-
this.websocket.close();
|
|
59
|
-
this.websocket = null;
|
|
60
|
-
this.messagesOnOpen = [];
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
61
8
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/**
|
|
13
|
+
* Class used to facilitate connection to a WebSocket and
|
|
14
|
+
* also to manage properly messages send to the WebSocket.
|
|
15
|
+
* This class must not contain any specific implementation.
|
|
16
|
+
*/
|
|
17
|
+
var WebSocketAPI = /** @class */ (function () {
|
|
18
|
+
function WebSocketAPI() {
|
|
19
|
+
this.defineProperties();
|
|
66
20
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
21
|
+
WebSocketAPI.prototype.defineProperties = function () {
|
|
22
|
+
var _this = this;
|
|
23
|
+
Object.defineProperties(this, {
|
|
24
|
+
closed: {
|
|
25
|
+
get: function () {
|
|
26
|
+
return !!(_this.websocket &&
|
|
27
|
+
_this.websocket.readyState === _this.websocket.CLOSED);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
closing: {
|
|
31
|
+
get: function () {
|
|
32
|
+
return !!(_this.websocket &&
|
|
33
|
+
_this.websocket.readyState === _this.websocket.CLOSING);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
connecting: {
|
|
37
|
+
get: function () {
|
|
38
|
+
return !!(_this.websocket &&
|
|
39
|
+
_this.websocket.readyState === _this.websocket.CONNECTING);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
open: {
|
|
43
|
+
get: function () {
|
|
44
|
+
return !!(_this.websocket && _this.websocket.readyState === _this.websocket.OPEN);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Array of message to send on open.
|
|
49
|
+
* @type {Array<string>}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
messagesOnOpen: {
|
|
53
|
+
value: [],
|
|
54
|
+
writable: true,
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Array of subscriptions.
|
|
58
|
+
* @type {Array<subscription>}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
subscriptions: {
|
|
62
|
+
value: [],
|
|
63
|
+
writable: true,
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* List of channels subscribed.
|
|
67
|
+
* @type {Array<subscription>}
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
subscribed: {
|
|
71
|
+
value: {},
|
|
72
|
+
writable: true,
|
|
73
|
+
},
|
|
79
74
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Get the websocket request string.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} method Request mehtod {GET, SUB}.
|
|
80
|
+
* @param {Object} params Request parameters.
|
|
81
|
+
* @param {string} params.channel Channel name
|
|
82
|
+
* @param {string} [params.args] Request arguments
|
|
83
|
+
* @param {Number} [params.id] Request identifier
|
|
84
|
+
* @return {string} request string
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
WebSocketAPI.getRequestString = function (method, params) {
|
|
88
|
+
var reqStr = "".concat(method, " ").concat(params.channel);
|
|
89
|
+
reqStr += params.args ? " ".concat(params.args) : '';
|
|
90
|
+
reqStr += params.id ? " ".concat(params.id) : '';
|
|
91
|
+
return reqStr.trim();
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* (Re)connect the websocket.
|
|
95
|
+
*
|
|
96
|
+
* @param {strin} url Websocket url.
|
|
97
|
+
* @param {function} onOpen Callback called when the websocket connection is opened and before subscriptions of previous subscriptions.
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
WebSocketAPI.prototype.connect = function (url, onOpen) {
|
|
101
|
+
var _this = this;
|
|
102
|
+
if (onOpen === void 0) { onOpen = function () { }; }
|
|
103
|
+
if (this.websocket && !this.closed) {
|
|
104
|
+
this.websocket.close();
|
|
105
|
+
}
|
|
106
|
+
/** @ignore */
|
|
107
|
+
this.websocket = new WebSocket(url);
|
|
108
|
+
if (!this.open) {
|
|
109
|
+
this.websocket.addEventListener('open', function () {
|
|
110
|
+
onOpen();
|
|
111
|
+
_this.subscribePreviousSubscriptions();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
onOpen();
|
|
116
|
+
this.subscribePreviousSubscriptions();
|
|
100
117
|
}
|
|
101
|
-
});
|
|
102
118
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this.subscriptions.filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb)).forEach(({ onMessageCb, onErrorCb }) => {
|
|
117
|
-
if (this.websocket) {
|
|
118
|
-
this.websocket.removeEventListener("message", onMessageCb);
|
|
119
|
-
if (onErrorCb) {
|
|
120
|
-
this.websocket.removeEventListener("error", onErrorCb);
|
|
121
|
-
this.websocket.removeEventListener("close", onErrorCb);
|
|
119
|
+
/**
|
|
120
|
+
* Close the websocket definitively.
|
|
121
|
+
*
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
WebSocketAPI.prototype.close = function () {
|
|
125
|
+
if (this.websocket) {
|
|
126
|
+
this.websocket.onclose = null;
|
|
127
|
+
this.websocket.close();
|
|
128
|
+
this.websocket = null;
|
|
129
|
+
this.messagesOnOpen = [];
|
|
122
130
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const index = this.subscriptions.findIndex((subcr) => params.channel === subcr.params.channel && cb === subcr.cb);
|
|
135
|
-
const newSubscr = { params, cb, errorCb, onMessageCb, onErrorCb, quiet };
|
|
136
|
-
if (index > -1) {
|
|
137
|
-
this.subscriptions[index] = newSubscr;
|
|
138
|
-
} else {
|
|
139
|
-
this.subscriptions.push(newSubscr);
|
|
140
|
-
}
|
|
141
|
-
if (!this.subscribed[reqStr]) {
|
|
142
|
-
if (!newSubscr.quiet) {
|
|
143
|
-
this.send(`GET ${reqStr}`);
|
|
144
|
-
this.send(`SUB ${reqStr}`);
|
|
145
|
-
}
|
|
146
|
-
this.subscribed[reqStr] = true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
unsubscribe(source, cb) {
|
|
150
|
-
const toRemove = this.subscriptions.filter((s) => s.params.channel === source && (!cb || s.cb === cb));
|
|
151
|
-
toRemove.forEach(({ onMessageCb, onErrorCb }) => {
|
|
152
|
-
if (this.websocket) {
|
|
153
|
-
this.websocket.removeEventListener("message", onMessageCb);
|
|
154
|
-
if (onErrorCb) {
|
|
155
|
-
this.websocket.removeEventListener("error", onErrorCb);
|
|
156
|
-
this.websocket.removeEventListener("close", onErrorCb);
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Sends a message to the websocket.
|
|
134
|
+
*
|
|
135
|
+
* @param {message} message Message to send.
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
138
|
+
WebSocketAPI.prototype.send = function (message) {
|
|
139
|
+
var _this = this;
|
|
140
|
+
if (!this.websocket) {
|
|
141
|
+
return;
|
|
157
142
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
143
|
+
var send = function () {
|
|
144
|
+
_this.websocket.send(message);
|
|
145
|
+
};
|
|
146
|
+
if (!this.open) {
|
|
147
|
+
// This 'if' avoid sending 2 identical BBOX message on open,
|
|
148
|
+
if (!this.messagesOnOpen.includes(message)) {
|
|
149
|
+
this.messagesOnOpen.push(message);
|
|
150
|
+
this.websocket.addEventListener('open', function () {
|
|
151
|
+
_this.messagesOnOpen = [];
|
|
152
|
+
send();
|
|
153
|
+
});
|
|
154
|
+
this.websocket.addEventListener('close', function () {
|
|
155
|
+
_this.messagesOnOpen = [];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (!this.messagesOnOpen.includes(message)) {
|
|
160
|
+
send();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Listen to websocket messages.
|
|
165
|
+
*
|
|
166
|
+
* @param {Object} params Parameters for the websocket get request
|
|
167
|
+
* @param {function} cb callback on listen
|
|
168
|
+
* @param {function} errorCb Callback on error
|
|
169
|
+
* @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
WebSocketAPI.prototype.listen = function (params, cb, errorCb) {
|
|
173
|
+
// Remove the previous identical callback
|
|
174
|
+
this.unlisten(params, cb);
|
|
175
|
+
var onMessage = function (evt) {
|
|
176
|
+
var data = {};
|
|
177
|
+
try {
|
|
178
|
+
data = JSON.parse(evt.data);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
// eslint-disable-next-line no-console
|
|
182
|
+
console.error('WebSocket: unable to parse JSON data', err, evt.data);
|
|
183
|
+
}
|
|
184
|
+
var source = params.channel;
|
|
185
|
+
source += params.args ? " ".concat(params.args) : '';
|
|
186
|
+
// Buffer channel message return a list of other channels to propagate to proper callbacks.
|
|
187
|
+
var contents = data.source === 'buffer' ? data.content : [data];
|
|
188
|
+
contents.forEach(function (content) {
|
|
189
|
+
// Because of backend optimization, the last content is null.
|
|
190
|
+
if ((content === null || content === void 0 ? void 0 : content.source) === source &&
|
|
191
|
+
(!params.id || params.id === data.client_reference)) {
|
|
192
|
+
cb(content);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
if (this.websocket) {
|
|
197
|
+
this.websocket.addEventListener('message', onMessage);
|
|
198
|
+
if (errorCb) {
|
|
199
|
+
this.websocket.addEventListener('error', errorCb);
|
|
200
|
+
this.websocket.addEventListener('close', errorCb);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { onMessageCb: onMessage, onErrorCb: errorCb };
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Unlisten websocket messages.
|
|
207
|
+
*
|
|
208
|
+
* @param {Object} params Parameters for the websocket get request.
|
|
209
|
+
* @param {function} cb Callback used when listen.
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
WebSocketAPI.prototype.unlisten = function (params, cb) {
|
|
213
|
+
var _this = this;
|
|
214
|
+
if (!this.websocket) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this.subscriptions
|
|
218
|
+
.filter(function (s) { return s.params.channel === params.channel && (!cb || s.cb === cb); })
|
|
219
|
+
.forEach(function (_a) {
|
|
220
|
+
var onMessageCb = _a.onMessageCb, onErrorCb = _a.onErrorCb;
|
|
221
|
+
if (_this.websocket) {
|
|
222
|
+
_this.websocket.removeEventListener('message', onMessageCb);
|
|
223
|
+
if (onErrorCb) {
|
|
224
|
+
_this.websocket.removeEventListener('error', onErrorCb);
|
|
225
|
+
_this.websocket.removeEventListener('close', onErrorCb);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Sends a get request to the websocket.
|
|
232
|
+
*
|
|
233
|
+
* @param {Object} params Parameters for the websocket get request
|
|
234
|
+
* @param {function} cb callback on listen
|
|
235
|
+
* @param {function} errorCb Callback on error
|
|
236
|
+
* @private
|
|
237
|
+
*/
|
|
238
|
+
WebSocketAPI.prototype.get = function (params, cb, errorCb) {
|
|
239
|
+
var reqStr = WebSocketAPI.getRequestString('GET', params);
|
|
240
|
+
this.send(reqStr);
|
|
241
|
+
this.listen(params, cb, errorCb);
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Subscribe to a given channel.
|
|
245
|
+
*
|
|
246
|
+
* @param {Object} params Parameters for the websocket get request
|
|
247
|
+
* @param {function} cb callback on listen
|
|
248
|
+
* @param {function} errorCb Callback on error
|
|
249
|
+
* @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
WebSocketAPI.prototype.subscribe = function (params, cb, errorCb, quiet) {
|
|
253
|
+
if (quiet === void 0) { quiet = false; }
|
|
254
|
+
var _a = this.listen(params, cb, errorCb), onMessageCb = _a.onMessageCb, onErrorCb = _a.onErrorCb;
|
|
255
|
+
var reqStr = WebSocketAPI.getRequestString('', params);
|
|
256
|
+
var index = this.subscriptions.findIndex(function (subcr) { return params.channel === subcr.params.channel && cb === subcr.cb; });
|
|
257
|
+
var newSubscr = { params: params, cb: cb, errorCb: errorCb, onMessageCb: onMessageCb, onErrorCb: onErrorCb, quiet: quiet };
|
|
258
|
+
if (index > -1) {
|
|
259
|
+
this.subscriptions[index] = newSubscr;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
this.subscriptions.push(newSubscr);
|
|
263
|
+
}
|
|
264
|
+
if (!this.subscribed[reqStr]) {
|
|
265
|
+
if (!newSubscr.quiet) {
|
|
266
|
+
this.send("GET ".concat(reqStr));
|
|
267
|
+
this.send("SUB ".concat(reqStr));
|
|
268
|
+
}
|
|
269
|
+
this.subscribed[reqStr] = true;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Unsubscribe from a channel.
|
|
274
|
+
* @param {string} source source to unsubscribe from
|
|
275
|
+
* @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
WebSocketAPI.prototype.unsubscribe = function (source, cb) {
|
|
279
|
+
var _this = this;
|
|
280
|
+
var toRemove = this.subscriptions.filter(function (s) { return s.params.channel === source && (!cb || s.cb === cb); });
|
|
281
|
+
toRemove.forEach(function (_a) {
|
|
282
|
+
var onMessageCb = _a.onMessageCb, onErrorCb = _a.onErrorCb;
|
|
283
|
+
if (_this.websocket) {
|
|
284
|
+
_this.websocket.removeEventListener('message', onMessageCb);
|
|
285
|
+
if (onErrorCb) {
|
|
286
|
+
_this.websocket.removeEventListener('error', onErrorCb);
|
|
287
|
+
_this.websocket.removeEventListener('close', onErrorCb);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
this.subscriptions = this.subscriptions.filter(function (s) { return s.params.channel !== source || (cb && s.cb !== cb); });
|
|
292
|
+
// If there is no more subscriptions to this channel, and the removed subscriptions didn't register quietly,
|
|
293
|
+
// we DEL it.
|
|
294
|
+
if (source &&
|
|
295
|
+
this.subscribed[source] &&
|
|
296
|
+
!this.subscriptions.find(function (s) { return s.params.channel === source; }) &&
|
|
297
|
+
toRemove.find(function (subscr) { return !subscr.quiet; })) {
|
|
298
|
+
this.send("DEL ".concat(source));
|
|
299
|
+
this.subscribed[source] = false;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* After an auto reconnection we need to re-subscribe to the channels.
|
|
304
|
+
*/
|
|
305
|
+
WebSocketAPI.prototype.subscribePreviousSubscriptions = function () {
|
|
306
|
+
var _this = this;
|
|
307
|
+
// Before to subscribe previous subscriptions we make sure they
|
|
308
|
+
// are all defined as unsubscribed, because this code is asynchrone
|
|
309
|
+
// and a subscription could have been added in between.
|
|
310
|
+
Object.keys(this.subscribed).forEach(function (key) {
|
|
311
|
+
_this.subscribed[key] = false;
|
|
312
|
+
});
|
|
313
|
+
// Subscribe all previous subscriptions.
|
|
314
|
+
__spreadArray([], this.subscriptions, true).forEach(function (s) {
|
|
315
|
+
_this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
return WebSocketAPI;
|
|
319
|
+
}());
|
|
320
|
+
exports.default = WebSocketAPI;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export default Control;
|
|
2
|
+
/**
|
|
3
|
+
* A class representing a control to display on map.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const control = new Control();
|
|
7
|
+
*
|
|
8
|
+
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map which the control refers to.
|
|
9
|
+
* @classproperty {boolean} active - Active the control.
|
|
10
|
+
* @classproperty {HTMLElement} element - The HTML element used to render the control.
|
|
11
|
+
* @classproperty {HTMLElement} target - The HTML element where to render the element property. Default is the map's element. Read only.
|
|
12
|
+
*/
|
|
13
|
+
declare class Control extends BaseObject {
|
|
14
|
+
/**
|
|
15
|
+
* Constructor
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} [options] Control options.
|
|
18
|
+
* @param {boolean} [options.active = true] Whether the control is active or not.
|
|
19
|
+
* @param {HTMLElement} [options.element] The HTML element used to render the control.
|
|
20
|
+
* @param {HTMLElement} [options.target] The HTML element where to render the element property. Default is the map's element.
|
|
21
|
+
* @param {function} [options.render] Render function called whenever the control needs to be rerendered.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: {
|
|
24
|
+
active?: boolean;
|
|
25
|
+
element?: HTMLElement;
|
|
26
|
+
target?: HTMLElement;
|
|
27
|
+
render?: Function;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* @ignore
|
|
31
|
+
*/
|
|
32
|
+
active: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Define control's properties.
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
private defineProperties;
|
|
39
|
+
/**
|
|
40
|
+
* Attach the control to the map. Add events, html element ...
|
|
41
|
+
*/
|
|
42
|
+
attachToMap(map: any): void;
|
|
43
|
+
map: any;
|
|
44
|
+
/**
|
|
45
|
+
* Detach the control From the map. Remove events, html element ..
|
|
46
|
+
*/
|
|
47
|
+
detachFromMap(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Add listeners then renders the control.
|
|
50
|
+
* To be defined in inherited classes.
|
|
51
|
+
*/
|
|
52
|
+
activate(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Remove listeners added by activate() function then renders the control.
|
|
55
|
+
* To be defined in inherited classes.
|
|
56
|
+
*/
|
|
57
|
+
deactivate(): void;
|
|
58
|
+
/**
|
|
59
|
+
* The default render function. It renders content in the HTML element.
|
|
60
|
+
* To be defined in inherited classes.
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private render;
|
|
65
|
+
/**
|
|
66
|
+
* The default element to display if this.element is not defined.
|
|
67
|
+
* To be defined in inherited classes.
|
|
68
|
+
*
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private createDefaultElement;
|
|
72
|
+
}
|
|
73
|
+
import BaseObject from "ol/Object";
|
|
74
|
+
//# sourceMappingURL=Control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Control.d.ts","sourceRoot":"","sources":["../../../src/common/controls/Control.js"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AACH;IACE;;;;;;;;OAQG;IACH;QAL6B,MAAM,GAAxB,OAAO;QACe,OAAO,GAA7B,WAAW;QACW,MAAM,GAA5B,WAAW;QACQ,MAAM;OAenC;IAJC;;OAEG;IACH,gBAAoB;IAGtB;;;;OAIG;IACH,yBAmEC;IAED;;OAEG;IACH,4BAEC;IADC,SAAc;IAGhB;;OAEG;IACH,sBAEC;IAED;;;OAGG;IACH,iBAEC;IAED;;;OAGG;IAEH,mBAAe;IAEf;;;;;OAKG;IACH,eAAW;IAEX;;;;;OAKG;IAEH,6BAAyB;CAC1B"}
|