mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
Update
This commit is contained in:
@@ -6,6 +6,7 @@ import { ContactsPage } from 'src/app/pages/chat/messages/contacts/contacts.page
|
||||
import { AlertService } from 'src/app/services/alert.service';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { connection } from 'src/app/services/socket/synchro.service';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { ChatOptionsPopoverPage } from 'src/app/shared/popover/chat-options-popover/chat-options-popover.page';
|
||||
import { MessagesOptionsPage } from 'src/app/shared/popover/messages-options/messages-options.page';
|
||||
@@ -29,6 +30,7 @@ export class MessagesPage implements OnInit, AfterViewChecked {
|
||||
roomId:string;
|
||||
el:any;
|
||||
|
||||
connection = connection
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
@@ -187,7 +189,7 @@ async openChatOptions(ev?: any) {
|
||||
//this.loadMessages()
|
||||
await this.serverLongPull();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,24 @@ export class SynchroService {
|
||||
private id: string = uuidv4();
|
||||
public conected = false
|
||||
private url: string = ''
|
||||
callback = function(){}
|
||||
|
||||
constructor(){}
|
||||
|
||||
setUrl(wss:wss) {
|
||||
setUrl() {
|
||||
|
||||
let header ={
|
||||
id:'1234',
|
||||
bluePrint: '12312123',
|
||||
jwt: uuidv4()
|
||||
}
|
||||
|
||||
let wss: wss ={
|
||||
header,
|
||||
url: 'wss://synchro-server.herokuapp.com/ws/some_url/',
|
||||
type: 'reflect'
|
||||
}
|
||||
|
||||
this.url = `${wss.url}${wss.header.id}/${wss.header.jwt}/${wss.header.bluePrint}/${this.id}/`
|
||||
}
|
||||
|
||||
@@ -42,19 +56,28 @@ export class SynchroService {
|
||||
|
||||
private onopen = () =>{
|
||||
console.log('open ======================= welcome to socket server')
|
||||
// this.connection.send(JSON.stringify({user:'user1'}));
|
||||
|
||||
}
|
||||
|
||||
public $send = (object: any) => {
|
||||
let sendData = JSON.stringify(Object.assign({}, object));
|
||||
public $send(object: any) {
|
||||
|
||||
let message = {
|
||||
message: '{"person.adress.country":"1Angola"}',
|
||||
username: '',
|
||||
idConnection: this.id
|
||||
}
|
||||
|
||||
let sendData = JSON.stringify(Object.assign({}, message));
|
||||
|
||||
this.connection.send(sendData);
|
||||
}
|
||||
|
||||
private onmessage = async (event: any)=> {
|
||||
|
||||
// alert('message')
|
||||
this.callback()
|
||||
}
|
||||
|
||||
private onclose=(event:any)=>{
|
||||
private onclose=(event:any)=> {
|
||||
setTimeout(() => {
|
||||
if (event.wasClean) {
|
||||
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
||||
@@ -72,3 +95,8 @@ export class SynchroService {
|
||||
console.log(`[error] ${event.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const connection = new SynchroService()
|
||||
connection.setUrl()
|
||||
connection.connect()
|
||||
@@ -10,6 +10,7 @@ import { MessagesOptionsPage } from 'src/app/shared/popover/messages-options/mes
|
||||
import { ProfileComponent } from '../../headers/header-no-search/profile/profile.page';
|
||||
import { ContactsPage } from '../new-group/contacts/contacts.page';
|
||||
import { Router } from '@angular/router';
|
||||
import { connection } from 'src/app/services/socket/synchro.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-messages',
|
||||
@@ -33,6 +34,9 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
|
||||
@Input() roomId:string;
|
||||
@Input() showMessages:string;
|
||||
|
||||
|
||||
connection = connection
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -46,6 +50,21 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
|
||||
|
||||
|
||||
this.connection.callback = function() {
|
||||
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
|
||||
|
||||
if (res == 502) {
|
||||
|
||||
} else if (res != 200) {
|
||||
this.messages = res['messages'].reverse();
|
||||
console.log(this.messages);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* this.dm = this.navParams.get('dm'); */
|
||||
}
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
@@ -103,7 +122,9 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(){
|
||||
sendMessage() {
|
||||
|
||||
this.connection.$send({})
|
||||
|
||||
let body = {
|
||||
"message":
|
||||
@@ -292,7 +313,8 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
|
||||
return await modal.present();
|
||||
}
|
||||
|
||||
async serverLongPull(){
|
||||
async serverLongPull() {
|
||||
|
||||
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
|
||||
|
||||
if (res == 502) {
|
||||
|
||||
Reference in New Issue
Block a user