0
0
mirror of https://github.com/Doodle3D/Doodle3D-API synced 2024-11-05 04:33:24 +01:00

fixes for last commit

This commit is contained in:
casperlamboo 2015-10-12 13:06:20 +02:00
parent c831a7cc02
commit 76a7b02dc7
4 changed files with 29 additions and 34 deletions

View File

@ -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);
}
}

View File

@ -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`, {});

View File

@ -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);
}
}

View File

@ -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);