add subscribe method to user logged

This commit is contained in:
tiago.kayaya
2022-01-17 14:39:12 +01:00
parent cdecf4f5cc
commit 05a1b4a82a
2 changed files with 50 additions and 18 deletions
@@ -42,7 +42,7 @@ export class WsChatMethodsService {
rooms.result.update.forEach((roomData: room) => {
let room:RoomService;
// console.log(roomData);
//console.log(roomData);
room = new RoomService(this.WsChatService, new MessageService())
@@ -87,6 +87,10 @@ export class WsChatMethodsService {
console.log('streamRoomMessages', subscription)
})
}
this.WsChatService.streamNotifyLogged().then((subscription=>{
console.log('streamRoomMessages', subscription)
}))
}
getDmRoom(id): RoomService {
+45 -17
View File
@@ -18,10 +18,10 @@ export class WsChatService {
connect() {
// dont connect if is already connected
if(this.ws.connected == true) {
return false
if(this.ws.connected == true) {
return false
}
this.ws.connect();
const message = {
@@ -47,12 +47,12 @@ export class WsChatService {
login() {
// dont login if is already login
if(this.isLogin == true) {
return new Promise((resolve, reject)=>{
resolve(this.loginResponse)
})
if(this.isLogin == true) {
return new Promise((resolve, reject)=>{
resolve(this.loginResponse)
})
}
const requestId = uuidv4()
const message = {
@@ -67,7 +67,7 @@ export class WsChatService {
]
}
this.ws.send({message, requestId, loginRequired: false})
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
@@ -75,7 +75,7 @@ export class WsChatService {
if(message.result) {
if(message.result.token) {
this.isLogin = true
this.loginResponse = message
@@ -124,7 +124,7 @@ export class WsChatService {
this.isLogin = false
this.ws.connected = false
}
// send message to room
send(roomId, msg) {
@@ -191,16 +191,16 @@ export class WsChatService {
}
setStatus(status: 'online' | 'busy' | 'away' | 'offline') {
const requestId = uuidv4()
const message = {
msg: "method",
method: `UserPresence:setDefaultStatus`,
id: requestId,
params: [ status ]
}
this.ws.send({message, requestId})
@@ -275,6 +275,34 @@ export class WsChatService {
});
}
streamNotifyLogged() {
alert('HERE')
const requestId = uuidv4()
const message = {
"msg": "sub",
"id": requestId,
"name": "stream-notify-logged",
"params":[
"user-status",
false
]
}
this.ws.send({message, requestId});
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId) { // same request send
resolve(message)
return true
}
}})
});
}
streamNotifyRoom(roomId : string) {
const requestId = uuidv4()
@@ -308,7 +336,7 @@ export class WsChatService {
}
// socket class ==================================================================
private socket!: WebSocket;
private socket!: WebSocket;
private wsMsgQueue : {[key: string]: msgQueue} = {}
private wsCallbacks: {[key: string]: wsCallbacksParams} = {}
@@ -338,7 +366,7 @@ export class WsChatService {
wsMsgQueue:()=> {
for (const [key, item] of Object.entries(this.wsMsgQueue)) {
if(item.loginRequired == true && this.isLogin == true) {
// console.log('run msgQueue ',index)
this.ws.send(item);
@@ -382,7 +410,7 @@ export class WsChatService {
onclose:(event: any)=> {
this.ws.connected = false
this.isLogin = false
this.connect()
this.login()