Se agrega funcionalidad de WebSockets
This commit is contained in:
@ -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))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user