diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 17ba9ebc9..6eccec89d 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -99,6 +99,12 @@ export class HomePage implements OnInit { //this.RocketChatClientService.send('fsMwcNdufWvdnChj7ya9nF9cX2HizxxWAM', 'Mensagem enviada programaticamente.'+ new Date().toISOString()) } + + this.RocketChatClientService.registerCallback({type:'Onmessage',requestId:'asdfasdfasdf',funx:(message)=>{ + // console.log('message', message) + }}) + + // this.RocketChatClientService.send() /* this.webNotificationPopupService.askNotificationPermission() */ diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index c73acf6c0..8a2dca3eb 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -48,7 +48,7 @@
@@ -89,7 +89,7 @@
- +
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index cc0c2e704..feb69f724 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -12,7 +12,7 @@ import { import { ModalController, Platform } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; import { ChatService } from 'src/app/services/chat.service'; -import { ChatService as ChatServiceGPR} from 'src/app/services/chat/chat.service' +import { wsChatService as wsChatService} from 'src/app/services/chat/chat.service' import { GroupMessagesPage } from './group-messages/group-messages.page'; import { ContactsPage } from './messages/contacts/contacts.page'; import { MessagesPage } from './messages/messages.page'; @@ -127,8 +127,7 @@ export class ChatPage implements OnInit { private sqlservice: SqliteService, private platform: Platform, private storageservice: StorageService, - public ChatServiceGPR: ChatServiceGPR, - private wsService: WebsocketService, + public wsChatService: wsChatService ) { @@ -144,9 +143,9 @@ export class ChatPage implements OnInit { console.log("CHAT PAGE"); - wsService.messages.subscribe(msg => { + /* wsService.messages.subscribe(msg => { console.log("Response from Websocket server: "+msg); - }); + }); */ this.load() } @@ -243,7 +242,7 @@ export class ChatPage implements OnInit { } */ - loadMessage(){ +/* loadMessage(){ this.wsService.messages.subscribe(msg => { console.log("Response from websocket: " + msg); }); @@ -253,7 +252,7 @@ export class ChatPage implements OnInit { this.wsService.messages.next(this.message); this.message.msg = ""; this.loadMessage(); - } + } */ /* Fim websockets functions */ diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 836d6ff58..693f1c0cc 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -49,7 +49,7 @@ -->
-
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index aee83350b..9939181c0 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -28,7 +28,7 @@ import { SqliteService } from 'src/app/services/sqlite.service'; import { elementAt } from 'rxjs-compat/operator/elementAt'; import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; import { ViewEventPage } from 'src/app/modals/view-event/view-event.page'; -import { ChatService as ChatServiceGPR} from 'src/app/services/chat/chat.service' +import { wsChatService as wsChatService} from 'src/app/services/chat/chat.service' const IMAGE_DIR = 'stored-images'; @@ -96,7 +96,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private changeDetectorRef: ChangeDetectorRef, private platform: Platform, private sqlservice: SqliteService, - public ChatServiceGPR: ChatServiceGPR + public wsChatService: wsChatService ) { this.loggedUser = authService.ValidatedUserChat['data']; this.roomId = this.navParams.get('roomId'); @@ -108,7 +108,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } }; - this.ChatServiceGPR.getRoom(this.roomId).loadHistory() + this.wsChatService.getRoom(this.roomId).loadHistory() } @@ -335,8 +335,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { window.removeEventListener('scroll', this.scrollChangeCallback, true); } - - sendMessage() { let body = { "message": diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 3678eed54..47746608b 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -43,7 +43,8 @@ export class AuthService { this.ValidatedUser = SessionStore.user console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password) - /* this.RocketChatClientService.connect(()=>{ + this.RocketChatClientService.connect(()=>{ + this.RocketChatClientService.login({ username: SessionStore.user.RochetChatUser, password: SessionStore.user.Password @@ -52,7 +53,8 @@ export class AuthService { }).catch((message)=>{ console.log('rocket chat login failed', message) }) - }) */ + + }) } diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts index 501c26195..4b87fa4d7 100644 --- a/src/app/services/chat/chat.service.ts +++ b/src/app/services/chat/chat.service.ts @@ -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; diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 47c0c09cc..cf1b39a98 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -31,4 +31,7 @@ export class MessageService { showDateDuration() {} + + + } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index ef85e84a0..2ce1f27b4 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -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) diff --git a/src/app/services/socket/rocket-chat-client.service.ts b/src/app/services/socket/rocket-chat-client.service.ts index 3f0fc0b01..e68256fae 100644 --- a/src/app/services/socket/rocket-chat-client.service.ts +++ b/src/app/services/socket/rocket-chat-client.service.ts @@ -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,17 +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() } @@ -63,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 { @@ -86,7 +75,7 @@ import { deepFind } from 'src/plugin/deep' } - getRooms() { + getRooms(roomOlder = 1480377601) { const requestId = uuidv4() @@ -279,6 +268,10 @@ import { deepFind } from 'src/plugin/deep' } + registerCallback(data:wsCallbacksParams) { + return this.ws.registerCallback(data) + } + // socket class ================================================================== private socket!: WebSocket; private wsUrl = '' diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 786a9c902..c7636b7c5 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -3,7 +3,7 @@
- {{users.name}} + {{ wsChatService.getRoom(roomId).name }}