mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
Merge branch 'feature/websocket' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/websocket
This commit is contained in:
+31
-20
@@ -17,7 +17,6 @@ import { File } from '@ionic-native/file/ngx';
|
||||
/* import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service'; */
|
||||
import { DocumentCounterService } from '../services/worker/document-counter.service';
|
||||
import { PermissionService } from '../services/worker/permission.service';
|
||||
import { Network } from '@ionic-native/network/ngx';
|
||||
import { BackgroundService } from 'src/app/services/background.service';
|
||||
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
|
||||
import { Storage } from '@ionic/storage';
|
||||
@@ -29,7 +28,7 @@ import { Device } from '@capacitor/device';
|
||||
import { RouteService } from 'src/app/services/route.service';
|
||||
import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -73,8 +72,6 @@ export class HomePage implements OnInit {
|
||||
status: string = "";
|
||||
audioName: string = "";
|
||||
|
||||
RocketChatClientService = RocketChatClientService
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
public modalCtrl: AlertController,
|
||||
@@ -95,25 +92,39 @@ export class HomePage implements OnInit {
|
||||
private processservice: ProcessesService,
|
||||
private screenOrientation: ScreenOrientation,
|
||||
private sqliteservice: SqliteService,
|
||||
private RouteService: RouteService) {
|
||||
private RouteService: RouteService,
|
||||
private RocketChatClientService: RocketChatClientService) {
|
||||
|
||||
this.RocketChatClientService.connect(()=>{
|
||||
|
||||
this.RocketChatClientService.login({
|
||||
username: 'paulo.pinto',
|
||||
email: 'paulo.pinto@gabinetedigital.local',
|
||||
password: 'tabteste@006'
|
||||
}).then((message)=>{
|
||||
console.log('rocket chat login successfully', message)
|
||||
this.RocketChatClientService.getRooms().then((rooms)=>{
|
||||
console.log('rooms', rooms)
|
||||
})
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
}).finally(()=>{
|
||||
this.RocketChatClientService.loadHistory('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 10).then((message)=>{
|
||||
console.log('loadHistory', message)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
this.RocketChatClientService.getRooms().then((rooms: any)=>{
|
||||
console.log('rooms', rooms)
|
||||
|
||||
rooms.result.update.forEach((room:any) => {
|
||||
console.log('room', room)
|
||||
this.RocketChatClientService.subscribe(room.lastMessage.rid).then((subscription)=>{
|
||||
console.log('subscription', subscription)
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.RocketChatClientService.receiveLiveMessageFromRoom(
|
||||
'fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM',
|
||||
this.constructor.name,
|
||||
(Chatmessage)=>{
|
||||
console.log('chat', Chatmessage)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
window['jj'] = ()=>{
|
||||
//send message // roomId // Message
|
||||
this.RocketChatClientService.send('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 'Mensagem enviada programaticamente.'+ new Date().toISOString())
|
||||
}
|
||||
|
||||
// this.RocketChatClientService.send()
|
||||
/* this.webNotificationPopupService.askNotificationPermission() */
|
||||
|
||||
@@ -8,5 +8,6 @@ export interface wsCallbacksParams {
|
||||
|
||||
export interface msgQueue {
|
||||
message: object,
|
||||
requestId: string
|
||||
requestId: string,
|
||||
loginRequired: boolean
|
||||
}
|
||||
@@ -56,6 +56,8 @@ export class UserSession {
|
||||
TypeShare: number;
|
||||
}[]
|
||||
UserName: string
|
||||
Password: string
|
||||
RochetChatUser: string
|
||||
Profile: any;
|
||||
LoginPreference: 'None' | 'Password' | 'Pin' | null;
|
||||
PIN: string
|
||||
|
||||
@@ -30,13 +30,25 @@ export class AuthService {
|
||||
public alertController: AlertController,
|
||||
private aesencrypt: AESEncrypt,
|
||||
private cookieService: CookieService,
|
||||
//private realtimeChat: RocketChatClientService;
|
||||
) {
|
||||
private RocketChatClientService: RocketChatClientService) {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
if (SessionStore.exist) {
|
||||
this.ValidatedUser = SessionStore.user
|
||||
|
||||
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
|
||||
this.RocketChatClientService.connect(()=>{
|
||||
this.RocketChatClientService.login({
|
||||
username: SessionStore.user.RochetChatUser,
|
||||
password: SessionStore.user.Password
|
||||
}).then((message) => {
|
||||
console.log('rocket chat login successfully', message)
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if (localStorage.getItem("userChat") != null) {
|
||||
@@ -78,6 +90,9 @@ export class AuthService {
|
||||
session.Profile = 'MDGPR'
|
||||
}
|
||||
|
||||
session.Password = user.password
|
||||
session.RochetChatUser = user.username.split('@')[0]
|
||||
|
||||
session.BasicAuthKey = user.BasicAuthKey
|
||||
|
||||
SessionStore.reset(session)
|
||||
@@ -99,6 +114,22 @@ export class AuthService {
|
||||
"password": user.password,
|
||||
}
|
||||
|
||||
|
||||
this.RocketChatClientService.connect(()=>{
|
||||
|
||||
this.RocketChatClientService.login({
|
||||
username: SessionStore.user.RochetChatUser,
|
||||
password: user.password
|
||||
}).then((message) => {
|
||||
console.log('rocket chat login successfully', message)
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
}).finally(()=>{
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
let responseChat = await this.httpService.post('login', postData).toPromise();
|
||||
|
||||
if(responseChat) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatUserService } from './chat-user.service';
|
||||
|
||||
describe('ChatUserService', () => {
|
||||
let service: ChatUserService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChatUserService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatUserService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MethodsService } from './methods.service';
|
||||
import { ChatService } from './chat.service';
|
||||
|
||||
describe('MethodsService', () => {
|
||||
let service: MethodsService;
|
||||
describe('ChatService', () => {
|
||||
let service: ChatService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(MethodsService);
|
||||
service = TestBed.inject(ChatService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomService } from './room.service';
|
||||
import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatService {
|
||||
|
||||
rooms: RoomService[] = []
|
||||
group = []
|
||||
|
||||
constructor(
|
||||
private RocketChatClientService: RocketChatClientService
|
||||
) {
|
||||
this.getAllRoomAndSubscribe()
|
||||
}
|
||||
|
||||
getAllRoomAndSubscribe() {
|
||||
this.RocketChatClientService.getRooms().then((rooms: any) => {
|
||||
rooms.result.update.forEach((roomData:any) => {
|
||||
const room = new RoomService(new RocketChatClientService(), new MessageService())
|
||||
room.setData({id: roomData.lastMessage.rid})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onJoinRoom() {
|
||||
// live
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MessageService } from './message.service';
|
||||
|
||||
describe('MessageService', () => {
|
||||
let service: MessageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(MessageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ChatService } from '../chat.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MethodsService {
|
||||
|
||||
constructor(private chatService: ChatService) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomService } from './room.service';
|
||||
|
||||
describe('RoomService', () => {
|
||||
let service: RoomService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service';
|
||||
import { MessageService } from 'src/app/services/chat/message.service'
|
||||
import { ChatUserService } from 'src/app/services/chat/chat-user.service'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomService {
|
||||
|
||||
massages: MessageService[] = []
|
||||
chatUser: ChatUserService[] = []
|
||||
id = []
|
||||
|
||||
constructor(
|
||||
private RocketChatClientService: RocketChatClientService,
|
||||
private MessageService: MessageService
|
||||
) {}
|
||||
|
||||
setData({id}){
|
||||
this.id= id
|
||||
}
|
||||
|
||||
create() {}
|
||||
sendMessage() {}
|
||||
deleteMessage() {}
|
||||
ReactToMessage() {}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { wsCallbacksParams, msgQueue } from 'src/app/models/rochet-chat-cliente-service'
|
||||
|
||||
class _RocketChatClientService {
|
||||
import { deepFind } from 'src/plugin/deep'
|
||||
/**
|
||||
* Use this class to interact with rocketChat realtime API
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RocketChatClientService {
|
||||
|
||||
private hasPing = false
|
||||
private firstPingFunx: Function
|
||||
isLogin = false;
|
||||
request = []
|
||||
|
||||
constructor() {}
|
||||
|
||||
private returns() {}
|
||||
|
||||
connect(firstPingFunx: Function) {
|
||||
this.hasPing = false
|
||||
this.firstPingFunx = firstPingFunx
|
||||
@@ -25,12 +28,12 @@ class _RocketChatClientService {
|
||||
support: ["1"]
|
||||
}
|
||||
|
||||
this.ws.send(connectMessage)
|
||||
this.ws.send(connectMessage, 'connect', false)
|
||||
|
||||
this.ws.registerCallback({type:'Onmessage',funx:(message: any) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message: any) => {
|
||||
|
||||
if(message.msg == "ping") {
|
||||
this.ws.send({msg:"pong"})
|
||||
this.ws.send({msg:"pong"},'recoonect', false)
|
||||
if(this.hasPing == false) {
|
||||
// first ping
|
||||
firstPingFunx()
|
||||
@@ -45,6 +48,7 @@ class _RocketChatClientService {
|
||||
login(user) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
this.isLogin = false
|
||||
|
||||
const loginRequest = {
|
||||
msg: "method",
|
||||
@@ -57,57 +61,35 @@ class _RocketChatClientService {
|
||||
}
|
||||
]
|
||||
}
|
||||
this.ws.send(loginRequest, requestId)
|
||||
this.ws.send(loginRequest, requestId, false)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, runOnces: true, funx:(message)=>{
|
||||
// console.log(message.result.id, requestId)
|
||||
if(message.id == requestId) { // same request send
|
||||
if(message.result) {
|
||||
if(message.result.token) {
|
||||
this.isLogin = true
|
||||
resolve(message)
|
||||
} else {
|
||||
this.isLogin = false
|
||||
reject(message)
|
||||
}
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message, 'result.id') == requestId) { // same request send
|
||||
|
||||
if(message.result.token) {
|
||||
this.isLogin = true
|
||||
setTimeout(()=>{
|
||||
this.ws.wsMsgQueue()
|
||||
},0)
|
||||
|
||||
resolve(message)
|
||||
} else {
|
||||
this.isLogin = false
|
||||
reject(message)
|
||||
}
|
||||
|
||||
reject(message)
|
||||
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
logout(){}
|
||||
|
||||
send(roomId, message, option) {
|
||||
const requestId = uuidv4()
|
||||
|
||||
var request = {
|
||||
msg: "method",
|
||||
method: "sendMessage",
|
||||
id: requestId,
|
||||
params: [{
|
||||
_id: "message-id" || uuidv4(),
|
||||
rid: "room-id" || roomId,
|
||||
msg: "Hello World!" || message
|
||||
}]
|
||||
}
|
||||
|
||||
// this.ws.send(request, requestId);
|
||||
|
||||
return requestId;
|
||||
}
|
||||
|
||||
subtribe() {}
|
||||
joinRoom(){}
|
||||
deleteMessage() {}
|
||||
createRoom() {}
|
||||
|
||||
getRooms() {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const request = {
|
||||
@@ -116,43 +98,186 @@ class _RocketChatClientService {
|
||||
"id": requestId,
|
||||
"params": [ { "$date": 1480377601 } ]
|
||||
}
|
||||
this.ws.send(request, requestId)
|
||||
|
||||
this.ws.send(request, requestId, true)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, runOnces: true, funx:(message)=>{
|
||||
if(message.result.id == requestId) { // same request send
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.id == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
logout() {}
|
||||
|
||||
send(roomId, message) {
|
||||
|
||||
subscribe() {
|
||||
const requestId = uuidv4()
|
||||
|
||||
var request = {
|
||||
msg: "method",
|
||||
method: "sendMessage",
|
||||
id: requestId,
|
||||
params: [{
|
||||
_id: uuidv4(),
|
||||
rid: roomId,
|
||||
msg: message
|
||||
}]
|
||||
}
|
||||
|
||||
this.ws.send(request, requestId, true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
joinRoom(){}
|
||||
deleteMessage() {}
|
||||
createRoom() {}
|
||||
|
||||
|
||||
|
||||
loadHistory(roomId, limit: number = 50) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const request = {
|
||||
msg: "method",
|
||||
method: "loadHistory",
|
||||
id: requestId,
|
||||
params: [
|
||||
roomId,
|
||||
null,
|
||||
limit,
|
||||
{
|
||||
"$date": 1480377601
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send(request, requestId, true)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
// console.log(message)
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(roomId : string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var subscribeRequest = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-notify-room",
|
||||
"params":[
|
||||
"room-id/event",
|
||||
`${roomId}/event`,
|
||||
false
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send(subscribeRequest);
|
||||
this.ws.send(subscribeRequest, requestId, true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, runOnces: true, funx:(message)=>{
|
||||
if(message.result.id == requestId) { // same request send
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.msg == 'ready' || deepFind(message, 'subs.0') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private disconnect = () => {
|
||||
/**
|
||||
* @param roomId
|
||||
* @param key
|
||||
* @param funx
|
||||
*/
|
||||
receiveLiveMessageFromRoom(roomId, key, funx: Function) {
|
||||
|
||||
this.ws.registerCallback({
|
||||
type:'Onmessage',
|
||||
requestId: key,
|
||||
funx:(message)=>{
|
||||
if(message.msg =='result') {
|
||||
if(message.result.msg) {
|
||||
if(message.result.rid == roomId) {
|
||||
funx(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
streamRoomMessages(roomId : string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
const request = {
|
||||
"msg": "sub",
|
||||
"id": requestId,
|
||||
"name": "stream-room-messages",
|
||||
"params":[
|
||||
`${roomId}/event`,
|
||||
false
|
||||
]
|
||||
}
|
||||
|
||||
this.ws.send(request, requestId, true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.msg == 'ready' || deepFind(message, 'subs.0') == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
}
|
||||
|
||||
streamNotifyRoom(roomId : string) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let streamNotifyObj = {
|
||||
"msg": "method",
|
||||
"method": "stream-notify-room",
|
||||
"id": requestId,
|
||||
"params": [
|
||||
`null/typing`,
|
||||
"paulo.pinto",
|
||||
true
|
||||
]
|
||||
};
|
||||
|
||||
this.ws.send(streamNotifyObj, requestId, true)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
|
||||
resolve('')
|
||||
return true
|
||||
}
|
||||
}})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -164,7 +289,7 @@ class _RocketChatClientService {
|
||||
|
||||
private ws = {
|
||||
connected: false,
|
||||
registerCallback:(params: wsCallbacksParams) =>{
|
||||
registerCallback:(params: wsCallbacksParams) => {
|
||||
|
||||
if(!params.requestId) {
|
||||
params.requestId = uuidv4()
|
||||
@@ -172,12 +297,10 @@ class _RocketChatClientService {
|
||||
|
||||
this.wsCallbacks[params.requestId] = {
|
||||
type: params.type,
|
||||
funx: params.funx,
|
||||
runOnces: params.runOnces
|
||||
funx: params.funx
|
||||
}
|
||||
|
||||
},
|
||||
deleteCallback(){},
|
||||
connect:(url)=> {
|
||||
this.ws.connected = false
|
||||
this.wsUrl = url
|
||||
@@ -191,20 +314,28 @@ class _RocketChatClientService {
|
||||
onopen:()=> {
|
||||
this.ws.connected = true
|
||||
console.log('================== welcome to socket server =====================')
|
||||
|
||||
this.wsMsgQueue.forEach((item, index, object) => {
|
||||
this.ws.send(item.message, item.requestId);
|
||||
object.splice(index, 1);
|
||||
})
|
||||
|
||||
this.ws.wsMsgQueue()
|
||||
},
|
||||
send: (message: object, requestId = uuidv4()) => {
|
||||
wsMsgQueue:()=> {
|
||||
this.wsMsgQueue.forEach((item, index, object) => {
|
||||
if(item.loginRequired == true && this.isLogin == true) {
|
||||
console.log('run msgQueue ',index)
|
||||
this.ws.send(item.message, item.requestId, item.loginRequired);
|
||||
delete this.wsMsgQueue[item.requestId]
|
||||
} else if(item.loginRequired == false) {
|
||||
console.log('run msgQueue ',index)
|
||||
this.ws.send(item.message, item.requestId, item.loginRequired);
|
||||
delete this.wsMsgQueue[item.requestId]
|
||||
}
|
||||
|
||||
if (this.ws.connected == false) { // save data to send when back online
|
||||
})
|
||||
},
|
||||
send: (message: object, requestId = uuidv4(), loginRequired) => {
|
||||
|
||||
if (this.ws.connected == false || loginRequired == true && this.isLogin == false) { // save data to send when back online
|
||||
console.log('save msgQueue')
|
||||
this.wsMsgQueue.push({message, requestId})
|
||||
this.wsMsgQueue.push({message, requestId, loginRequired})
|
||||
} else {
|
||||
console.log('send rocket chat', message)
|
||||
let messageStr = JSON.stringify(message)
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
@@ -213,16 +344,17 @@ class _RocketChatClientService {
|
||||
|
||||
onmessage:(event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
console.log('event.data', data)
|
||||
// console.log('event.data', data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
value.funx(data)
|
||||
if(value.runOnces) {
|
||||
delete this.wsCallbacks[value.requestId || key]
|
||||
}
|
||||
}
|
||||
const dontRepeat = value.funx(data)
|
||||
|
||||
if(dontRepeat) {
|
||||
delete this.wsCallbacks[key]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -243,6 +375,3 @@ class _RocketChatClientService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const RocketChatClientService = new _RocketChatClientService()
|
||||
|
||||
Reference in New Issue
Block a user