improve chat

This commit is contained in:
Peter Maquiran
2022-01-12 11:52:05 +01:00
parent b8b4ba6a05
commit 5552aa484b
13 changed files with 46 additions and 44 deletions
+2
View File
@@ -39,6 +39,7 @@ export class AuthService {
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
this.RocketChatClientService.connect(()=>{
this.RocketChatClientService.login({
username: SessionStore.user.RochetChatUser,
password: SessionStore.user.Password
@@ -47,6 +48,7 @@ export class AuthService {
}).catch((message)=>{
console.log('rocket chat login failed', message)
})
})
}
+5 -3
View File
@@ -7,7 +7,7 @@ import { SessionStore } from 'src/app/store/session.service';
@Injectable({
providedIn: 'root'
})
export class ChatService {
export class wsChatService {
individual: {[key: string]: RoomService} = {}
@@ -23,17 +23,19 @@ export class ChatService {
) {
(async()=>{
await this.getAllRoom();
await this.getAllRooms();
this.subscribeToRoom()
})()
}
async getAllRoom () {
async getAllRooms () {
this.loadingWholeList = true
const rooms: any = await this.RocketChatClientService.getRooms();
console.log(rooms)
rooms.result.update.forEach((roomData:any) => {
let room:RoomService;
+3
View File
@@ -31,4 +31,7 @@ export class MessageService {
showDateDuration() {}
}
+2 -3
View File
@@ -2,8 +2,6 @@ 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'
import { TimeService } from 'src/app/services/functions/time.service';
import { ChatService } from '../chat.service';
import { showDateDuration } from 'src/plugin/showDateDuration'
@Injectable({
providedIn: 'root'
@@ -47,6 +45,7 @@ export class RoomService {
message.setData(Chatmessage.result)
this.massages.push(message)
this.calDateDuration(Chatmessage.result._updatedAt)
}
)
}
@@ -58,7 +57,7 @@ export class RoomService {
// runs onces only
loadHistory(limit= 100) {
if(this.hasLoadHistory){ return false }
if(this.hasLoadHistory){ return false}
this.RocketChatClientService.loadHistory(this.id, limit).then((message:any) => {
console.log('loadHistory', message)
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { v4 as uuidv4 } from 'uuid'
import { wsCallbacksParams, msgQueue } from 'src/app/models/rochet-chat-cliente-service'
import { deepFind } from 'src/plugin/deep'
import { environment } from 'src/environments/environment';
/**
* Use this class to interact with rocketChat realtime API
*/
@@ -10,17 +11,15 @@ import { deepFind } from 'src/plugin/deep'
})
export class RocketChatClientService {
private hasPing = false
private firstPingFunx: Function
isLogin = false;
constructor() {}
connect(firstPingFunx: Function) {
this.hasPing = false
this.firstPingFunx = firstPingFunx
this.firstPingFunx = firstPingFunx //
this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket');
this.ws.connect(environment.apiWsChatUrl);
const connectMessage = {
msg: "connect",
@@ -29,19 +28,8 @@ import { deepFind } from 'src/plugin/deep'
}
this.ws.send(connectMessage, 'connect', false)
this.ws.registerCallback({type:'Onmessage', funx:(message: any) => {
if(message.msg == "ping") {
this.ws.send({msg:"pong"},'recoonect', false)
if(this.hasPing == false) {
// first ping
firstPingFunx()
this.hasPing = true
}
}
}})
this.ws.send({msg:"pong"},'recoonect', false)
firstPingFunx()
}
@@ -65,13 +53,12 @@ import { deepFind } from 'src/plugin/deep'
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
if(message.id == requestId ) { // same request send
if(message.result.token) {
this.isLogin = true
setTimeout(()=>{
this.ws.wsMsgQueue()
},0)
this.ws.wsMsgQueue()
resolve(message)
} else {
@@ -88,7 +75,7 @@ import { deepFind } from 'src/plugin/deep'
}
getRooms() {
getRooms(roomOlder = 1480377601) {
const requestId = uuidv4()
@@ -281,6 +268,10 @@ import { deepFind } from 'src/plugin/deep'
}
registerCallback(data:wsCallbacksParams) {
return this.ws.registerCallback(data)
}
// socket class ==================================================================
private socket!: WebSocket;
private wsUrl = ''