test with new websocket implementation

This commit is contained in:
Stefan Dej committed 2020-04-25 21:17:27 +02:00
1 parent 544d5e2db5
commit efc70ca5aa
20 files changed
+332 -256

No files matched your search

+18 -14
View File
@@ -12321,11 +12321,6 @@
"integrity": "sha512-BXq3jwIagosjgNVae6tkHzzIk6a8MHFtzAdwhnV5VlvPTFxDCvIttgSiHWjdGoTJvXtmRu5HacExfdarRcFhog==",
"dev": true
},
"vue-json-rpc-websocket": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/vue-json-rpc-websocket/-/vue-json-rpc-websocket-1.1.1.tgz",
"integrity": "sha512-uyIVLpToFnLcPLgTSb6hEvvtrgwyD8hAkozPfpRT1E3c8Fzs3XQjvTOLkbO2DkUYBXQzIAS1uH5GSuy3YL9v8Q=="
},
"vue-loader": {
"version": "15.9.1",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.1.tgz",
@@ -12545,6 +12540,15 @@
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz",
"integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==",
"dev": true
},
"ws": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"dev": true,
"requires": {
"async-limiter": "~1.0.0"
}
}
}
},
@@ -12751,6 +12755,15 @@
}
}
},
"ws": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"dev": true,
"requires": {
"async-limiter": "~1.0.0"
}
},
"yargs": {
"version": "12.0.5",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz",
@@ -12958,15 +12971,6 @@
"mkdirp": "^0.5.1"
}
},
"ws": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"dev": true,
"requires": {
"async-limiter": "~1.0.0"
}
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
-1
View File
@@ -16,7 +16,6 @@
"vue-chartjs": "^3.5.0",
"vue-context": "^5.1.0",
"vue-headful": "^2.1.0",
"vue-json-rpc-websocket": "^1.1.1",
"vue-resource": "^1.5.1",
"vue-simple-upload": "^0.1.6",
"vue-toast-notification": "^0.2.0",
+2 -2
View File
@@ -1,7 +1,7 @@
{
"socket": {
"hostname": "voron250.local",
"reconnectInterval": 5000,
"reconnectAttempts": 1000
"port": 8080,
"reconnectInterval": 3000
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

+4 -5
View File
@@ -66,7 +66,7 @@
<v-footer app class="d-block">
<span v-if="version">{{ version }}</span>
<span class="float-right">Made with <img src="/img/heard.svg" height="10" /> by <img src="/img/voron.png" height="10" />. &copy; 2020</span>
<span class="float-right">Made with <img src="/img/heard.png" height="15" title="love" alt="heard" /> by <a href="http://www.vorondesign.com/" target="_blank"><img src="/img/voron.png" height="15" title="VoronDesign" alt="Logo - VoronDesign" /></a></span>
</v-footer>
</v-app>
</template>
@@ -89,9 +89,8 @@ export default {
}),
created () {
this.$vuetify.theme.dark = true;
this.$socket.onOpen = () => {
}
window.console.log('app created');
this.$webSocketsConnect();
},
computed: {
currentPage: function() {
@@ -114,7 +113,7 @@ export default {
methods: {
emergencyStop: function() {
this.$store.commit('setLoadingEmergencyStop', true);
this.$socket.sendObj('post_printer_gcode', {script: 'M112'}, 'setLoadingEmergencyStop');
//this.$socket.sendObj('post_printer_gcode', {script: 'M112'}, 'setLoadingEmergencyStop');
},
drawFavicon(val) {
let favicon = document.getElementById('favicon');
+20 -15
View File
@@ -6,7 +6,7 @@
<v-card>
<v-row class="">
<v-col class="col-12 pb-0 text-center">
<div class="d-inline-block mx-2 my-1"><v-btn @click="doHome" :loading="loadingHome" :color="homedAxes.includes('xyz') ? 'primary' : 'warning'" class=""><v-icon class="mr-1">mdi-home</v-icon><span class="d-none d-sm-inline">Home </span>all</v-btn></div>
<div class="d-inline-block mx-2 my-1"><v-btn @click="doHome" :loading="loadingHomeAll" :color="homedAxes.includes('xyz') ? 'primary' : 'warning'" class=""><v-icon class="mr-1">mdi-home</v-icon><span class="d-none d-sm-inline">Home </span>all</v-btn></div>
<div class="d-inline-block mx-2 my-1" v-if="config.hasOwnProperty('quad_gantry_level')"><v-btn @click="doQGL" :loading="loadingQGL" color="primary">QGL</v-btn></div>
</v-col>
</v-row>
@@ -61,6 +61,7 @@
<script>
import { mapState, mapGetters, mapMutations } from 'vuex'
import Vue from "vue";
export default {
components: {
@@ -68,24 +69,20 @@
},
data: function() {
return {
loadingHomeAll: false,
loadingHomeX: false,
loadingHomeY: false,
loadingHomeZ: false,
}
},
computed: {
...mapState({
loadingHome: state => state.socket.loadingHome,
loadingHomeX: state => state.socket.loadingHomeX,
loadingHomeY: state => state.socket.loadingHomeY,
loadingHomeZ: state => state.socket.loadingHomeZ,
loadingQGL: state => state.socket.loadingQGL,
homedAxes: state => state.printer.toolhead.homed_axes,
config: state => state.config,
loadings: state => state.loadings,
}),
...mapMutations([
'setLoadingHome',
'setLoadingHomeX',
'setLoadingHomeY',
'setLoadingHomeZ',
'setLoadingQGL',
]),
...mapGetters([
@@ -94,19 +91,19 @@
},
methods: {
doHome() {
this.$store.commit('setLoadingHome', true);
this.$store.commit('setLoading', { name: 'controlHomeAll' });
this.$socket.sendObj('post_printer_gcode', { script: "G28" }, "responseHome");
},
doHomeX() {
this.$store.commit('setLoadingHomeX', true);
this.$store.commit('setLoading', { name: 'controlHomeX' });
this.$socket.sendObj('post_printer_gcode', { script: "G28 X" }, "responseHomeX");
},
doHomeY() {
this.$store.commit('setLoadingHomeY', true);
this.$store.commit('setLoading', { name: 'controlHomeY' });
this.$socket.sendObj('post_printer_gcode', { script: "G28 Y" }, "responseHomeY");
},
doHomeZ() {
this.$store.commit('setLoadingHomeZ', true);
this.$store.commit('setLoading', { name: 'controlHomeZ' });
this.$socket.sendObj('post_printer_gcode', { script: "G28 Z" }, "responseHomeZ");
},
doQGL() {
@@ -121,8 +118,16 @@
this.doSend(gcode);
},
doSend(gcode) {
this.$socket.sendObj('post_printer_gcode', { script: gcode }, "sendGcode");
Vue.prototype.$webSocketsSendObj('post_printer_gcode', { script: gcode }, "sendGcode");
},
},
watch: {
loadings: function(loadings) {
this.loadingHomeAll = loadings.includes('controlHomeAll');
this.loadingHomeX = loadings.includes('controlHomeX');
this.loadingHomeY = loadings.includes('controlHomeY');
this.loadingHomeZ = loadings.includes('controlHomeZ');
}
}
}
</script>
@@ -11,6 +11,8 @@
<div><v-btn :href="'http://'+hostname+':'+port+'/printer/log'" color="primary"><v-icon class="mr-sm-2">mdi-download</v-icon>Download Log</v-btn></div>
<div><v-btn @click="doRestart" :loading="loadingRestart" color="error" class="mt-3"><v-icon class="mr-sm-2">mdi-cached</v-icon>Restart</v-btn></div>
<div><v-btn @click="doRestartFirmware" :loading="loadingRestartFirmware" class="mt-3" color="error"><v-icon class="mr-sm-2">mdi-cached</v-icon><span class="d-none d-sm-block">FW Restart</span></v-btn></div>
<div><v-btn @click="doRebootHost" :loading="loadingRebootHost" class="mt-3" color="error"><v-icon class="mr-sm-2">mdi-cached</v-icon><span class="d-none d-sm-block">Host Restart</span></v-btn></div>
<div><v-btn @click="doShutdownHost" :loading="loadingShutdownHost" class="mt-3" color="error"><v-icon class="mr-sm-2">mdi-power</v-icon><span class="d-none d-sm-block">Host Shutdown</span></v-btn></div>
</v-card-text>
</v-card>
</template>
@@ -33,6 +35,8 @@
port: state => state.socket.port,
loadingRestart: state => state.socket.loadingRestart,
loadingRestartFirmware: state => state.socket.loadingRestartFirmware,
loadingRebootHost: state => state.socket.loadingRebootHost,
loadingShutdownHost: state => state.socket.loadingShutdownHost,
}),
...mapMutations([
'setLoadingRestart',
@@ -48,6 +52,14 @@
this.$store.commit('setLoadingRestartFirmware', true);
this.$socket.sendObj('post_printer_firmware_restart', { }, "responseRestartFirmware");
},
doRebootHost() {
this.$store.commit('setLoadingRebootHost', true);
this.$socket.sendObj('post_machine_reboot', { });
},
doShutdownHost() {
this.$store.commit('setLoadingShutdownHost', true);
this.$socket.sendObj('post_machine_shutdown', { });
},
}
}
</script>
+4 -4
View File
@@ -43,7 +43,7 @@
<v-flex grow class="equal-width">
<v-layout column>
<v-flex tag="strong">Filament used</v-flex>
<v-flex tag="span">{{ filament_used.toFixed(2) }}mm</v-flex>
<v-flex tag="span">{{ filament_total.toFixed(2) }}mm</v-flex>
</v-layout>
</v-flex>
<v-flex grow class="equal-width">
@@ -73,13 +73,13 @@
<v-flex grow class="equal-width">
<v-layout column>
<v-flex tag="strong">Filament</v-flex>
<v-flex tag="span">{{ filament_used > 0 && current_file_filament_used > 0 ? formatTime(print_time / (filament_used / current_file_filament_used) - print_time) : '--' }}</v-flex>
<v-flex tag="span">{{ (filament_used > 0 && current_file_filament_total > filament_used) ? formatTime(print_time / (filament_used / current_file_filament_total) - print_time) : '--' }}</v-flex>
</v-layout>
</v-flex>
<v-flex grow class="equal-width">
<v-layout column>
<v-flex tag="strong">Slicer</v-flex>
<v-flex tag="span">{{ current_file_estimated_time > print_time ? formatTime(current_file_estimated_time - print_time) : formatTime(0) }}</v-flex>
<v-flex tag="span">{{ current_file_estimated_time > print_time ? formatTime(current_file_estimated_time - print_time) : '--'}}</v-flex>
</v-layout>
</v-flex>
</v-layout>
@@ -132,7 +132,7 @@
'current_file_size',
'current_file_metadata',
'current_file_estimated_time',
'current_file_filament_used',
'current_file_filament_total',
'is_printing',
]),
},
+14 -6
View File
@@ -1,5 +1,6 @@
import Vue from 'vue'
import JRPCWS from './plugins/json-rpc-websocket'
//import WebSocketClient from './plugins/wsClient'
import webSocketService from './services/websocket'
import App from './App.vue'
import vuetify from './plugins/vuetify'
import VueResource from 'vue-resource'
@@ -22,12 +23,19 @@ Vue.component('vue-headful', vueHeadful);
fetch('/config.json').then(res => res.json())
.then(file => {
store.commit('setSettings', file);
Vue.use(JRPCWS, 'ws://' + store.state.socket.hostname + ':' + store.state.socket.port + '/websocket', {
store: store,
reconnectEnabled: true,
reconnectInterval: store.state.socket.reconnectInterval,
reconnectAttempts: store.state.socket.reconnectAttempts,
/*const socketClient = new WebSocketClient('ws://' + store.state.socket.hostname + ':' + store.state.socket.port + '/websocket', {
store: store,
reconnectEnabled: true,
reconnectInterval: store.state.socket.reconnectInterval,
});
socketClient.connect()
Vue.prototype.$socket = socketClient*/
Vue.use(webSocketService, {
store,
url: 'ws://' + store.state.socket.hostname + ':' + store.state.socket.port + '/websocket'
})
new Vue({
vuetify,
+3 -1
View File
@@ -82,6 +82,7 @@
</template>
<script>
import { mapState, mapGetters } from 'vuex';
import Vue from "vue";
export default {
data () {
@@ -131,8 +132,9 @@
},
methods: {
doSend() {
window.console.log('send gcode: '+this.gcode);
this.loadingSendGcode = true;
this.$socket.sendObj('post_printer_gcode', { script: this.gcode }, "sendGcode");
Vue.prototype.$webSocketsSendObj('post_printer_gcode', { script: this.gcode }, "sendGcode");
this.lastCommands.push(this.gcode);
this.gcode = "";
this.lastCommandNumber = null;
-9
View File
@@ -1,9 +0,0 @@
import WebSocketClient from './wsClient'
export default {
install (Vue, url, options) {
const socketClient = new WebSocketClient(url, options)
socketClient.connect()
Vue.prototype.$socket = socketClient
}
}
-122
View File
@@ -1,122 +0,0 @@
export default class WebSocketClient {
constructor (url, options) {
this.instance = null
this.url = url
this.options = options || this.defaultOptions()
if (this.options) {
if (options.reconnectEnabled) {
this.reconnectEnabled = options.reconnectEnabled
if (this.reconnectEnabled) {
this.reconnectInterval = options.reconnectInterval
this.reconnectAttempts = options.recconectAttempts
this.reconnectCount = 1
}
}
if (options.store) {
this.store = options.store
}
}
this.wsData = []
this.onOpen = null
this.onMessage = null
this.onClose = null
this.onError = null
}
createMessage (method, params, id) {
let msg = {
jsonrpc: '2.0', method: method, params: params, id: id
};
return JSON.stringify(msg)
}
defaultOptions () {
return {
reconnectEnabled: false,
reconnectInterval: 0,
recconectAttempts: 0,
store: undefined
}
}
passToStore (eventName, event) {
if (!eventName.startsWith('socket_')) { return }
let method = 'dispatch'
let target = eventName
let msg = event
if (event.data) {
msg = JSON.parse(event.data)
}
this.store[method](target, msg)
}
connect () {
this.instance = new WebSocket(this.url);
this.instance.onopen = () => {
if (this.reconnectEnabled) this.reconnectCount = 1;
if (typeof this.onOpen === 'function') this.onOpen();
if (this.store) this.passToStore('socket_on_open', event);
};
this.instance.onmessage = (msg) => {
let data = JSON.parse(msg.data);
if (typeof this.onMessage === 'function') {
this.onMessage(data)
} else if (this.store) {
if ('error' in data) {
this.passToStore('socket_on_error', data.error)
} else if (this.wsData.filter(item => item.id === data.id).length > 0 &&
this.wsData.filter(item => item.id === data.id)[0].action !== "") {
this.store.dispatch(
this.wsData.filter(item => item.id === data.id)[0].action,
data.result
)
} else this.passToStore('socket_on_message', data)
}
}
this.instance.onclose = (e) => {
if (typeof this.onClose === 'function') {
this.onClose(e)
} else if (this.store) {
this.passToStore('socket_on_close', e)
}
if (!e.wasClean && this.reconnectEnabled) {
this.reconnect()
}
}
this.instance.onerror = (e) => {
if (typeof this.onError === 'function') {
this.onError(e)
} else if (this.store) {
this.passToStore('socket_on_error', e)
}
}
}
reconnect () {
if (this.reconnectCount <= this.reconnectAttempts) {
this.reconnectCount++
delete this.instance
setTimeout(() => {
this.connect()
if (this.store) { this.passToStore('socket_reconnect', this.reconnectCount) }
}, this.reconnectInterval)
} else {
if (this.store) { this.passToStore('socket_reconnect_error', true) }
}
}
sendObj (method, params, action = '') {
let id = Math.floor(Math.random() * 10000) + 1
this.wsData.push({
id: id,
action: action
})
this.instance.send(this.createMessage(method, params, id))
}
}
+96
View File
@@ -0,0 +1,96 @@
export default class WebSocketClient {
constructor (url, options) {
this.instance = null;
this.url = url;
this.reconnectInterval = options.reconnectInterval;
this.store = options.store;
this.wsData = [];
this.timerId = 0;
this.keepAliveTimeout = 1000;
this.onOpen = null;
this.onMessage = null;
this.onClose = null;
this.onError = null;
}
createMessage (method, params, id) {
let msg = {
jsonrpc: '2.0', method: method, params: params, id: id
};
return JSON.stringify(msg)
}
passToStore (eventName, event) {
if (!eventName.startsWith('socket_')) { return }
let method = 'dispatch'
let target = eventName
let msg = event
if (event.data) {
msg = JSON.parse(event.data)
}
this.store[method](target, msg)
}
connect () {
this.instance = new WebSocket(this.url);
this.instance.onopen = () => {
if (this.store) this.passToStore('socket_on_open', event);
this.keepAlive();
};
this.instance.onclose = (e) => {
window.console.log("Websocket Closed, reconnecting in "+this.reconnectInterval+"ms: ", e.reason);
this.passToStore('socket_on_close', e);
this.cancelKeepAlive();
setTimeout(() => {
this.connect();
}, this.reconnectInterval);
};
this.instance.onerror = (err) => {
console.log("Websocket Error: ", err);
this.instance.close();
};
this.instance.onmessage = (msg) => {
let data = JSON.parse(msg.data);
if (this.store) {
if (this.wsData.filter(item => item.id === data.id).length > 0 &&
this.wsData.filter(item => item.id === data.id)[0].action !== "") {
this.store.dispatch(
this.wsData.filter(item => item.id === data.id)[0].action,
data.result
)
} else this.passToStore('socket_on_message', data)
}
};
}
keepAlive() {
window.console.log('keepAlive start');
window.console.log(this.instance);
if (this.instance.readyState === this.instance.OPEN) {
window.console.log('keepAlive send');
this.sendObj('get_printer_info', {}, 'getKlipperInfo');
}
this.timerId = setTimeout(this.keepAlive, this.keepAliveTimeout);
}
cancelKeepAlive() {
if (this.timerId) clearTimeout(this.timerId);
}
sendObj (method, params, action = '') {
let id = Math.floor(Math.random() * 10000) + 1
this.wsData.push({
id: id,
action: action
})
this.instance.send(this.createMessage(method, params, id))
}
}
+6 -6
View File
@@ -41,20 +41,20 @@ const routes = [
{
title: "Settings",
path: '/settings',
redirect: '/settings/interface',
redirect: '/settings/machine',
icon: 'wrench',
component: Settings,
children: [
{
title: 'Interface',
path: '/settings/interface',
component: SettingsInterface
},
{
title: 'Machine',
path: '/settings/machine',
component: SettingsMachine
},
{
title: 'Interface',
path: '/settings/interface',
component: SettingsInterface
},
]
},
+107
View File
@@ -0,0 +1,107 @@
let webSocketsService = {}
webSocketsService.install = function (Vue, options) {
let ws = new WebSocket(options.url)
let reconnectInterval = options.reconnectInterval || 1000
let wsData = [];
let timerId = 0;
Vue.prototype.$webSocketsConnect = () => {
window.console.log('webSocketConnect');
ws = new WebSocket(options.url);
ws.onopen = () => {
window.console.log('onopen');
// Restart reconnect interval
reconnectInterval = options.reconnectInterval || 1000
options.store.dispatch('socket_on_open');
keepAlive();
}
ws.onmessage = (event) => {
// New message from the backend - use JSON.parse(event.data)
handleNotification(event)
}
ws.onclose = (event) => {
cancelKeepAlive();
if (event) {
// Event.code 1000 is our normal close event
if (event.code !== 1000) {
let maxReconnectInterval = options.maxReconnectInterval || 3000
setTimeout(() => {
if (reconnectInterval < maxReconnectInterval) {
// Reconnect interval can't be > x seconds
reconnectInterval += 1000
}
Vue.prototype.$webSocketsConnect()
}, reconnectInterval)
}
}
}
ws.onerror = (error) => {
window.console.log(error);
ws.close()
}
}
Vue.prototype.$webSocketsDisconnect = () => {
window.console.log('disconnect');
// Our custom disconnect event
ws.close()
}
Vue.prototype.$webSocketsSend = (data) => {
ws.send(JSON.stringify(data))
}
Vue.prototype.$webSocketsSendObj = (method, params, action = '') => {
let id = Math.floor(Math.random() * 10000) + 1
wsData.push({
id: id,
action: action
});
ws.send(JSON.stringify({
jsonrpc: '2.0', method: method, params: params, id: id
}))
}
function keepAlive() {
var timeout = 5000;
if (ws.readyState === ws.OPEN) {
Vue.prototype.$webSocketsSendObj('get_printer_info', {}, 'getKlipperInfo');
}
timerId = setTimeout(keepAlive, timeout);
}
function cancelKeepAlive() {
if (timerId) {
clearTimeout(timerId);
}
}
function passToStore (eventName, event) {
if (!eventName.startsWith('socket_')) { return }
let target = eventName
let msg = event
if (event.data) {
msg = JSON.parse(event.data)
}
options.store.dispatch(target, msg)
}
function handleNotification (params) {
let data = JSON.parse(params.data);
if (wsData.filter(item => item.id === data.id).length > 0 &&
wsData.filter(item => item.id === data.id)[0].action !== "") {
options.store.dispatch(
wsData.filter(item => item.id === data.id)[0].action,
data.result
)
} else passToStore('socket_on_message', data)
}
}
export default webSocketsService
+15 -40
View File
@@ -7,7 +7,7 @@ import axios from "axios";
export default {
socket_on_open ({ commit }) {
commit('setConnected');
Vue.prototype.$socket.sendObj('get_printer_status', { }, 'getHelpData');
Vue.prototype.$webSocketsSendObj('get_printer_status', { }, 'getHelpData');
fetch('http://'+store.state.socket.hostname+':'+store.state.socket.port+'/printer/files/gui.json')
.then(res => res.json()).then(file => {
@@ -16,11 +16,11 @@ export default {
window.console.warn('No kwc config file found.');
});
Vue.prototype.$socket.sendObj('get_printer_info', {}, 'getKlipperInfo');
Vue.prototype.$socket.sendObj('get_printer_objects', {}, 'getObjectInfo');
Vue.prototype.$socket.sendObj('get_printer_status', { heater: [] }, 'getObjectInfo');
Vue.prototype.$socket.sendObj('get_printer_status', { configfile: ['config'] }, 'getPrinterConfig');
Vue.prototype.$socket.sendObj('post_printer_subscriptions', {
Vue.prototype.$webSocketsSendObj('get_printer_info', {}, 'getKlipperInfo');
Vue.prototype.$webSocketsSendObj('get_printer_objects', {}, 'getObjectInfo');
Vue.prototype.$webSocketsSendObj('get_printer_status', { heater: [] }, 'getObjectInfo');
Vue.prototype.$webSocketsSendObj('get_printer_status', { configfile: ['config'] }, 'getPrinterConfig');
Vue.prototype.$webSocketsSendObj('post_printer_subscriptions', {
gcode: [],
toolhead: [],
virtual_sdcard: [],
@@ -32,8 +32,8 @@ export default {
idle_timeout: [],
});
Vue.prototype.$socket.sendObj('get_printer_files', {}, 'getFileList');
Vue.prototype.$socket.sendObj('get_printer_gcode_help', {}, 'getHelpList');
Vue.prototype.$webSocketsSendObj('get_printer_files', {}, 'getFileList');
Vue.prototype.$webSocketsSendObj('get_printer_gcode_help', {}, 'getHelpList');
},
socket_on_close ({ commit }, event) {
@@ -46,10 +46,6 @@ export default {
window.console.error('Code: ' + event.code)
},
socket_on_error ({ commit }, data) {
commit('reportError', data);
},
socket_on_message ({ commit, state }, data) {
if (!state.socket.isConnected) commit('setConnected');
switch(data.method) {
@@ -86,30 +82,6 @@ export default {
}
},
socket_reconnect ({ commit }, count) {
commit('setConnected');
window.console.log(count);
Vue.prototype.$socket.sendObj('get_printer_status', { heater: [] }, 'getObjectInfo');
Vue.prototype.$socket.sendObj('get_printer_status', { configfile: ['config'] }, 'getPrinterConfig');
Vue.prototype.$socket.sendObj('post_printer_subscriptions', {
gcode: [],
toolhead: [],
virtual_sdcard: [],
heater: [],
heater_bed: [],
extruder: ["temperature", "target"],
fan: [],
pause_resume: [],
idle_timeout: [],
});
},
socket_reconnect_error ({ commit }) {
commit('setDisconnected');
window.console.error('Socket disconnected')
},
saveGuiSettings({ commit, state }) {
commit('setLoadingSaveGuiConfige', true);
let file = new File([JSON.stringify({ webcam: state.webcam, gui: state.gui })], 'gui.json');
@@ -178,24 +150,27 @@ export default {
},
sendGcode({commit}, data) {
window.console.log('finish');
window.console.log(data);
commit('setLoadingSendGcode', false);
commit('sendGcode', data);
},
responseHome({commit}) {
commit('setLoadingHome', false);
commit('removeLoading', { name: 'controlHomeAll' });
},
responseHomeX({commit}) {
commit('setLoadingHomeX', false);
commit('removeLoading', { name: 'controlHomeX' });
},
responseHomeY({commit}) {
commit('setLoadingHomeY', false);
commit('removeLoading', { name: 'controlHomeY' });
},
responseHomeZ({commit}) {
commit('setLoadingHomeZ', false);
commit('removeLoading', { name: 'controlHomeZ' });
},
responseQGL({commit}) {
+5 -4
View File
@@ -84,10 +84,10 @@ export default {
return 0;
},
current_file_filament_used: state => {
current_file_filament_total: state => {
let file = state.files.filter((file) => file.filename === state.printer.virtual_sdcard.current_file);
if (file.length) return file[0]['filament_used'];
if (file.length) return file[0]['filament_total'];
return 0;
},
@@ -109,7 +109,7 @@ export default {
for (let prop in state.config) {
if (prop.startsWith('gcode_macro') &&
!state.config[prop].hasOwnProperty('rename_existing') &&
!Object.hasOwnProperty.call(state.config[prop], 'rename_existing') &&
!(hiddenMacros.indexOf(prop.replace('gcode_macro ', '').toLowerCase()) > -1)
) {
array.push({
@@ -134,7 +134,8 @@ export default {
let array = [];
for (let prop in state.config) {
if (prop.startsWith('gcode_macro') && !state.config[prop].hasOwnProperty('rename_existing')) {
if (prop.startsWith('gcode_macro') &&
!Object.hasOwnProperty.call(state.config[prop], 'rename_existing')) {
array.push({
'name': prop.replace('gcode_macro ', ''),
'prop': state.config[prop]
+3 -5
View File
@@ -14,20 +14,17 @@ export default new Vuex.Store({
hostname: window.location.hostname,
port: window.location.port,
reconnectInterval: 3000,
reconnectAttempts: 1000,
isConnected: false,
loadingGcodeUpload: false,
loadingGcodeRefresh: false,
loadingEmergencyStop: false,
loadingPrintPause: false,
loadingPrintResume: false,
loadingHome: false,
loadingHomeX: false,
loadingHomeY: false,
loadingHomeZ: false,
loadingQGL: false,
loadingRestart: false,
loadingRestartFirmware: false,
loadingRebootHost: false,
loadingShutdownHost: false,
loadingSaveGuiConfig: false,
loadingEndstopStatus: false,
},
@@ -48,6 +45,7 @@ export default new Vuex.Store({
countPerPage: 10,
}
},
loadings: [],
config: {
},
+23 -22
View File
@@ -3,15 +3,14 @@ const objectAssignDeep = require(`object-assign-deep`);
import { colorArray, colorChamber, colorHeaterBed, temperaturChartSampleInterval, temperaturChartSampleLength } from './variables';
export default {
setConnected (state) {
state.socket.isConnected = true;
Vue.prototype.$socket
},
setDisconnected (state) {
state.socket.isConnected = false;
Vue.prototype.$socket.reconnect();
//Vue.prototype.$socket.reconnect();
},
setPrinterData(state, data) {
@@ -103,11 +102,11 @@ export default {
let nameSplit = key.split(" ");
if (nameSplit[0] === "temperature_fan") {
Vue.prototype.$socket.sendObj('post_printer_subscriptions', { [key]: [] });
Vue.prototype.$webSocketsSendObj('post_printer_subscriptions', { [key]: [] });
}
if (nameSplit[0] === "filament_switch_sensor") {
Vue.prototype.$socket.sendObj('post_printer_subscriptions', { [key]: [] });
Vue.prototype.$webSocketsSendObj('post_printer_subscriptions', { [key]: [] });
}
}
},
@@ -128,7 +127,7 @@ export default {
modified: Date.parse(file.modified),
size: file.size,
slicer: file.slicer,
filament_used: file.filament_used,
filament_total: file.filament_total,
estimated_time: file.estimated_time,
layer_height: file.layer_height,
first_layer_height: file.first_layer_height,
@@ -174,6 +173,16 @@ export default {
state.socket.loadingSendGcode = false;
},
setLoading(state, data) {
if (!state.loadings.includes(data.name)) {
state.loadings.push(data.name);
}
},
removeLoading(state, data) {
state.loadings = state.loadings.filter(function(ele){ return ele !== data.name; });
},
setPrinterStatus(state, value) {
state.printer.toolhead.status = value;
},
@@ -202,22 +211,6 @@ export default {
state.socket.loadingPrintCancel = value;
},
setLoadingHome(state, value) {
state.socket.loadingHome = value;
},
setLoadingHomeX(state, value) {
state.socket.loadingHomeX = value;
},
setLoadingHomeY(state, value) {
state.socket.loadingHomeY = value;
},
setLoadingHomeZ(state, value) {
state.socket.loadingHomeZ = value;
},
setLoadingQGL(state, value) {
state.socket.loadingQGL = value;
},
@@ -230,6 +223,14 @@ export default {
state.socket.loadingRestartFirmware = value;
},
setLoadingRebootHost(state, value) {
state.socket.loadingRebootHost = value;
},
setLoadingShutdownHost(state, value) {
state.socket.loadingShutdownHost = value;
},
setLoadingSaveGuiConfige(state, value) {
state.socket.loadingSaveGuiConfig = value;
},