Merge branch 'feature/websocket' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/websocket

This commit is contained in:
tiago.kayaya
2022-01-14 11:53:21 +01:00
3 changed files with 37 additions and 10 deletions
+15 -1
View File
@@ -39,7 +39,7 @@ export class RoomService {
}
receiveMessage() {
this.WsChatService.receiveLiveMessageFromRoom(
this.WsChatService.receiveMyMessageConfirmation(
this.id,
(ChatMessage:ChatMessage) => {
@@ -51,6 +51,20 @@ export class RoomService {
this.ToastService.presentToast('nova mensagem')
}
)
this.WsChatService.receiveLiveMessageFromRoom(
this.id,
(ChatMessage) => {
ChatMessage = ChatMessage.fields.args[0]
ChatMessage = this.fix_updatedAt(ChatMessage)
const message = new MessageService()
this.ToastService.presentToast('nova mensagem')
message.setData(ChatMessage)
this.massages.push(message)
this.calDateDuration(ChatMessage.result._updatedAt)
}
)
}
send(msg) {
@@ -27,6 +27,7 @@ export class WsChatMethodsService {
(async()=>{
await this.getAllRooms();
this.subscribeToRoom()
})()
}
@@ -69,20 +70,20 @@ export class WsChatMethodsService {
});
console.log('this.group', this.group)
this.loadingWholeList = false
}
subscribeToRoom() {
for (const id in this.dm) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
// console.log('subscription', subscription)
console.log('streamRoomMessages', subscription)
})
}
for (const id in this.group) {
this.WsChatService.streamRoomMessages(id).then((subscription)=>{
// console.log('subscription', subscription)
console.log('streamRoomMessages', subscription)
})
}
}
+18 -6
View File
@@ -74,13 +74,11 @@ export class WsChatService {
if(message.id == requestId ) { // same request send
if(message.result) {
console.log(message)
if(message.result.token) {
this.isLogin = true
this.loginResponse = message
console.log('wsMsgQueue', this.wsMsgQueue)
this.ws.wsMsgQueue()
resolve(message)
@@ -242,7 +240,7 @@ export class WsChatService {
* @param key
* @param funx
*/
receiveLiveMessageFromRoom(roomId, funx: Function) {
receiveMyMessageConfirmation(roomId, funx: Function) {
this.ws.registerCallback({
type:'Onmessage',
@@ -261,6 +259,21 @@ export class WsChatService {
}
receiveLiveMessageFromRoom(roomId, funx: Function) {
this.ws.registerCallback({
type:'Onmessage',
funx:(message)=>{
if(message.msg =='changed' && message.collection == 'stream-room-messages') {
if(message.fields.args[0].rid == roomId) {
funx(message)
}
}
}
})
}
streamRoomMessages(roomId : string) {
const requestId = uuidv4()
@@ -270,7 +283,7 @@ export class WsChatService {
"id": requestId,
"name": "stream-room-messages",
"params":[
`${roomId}/event`,
`${roomId}`,
false
]
}
@@ -279,7 +292,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.msg == 'ready' || deepFind(message, 'subs.0') == requestId) { // same request send
if(message.id == requestId) { // same request send
resolve(message)
return true
}
@@ -375,7 +388,6 @@ export class WsChatService {
},
onmessage:(event: any)=> {
// if(this.ws.connected == false) { return true }
const data = JSON.parse(event.data)
for (const [key, value] of Object.entries(this.wsCallbacks)) {