Se agrega funcionalidad de WebSockets

This commit is contained in:
2021-03-30 16:21:51 -03:00
parent 4a8ae50fdc
commit 70f8671c01
8 changed files with 358 additions and 141 deletions

View File

@ -12,3 +12,38 @@ function readyDate(date) {
+ ':' + date.getMinutes()
+ ':' + date.getSeconds()
}
let socket = {
url: '',
conn: null,
connect: function(ready, getMessage) {
this.conn = new WebSocket(this.url)
this.conn.onopen = (e) => {
console.debug(e)
ready()
}
this.conn.onmessage = (e) => {
console.debug(e)
getMessage(e)
}
this.conn.onerror = (e) => {
console.error(e)
}
this.conn.onclose = (e) => {
if (e.code != 1000) {
console.error(e)
return
}
console.debug(e)
}
},
sendMessage: function(action, data = null) {
var msg = {
action: action
}
if (data != null) {
msg['data'] = data
}
this.conn.send(JSON.stringify(msg))
}
}