// JS websocket part for esp32 server_http_ws template
// Copyright by Anthony Vogelaar, Perth Scotland
// rev 0.10  2025-12-12 initial release

// ====================== websocket ============================

const	wsock	= new WebSocket("ws://" + location.hostname + ":5000/ws")
wsock.addEventListener("message", wsOnMessage)


// send obj in json through ws
function wsSend(obj) {
    wsock.send(JSON.stringify(obj))
}


// handle incoming ws json message
function wsOnMessage(ev) {
    let obj = JSON.parse(ev.data)
    doCommand(obj)
}

// ========================= end ==============================
