From 76a7b02dc77e4318ee1350ca6ed4b9cb578eaa71 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 12 Oct 2015 13:06:20 +0200 Subject: [PATCH] fixes for last commit --- src/doodle3dapi.js | 47 +++++++++++++++++++--------------------------- src/networkapi.js | 2 +- src/printerapi.js | 7 ++++--- src/restapi.js | 7 +++++-- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/doodle3dapi.js b/src/doodle3dapi.js index 343e24f..ac59b0f 100644 --- a/src/doodle3dapi.js +++ b/src/doodle3dapi.js @@ -16,14 +16,6 @@ export default class extends EventDispatcher { this.boxData = boxData; this.api = `http://${boxData.localip}/d3dapi/`; - - this.config = new ConfigAPI(this.api); - this.info = new InfoAPI(this.api); - this.network = new NetworkAPI(this.api); - this.printer = new PrinterAPI(this.api); - this.sketch = new SketchAPI(this.api); - this.system = new SystemAPI(this.api); - this.update = new UpdateAPI(this.api); this.alive = false; this.autoUpdate = false; @@ -32,6 +24,14 @@ export default class extends EventDispatcher { this.maxBatchSize = 10*1024; this.maxBufferSize = 1024*1024; this.fullBufferTimeout = 10000; + + this.config = new ConfigAPI(this.api); + this.info = new InfoAPI(this.api); + this.network = new NetworkAPI(this.api); + this.printer = new PrinterAPI(this.api); + this.sketch = new SketchAPI(this.api); + this.system = new SystemAPI(this.api); + this.update = new UpdateAPI(this.api); } setAutoUpdate (autoUpdate = true, updateInterval = 1000) { @@ -111,29 +111,20 @@ export default class extends EventDispatcher { } async _update () { - let alive = await this.checkAlive(); - if (alive) { - while (this.autoUpdate) { - try { - this.state = await this.info.status(); + while (this.autoUpdate) { + try { + this.state = await this.info.status(); - this.dispatchEvent({ - type: 'update', - state: this.state - }); - - await sleep(this.updateInterval); - } - catch (error) { - this._update(); - break; - } + this.dispatchEvent({ + type: 'update', + state: this.state + }); + } + catch (error) { + await this.checkAlive(); } - } - else { - await sleep(this.updateInterval); - this._update(); + await sleep(this.updateInterval); } } diff --git a/src/networkapi.js b/src/networkapi.js index 1f3bd59..222308d 100644 --- a/src/networkapi.js +++ b/src/networkapi.js @@ -27,7 +27,7 @@ export default class { return rest.post(`${this.api}network/associate`, data); } - disassosiate () { + disassociate () { //not tested return rest.post(`${this.api}network/disassociate`, {}); diff --git a/src/printerapi.js b/src/printerapi.js index ef649a8..4fb8cca 100644 --- a/src/printerapi.js +++ b/src/printerapi.js @@ -37,9 +37,10 @@ export default class { } stop (gcode = '') { - this._currentBatch = 0; - this._printBatches = []; + let data = { + gcode + }; - return rest.post(`${this.api}printer/stop`, {gcode}); + return rest.post(`${this.api}printer/stop`, data); } } diff --git a/src/restapi.js b/src/restapi.js index 32371f7..2a8d84f 100644 --- a/src/restapi.js +++ b/src/restapi.js @@ -1,11 +1,14 @@ import $ from 'jquery'; +const GET_TIMEOUT = 5000; +const POST_TIMEOUT = 10000; + export function get (url) { return new Promise((resolve, reject) => { $.ajax({ url: url, dataType: 'json', - timeout: 5000, + timeout: GET_TIMEOUT, success: (response) => { if (response.status === 'success') { resolve(response.data, response.msg); @@ -25,7 +28,7 @@ export function post (url, data) { type: 'POST', data: data, dataType: 'json', - timeout: 10000, + timeout: POST_TIMEOUT, success: (response) => { if (response.status === 'success') { resolve(response.data);