(params: { [key: string]: any; }[], seq: number)
| 277 | } |
| 278 | |
| 279 | _send(params: { [key: string]: any; }[], seq: number): Promise<void> { |
| 280 | if (this.closed()) { |
| 281 | this.sender.stop(); |
| 282 | error_alert(t("disconnected_with_server")); |
| 283 | return Promise.reject(); |
| 284 | } |
| 285 | let data: any, ajax_options: any; |
| 286 | let json = params.some(p => p.json); |
| 287 | if (json) { |
| 288 | data = JSON.stringify(params.map(p => p.data)); |
| 289 | ajax_options = { |
| 290 | contentType: "application/json; charset=utf-8", |
| 291 | } |
| 292 | } else { |
| 293 | data = params[0].data; |
| 294 | ajax_options = { |
| 295 | cache: false, |
| 296 | processData: false, |
| 297 | contentType: 'application/octet-stream', |
| 298 | } |
| 299 | } |
| 300 | return new Promise((resolve, reject) => { |
| 301 | $.ajax({ |
| 302 | data: data, |
| 303 | ...ajax_options, |
| 304 | type: "POST", |
| 305 | url: `${this.api_url}&ack=${this._executed_command_msg_id}&seq=${seq}`, |
| 306 | dataType: "json", |
| 307 | headers: {"webio-session-id": this.webio_session_id}, |
| 308 | success: this._on_request_success.bind(this), |
| 309 | xhr: function () { |
| 310 | let xhr = new window.XMLHttpRequest(); |
| 311 | // Upload progress |
| 312 | xhr.upload.addEventListener("progress", function (evt) { |
| 313 | if (evt.lengthComputable) { |
| 314 | params.forEach(p => { |
| 315 | if (p.onprogress) // only the first one |
| 316 | p.onprogress(evt.loaded, evt.total); |
| 317 | p.onprogress = null; |
| 318 | }); |
| 319 | } |
| 320 | }, false); |
| 321 | return xhr; |
| 322 | }, |
| 323 | error: function () { |
| 324 | console.error('Http push event failed, will retry'); |
| 325 | } |
| 326 | }).always(() => resolve()); |
| 327 | }); |
| 328 | } |
| 329 | |
| 330 | close_session(): void { |
| 331 | this._closed = true; |
nothing calls this directly
no test coverage detected