V2.0.0-beta (#308)
* test vue-echarts and dataset>source instead of series>data Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix disposed state of chart & delete update interval of settings page Signed-off-by: Stefan Dej <meteyou@gmail.com> * init TS migation & dashboard Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: dashbaord console Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: add "disabled" status to the filament runout sensor on the dashboard Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix klipper restart process Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix status panel during a print Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert g-code files to typescript Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert history files to typescript Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert machine limits to typescript Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert update manager to typescript Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert endstops & logfiles to typescript Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix temp display in tools panel Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert machine > config files to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert select printer dialog to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert select printer menu to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert farm page to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix debug output of farm printer getters Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix import webcam streams in farm view Signed-off-by: Stefan Dej <meteyou@gmail.com> * better handling when changing printers Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert heightmap to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert heightmap to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * Console QOL (#300) * CHORE Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * NEW: console ts refactor, linux autocomplete, gui helplist, multiline Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * FIX: console autocomplete flood fix Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * fix merged console Signed-off-by: Stefan Dej <meteyou@gmail.com> * fixed return of ConsoleTable.vue isCommand Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: add toast after creating file in ConfigFilesPanel.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: file upload message Signed-off-by: Stefan Dej <meteyou@gmail.com> * add toolbar to files panels Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: disable scrollbars in TempChart.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: sidebar z-index and farm printer toolbar Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: sidebar & topbar z-index and farm printer toolbar Signed-off-by: Stefan Dej <meteyou@gmail.com> * update toolbars in gcode-files and history Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: new settings dialog (#302) * create settings dialog and integrate general, console, control, marcos, presets, webcams Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: renamed webcam gui state variable Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: temperature_fan chamber in farm printers dashboard Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: only display RPM in tools panel, when its available Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: reading empty remote printers list Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: loading additionalSensors in temp panel Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix: bed_mesh loading rework heightmap settings save heightmap settings in moonraker db Signed-off-by: Stefan Dej <meteyou@gmail.com> * add remote printers to settings Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix types Signed-off-by: Stefan Dej <meteyou@gmail.com> * add beforeDestroy to echarts Signed-off-by: Stefan Dej <meteyou@gmail.com> * add heightmap visualMap scaling and format tooltip Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: logo & primary color customizing Signed-off-by: Stefan Dej <meteyou@gmail.com> * remove keep-alive in app.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * round tempchart data Signed-off-by: Stefan Dej <meteyou@gmail.com> * normalize toolbar buttons Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix series attributes & update echarts-gl Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix hostname in sidebar Signed-off-by: Stefan Dej <meteyou@gmail.com> * rework websocket loadings Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix rework websocket loadings Signed-off-by: Stefan Dej <meteyou@gmail.com> * Fixes for console QOL PR (#301) * FIX: command help dialog added Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * FIX: console fixes Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * rework events store Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: check customFilters if string or array Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: edit preset dont work (existing name check) Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: save webcam with index 0 Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: tool combobox input dont work Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: tooltip position & z-index Signed-off-by: Stefan Dej <meteyou@gmail.com> * rework console Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix output name of filament sensor Signed-off-by: Stefan Dej <meteyou@gmail.com> * store performance updates and StatusPanel.vue optimizing Signed-off-by: Stefan Dej <meteyou@gmail.com> * console bugfixes Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix icon-rotate in temperatures panel Signed-off-by: Stefan Dej <meteyou@gmail.com> * add auto-grow to console input fields Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix dialog action button colors Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix refreshMetadata of gcocde files Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: add multi fileupload to drag&drop upload Signed-off-by: Stefan Dej <meteyou@gmail.com> * convert SystemPanel to TS Signed-off-by: Stefan Dej <meteyou@gmail.com> * add init and getters for system panels Signed-off-by: Stefan Dej <meteyou@gmail.com> * add init and getters for system panels Signed-off-by: Stefan Dej <meteyou@gmail.com> * finish SystemPanel.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: raspberry throttled flags in topbar Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: fix type in TheThrottledStates.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: add new editor (#307) * init test Signed-off-by: Stefan Dej <meteyou@gmail.com> * theme test Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: switch to codemirror editor Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: fix type in TheThrottledStates.vue Signed-off-by: Stefan Dej <meteyou@gmail.com> * reformat flags output and deactivate debug output Signed-off-by: Stefan Dej <meteyou@gmail.com> * add types to throttle states Signed-off-by: Stefan Dej <meteyou@gmail.com> * display "dirty" in the board firmware version string Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix mini console array cut Signed-off-by: Stefan Dej <meteyou@gmail.com> * delete old comment Signed-off-by: Stefan Dej <meteyou@gmail.com> * fix config files on small devices Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: display macro description in settings tab Signed-off-by: Stefan Dej <meteyou@gmail.com> * change settings icons Signed-off-by: Stefan Dej <meteyou@gmail.com> * rename dashboard panel & change slider text in settings Signed-off-by: Stefan Dej <meteyou@gmail.com> * responsive optimations for settings Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix throttled state flags filter Signed-off-by: Stefan Dej <meteyou@gmail.com> * Code highlighting for codemirror (#309) * init test Signed-off-by: Stefan Dej <meteyou@gmail.com> * theme test Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: switch to codemirror editor Signed-off-by: Stefan Dej <meteyou@gmail.com> * NEW: klipper_config editor theme Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> * NEW: code highlighting for codemirror Signed-off-by: Eike Ahmels <eike.ahmels@tu-dortmund.de> Co-authored-by: Stefan Dej <meteyou@gmail.com> * feature: hide/show jobs with special print status Signed-off-by: Stefan Dej <meteyou@gmail.com> * redesign console help modal Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: default state of sidebar was wrong on mobile devices Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: mobile view interface settings Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: optimize mobile view interface settings Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: block empty console commands Signed-off-by: Stefan Dej <meteyou@gmail.com> * push version number Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: add current / max flow in status panel Signed-off-by: Stefan Dej <meteyou@gmail.com> * feature: add big gcode thumbnail to status panel Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: fix favicon and setting tab names Signed-off-by: Stefan Dej <meteyou@gmail.com> * cleanup old editor Signed-off-by: Stefan Dej <meteyou@gmail.com> * bugfix: add redirect for updates from 1.6.0 to 2.0.0 Signed-off-by: Stefan Dej <meteyou@gmail.com> Co-authored-by: Eike Ahmels <hui_buh-@gmx.net>
This commit is contained in:
1 parent
84e86bb8b2
commit
baa25c4bcd
227 files changed
+25004
-28604
No files matched your search
@@ -0,0 +1,170 @@
|
||||
import {Store} from "vuex"
|
||||
import _Vue from "vue";
|
||||
import {RootState} from "@/store/types";
|
||||
|
||||
export class WebSocketClient {
|
||||
url = ''
|
||||
instance: WebSocket | null = null
|
||||
maxReconnects = 5
|
||||
reconnectInterval = 1000
|
||||
reconnects = 0
|
||||
keepAliveTimeout = 1000
|
||||
timerId: number | null = null
|
||||
store: Store<RootState> | null = null
|
||||
waits: Wait[] = []
|
||||
|
||||
constructor (options: WebSocketPluginOptions) {
|
||||
this.url = options.url
|
||||
this.maxReconnects = options.maxReconnects || 5
|
||||
this.reconnectInterval = options.reconnectInterval || 1000
|
||||
this.store = options.store
|
||||
}
|
||||
|
||||
setUrl(url: string): void {
|
||||
this.url = url
|
||||
}
|
||||
|
||||
passToStore (eventName: string, event: any): void {
|
||||
if (!eventName.startsWith('socket/')) { return }
|
||||
|
||||
this.store?.dispatch(eventName, event)
|
||||
}
|
||||
|
||||
connect(): void {
|
||||
this.store?.dispatch("socket/setData", { isConnecting: true })
|
||||
this.instance = new WebSocket(this.url)
|
||||
|
||||
this.instance.onopen = () => {
|
||||
this.reconnects = 0
|
||||
this.store?.dispatch('socket/onOpen', event)
|
||||
}
|
||||
|
||||
this.instance.onclose = (e) => {
|
||||
if (!e.wasClean && this.reconnects < this.maxReconnects) {
|
||||
this.reconnects++
|
||||
setTimeout(() => {
|
||||
this.connect()
|
||||
}, this.reconnectInterval)
|
||||
} else this.store?.dispatch('socket/onClose', e)
|
||||
}
|
||||
|
||||
this.instance.onerror = () => {
|
||||
if (this.instance) this.instance.close()
|
||||
}
|
||||
|
||||
this.instance.onmessage = (msg) => {
|
||||
const data = JSON.parse(msg.data)
|
||||
if (this.store) {
|
||||
const wait = this.getWaitById(data.id)
|
||||
if (wait && wait.action !== ""){
|
||||
if (data.error && data.error.message) {
|
||||
window.console.error("Response Error: "+wait.action+" > "+data.error.message)
|
||||
if (wait.params) window.console.log(wait.params)
|
||||
|
||||
/*this.store?.dispatch(wait.action,
|
||||
Object.assign(wait.actionPreload || {}, {
|
||||
error: data.error,
|
||||
requestParams: wait.params
|
||||
})
|
||||
)*/
|
||||
} else if (wait.action) {
|
||||
let result = data.result
|
||||
if (result === "ok") result = { result: result }
|
||||
if (typeof(result) === "string") result = { result: result }
|
||||
|
||||
const preload = {}
|
||||
if (wait.actionPayload) Object.assign(preload, wait.actionPayload)
|
||||
Object.assign(preload, { requestParams: wait.params })
|
||||
Object.assign(preload, result)
|
||||
this.store?.dispatch(wait.action, preload)
|
||||
}
|
||||
} else this.store?.dispatch('socket/onMessage', data)
|
||||
|
||||
if (wait) this.removeWaitById(wait.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close():void {
|
||||
if (this.instance) this.instance.close()
|
||||
}
|
||||
|
||||
getWaitById(id: number): Wait | null {
|
||||
return this.waits.find((wait: Wait) => wait.id === id) ?? null
|
||||
}
|
||||
|
||||
removeWaitById(id: number): void {
|
||||
const index = this.waits.findIndex((wait: Wait) => wait.id === id)
|
||||
if (index) {
|
||||
const wait = this.waits[index]
|
||||
if (wait.loading && this.store) {
|
||||
this.store.dispatch("socket/removeLoading", { name: wait.loading })
|
||||
}
|
||||
this.waits.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
emit(method: string, params: Params, options: emitOptions = {}):void {
|
||||
if (this.instance?.readyState === WebSocket.OPEN) {
|
||||
const id = Math.floor(Math.random() * 10000) + 1
|
||||
this.waits.push({
|
||||
id: id,
|
||||
params: params,
|
||||
action: options.action ?? null,
|
||||
actionPayload: options.actionPayload ?? {},
|
||||
loading: options.loading ?? null,
|
||||
})
|
||||
|
||||
if (options.loading && this.store) {
|
||||
this.store.dispatch("socket/addLoading", { name: options.loading })
|
||||
}
|
||||
|
||||
const msg = JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
method: method,
|
||||
params: params,
|
||||
id: id
|
||||
})
|
||||
|
||||
this.instance.send(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function WebSocketPlugin<WebSocketPlugin>(Vue: typeof _Vue, options: WebSocketPluginOptions): void {
|
||||
const socket = new WebSocketClient(options)
|
||||
Vue.prototype.$socket = socket
|
||||
Vue.$socket = socket
|
||||
}
|
||||
|
||||
export interface WebSocketPluginOptions {
|
||||
url: string
|
||||
maxReconnects?: number
|
||||
reconnectInterval?: number
|
||||
store: Store<RootState>
|
||||
}
|
||||
|
||||
export interface WebSocketClient {
|
||||
connect(): void
|
||||
close(): void
|
||||
emit(method: string, params: Params, emitOptions: emitOptions):void
|
||||
}
|
||||
|
||||
export interface Wait {
|
||||
id: number
|
||||
params: any
|
||||
action?: string | null
|
||||
actionPayload?: any
|
||||
loading?: string | null
|
||||
}
|
||||
|
||||
interface Params {
|
||||
data?: any
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
interface emitOptions {
|
||||
action?: string | null
|
||||
actionPayload?: Params
|
||||
loading?: string | null
|
||||
}
|
||||
Reference in new issue
Block a user