2021-03-19 22:48:24 -03:00
|
|
|
function formatValue(value, base) {
|
|
|
|
return (new Intl.NumberFormat('es-CL', {style: 'currency', currency: base, minimumSignificantDigits: 2})).format(value)
|
2021-03-18 23:25:35 -03:00
|
|
|
}
|
2021-03-19 22:48:24 -03:00
|
|
|
function formatDate(date) {
|
|
|
|
return (new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'})).format(date)
|
2021-03-18 23:25:35 -03:00
|
|
|
}
|
2021-03-19 22:48:24 -03:00
|
|
|
function readyDate(date) {
|
|
|
|
return date.getFullYear()
|
|
|
|
+ '-' + (date.getMonth() + 1)
|
|
|
|
+ '-' + date.getDate()
|
|
|
|
+ ' ' + date.getHours()
|
|
|
|
+ ':' + date.getMinutes()
|
|
|
|
+ ':' + date.getSeconds()
|
2021-03-18 23:25:35 -03:00
|
|
|
}
|
2021-03-30 16:21:51 -03:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|