mobility-toolbox-js 1.7.8-beta.3 → 1.7.8-beta.6
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/tralis/TralisAPI.js
CHANGED
|
@@ -77,7 +77,7 @@ class TralisAPI {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const { apiKey } = opt;
|
|
80
|
-
let { url, projection, bbox } = opt;
|
|
80
|
+
let { url, projection, bbox, buffer = [100, 100] } = opt;
|
|
81
81
|
const conn = new WebSocketConnector();
|
|
82
82
|
|
|
83
83
|
if (apiKey) {
|
|
@@ -114,6 +114,17 @@ class TralisAPI {
|
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
|
+
buffer: {
|
|
118
|
+
get: () => buffer,
|
|
119
|
+
set: (newBuffer) => {
|
|
120
|
+
if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
|
|
121
|
+
buffer = newBuffer;
|
|
122
|
+
if (this.conn) {
|
|
123
|
+
this.conn.send(`BUFFER ${buffer.join(' ')}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
},
|
|
117
128
|
/**
|
|
118
129
|
* The websocket helper class to connect the websocket.
|
|
119
130
|
*
|
|
@@ -178,10 +189,15 @@ class TralisAPI {
|
|
|
178
189
|
if (this.projection) {
|
|
179
190
|
this.conn.send(`PROJECTION ${this.projection}`);
|
|
180
191
|
}
|
|
192
|
+
|
|
181
193
|
if (this.bbox) {
|
|
182
194
|
this.conn.send(`BBOX ${this.bbox.join(' ')}`);
|
|
183
195
|
}
|
|
184
196
|
|
|
197
|
+
if (this.buffer) {
|
|
198
|
+
this.conn.send(`BUFFER ${this.buffer.join(' ')}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
185
201
|
/**
|
|
186
202
|
* Keep websocket alive
|
|
187
203
|
*/
|
|
@@ -172,16 +172,27 @@ class WebSocketConnector {
|
|
|
172
172
|
this.unlisten(params, cb);
|
|
173
173
|
|
|
174
174
|
const onMessage = (evt) => {
|
|
175
|
-
|
|
175
|
+
let data = {};
|
|
176
|
+
try {
|
|
177
|
+
data = JSON.parse(evt.data);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
// eslint-disable-next-line no-console
|
|
180
|
+
console.error('WebSocket: unable to parse JSON data', err, evt.data);
|
|
181
|
+
}
|
|
176
182
|
let source = params.channel;
|
|
177
183
|
source += params.args ? ` ${params.args}` : '';
|
|
178
184
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
// Buffer channel message return a list of other channels to propagate to proper callbacks.
|
|
186
|
+
const contents = data.source === 'buffer' ? data.content : [data];
|
|
187
|
+
contents.forEach((content) => {
|
|
188
|
+
// Because of backend optimization, the last content is null.
|
|
189
|
+
if (
|
|
190
|
+
content?.source === source &&
|
|
191
|
+
(!params.id || params.id === data.client_reference)
|
|
192
|
+
) {
|
|
193
|
+
cb(content);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
185
196
|
};
|
|
186
197
|
|
|
187
198
|
if (this.websocket) {
|