mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Merge branch 'feature/websocket' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/websocket
This commit is contained in:
@@ -3,21 +3,20 @@ 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';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WsChatService {
|
||||
|
||||
|
||||
private firstPingFunx: Function
|
||||
isLogin = false;
|
||||
|
||||
constructor() {}
|
||||
|
||||
connect(firstPingFunx: Function) {
|
||||
this.firstPingFunx = firstPingFunx //
|
||||
connect() {
|
||||
|
||||
this.ws.connect(environment.apiWsChatUrl);
|
||||
this.ws.connect();
|
||||
|
||||
const connectMessage = {
|
||||
msg: "connect",
|
||||
@@ -27,14 +26,10 @@ export class WsChatService {
|
||||
|
||||
this.ws.send(connectMessage, 'connect', false)
|
||||
this.ws.send({msg:"pong"},'recoonect', false)
|
||||
firstPingFunx()
|
||||
|
||||
}
|
||||
|
||||
login(user) {
|
||||
|
||||
login() {
|
||||
const requestId = uuidv4()
|
||||
this.isLogin = false
|
||||
|
||||
const loginRequest = {
|
||||
msg: "method",
|
||||
@@ -42,8 +37,8 @@ export class WsChatService {
|
||||
id: requestId,
|
||||
params: [
|
||||
{
|
||||
user: { username: user.username },
|
||||
password: user.password
|
||||
user: { username: SessionStore.user.RochetChatUser },
|
||||
password: SessionStore.user.Password
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -51,9 +46,12 @@ export class WsChatService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, funx:(message)=>{
|
||||
console.log('message login', message)
|
||||
if(message.id == requestId ) { // same request send
|
||||
console.log('message login', message)
|
||||
|
||||
if(message.result.token) {
|
||||
console.log('this.isLogin = true')
|
||||
this.isLogin = true
|
||||
|
||||
this.ws.wsMsgQueue()
|
||||
@@ -290,9 +288,8 @@ export class WsChatService {
|
||||
}
|
||||
|
||||
},
|
||||
connect:(url)=> {
|
||||
this.wsUrl = url
|
||||
this.socket = new WebSocket(this.wsUrl);
|
||||
connect:()=> {
|
||||
this.socket = new WebSocket(environment.apiWsChatUrl);
|
||||
// bind function
|
||||
this.socket.onopen = this.ws.onopen;
|
||||
this.socket.onmessage = this.ws.onmessage;
|
||||
@@ -302,6 +299,7 @@ export class WsChatService {
|
||||
onopen:()=> {
|
||||
this.ws.connected = true
|
||||
console.log('================== welcome to socket server =====================')
|
||||
|
||||
this.ws.wsMsgQueue()
|
||||
},
|
||||
wsMsgQueue:()=> {
|
||||
@@ -350,7 +348,8 @@ export class WsChatService {
|
||||
|
||||
onclose:(event: any)=> {
|
||||
|
||||
this.connect(this.firstPingFunx())
|
||||
this.connect()
|
||||
this.login()
|
||||
|
||||
this.ws.connected = false
|
||||
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
||||
|
||||
Reference in New Issue
Block a user