mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
improve rocket-chat-cliente interface
This commit is contained in:
@@ -9,7 +9,7 @@ export class SocketInterfaceService {
|
||||
private url = ''
|
||||
private connected = false
|
||||
private callBacks: {
|
||||
type: 'Offline' | 'Online' | 'Onmessage' | 'Chat' | 'Notification' | 'Notifications' | '',
|
||||
type: 'Offline' | 'Online' | 'Open' ,
|
||||
object?: string
|
||||
funx: Function
|
||||
}[] = []
|
||||
@@ -17,6 +17,14 @@ export class SocketInterfaceService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
registerCallback(type: 'Offline' | 'Online' | 'Open', funx: Function, object = '') {
|
||||
this.callBacks.push({
|
||||
type,
|
||||
funx,
|
||||
object
|
||||
})
|
||||
}
|
||||
|
||||
connect(url) {
|
||||
|
||||
this.url = url
|
||||
@@ -28,8 +36,20 @@ export class SocketInterfaceService {
|
||||
this.socket.onerror = this.onerror;
|
||||
}
|
||||
|
||||
onopen() {
|
||||
this.connected = true
|
||||
|
||||
// send all saved data due to internet connection
|
||||
this.msgQueue.forEach((item, index, object) => {
|
||||
this.send(item);
|
||||
object.splice(index, 1);
|
||||
})
|
||||
}
|
||||
|
||||
send(message: object) {
|
||||
if (!this.connected) { // save data to send when back online
|
||||
console.log(this.connected, message)
|
||||
|
||||
if (this.connected === false) { // save data to send when back online
|
||||
this.msgQueue.push(message)
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
@@ -37,12 +57,12 @@ export class SocketInterfaceService {
|
||||
}
|
||||
}
|
||||
|
||||
onopen() {
|
||||
|
||||
onmessage(event: any) {
|
||||
console.log('event.data', JSON.parse(event.data))
|
||||
}
|
||||
onmessage() {}
|
||||
|
||||
onclose(event: any) {
|
||||
this.connected = false
|
||||
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
||||
setTimeout(()=>{
|
||||
this.connect(this.url)
|
||||
|
||||
Reference in New Issue
Block a user