mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
save
This commit is contained in:
@@ -21,6 +21,9 @@ import { NewchatPage } from './newchat/newchat.page';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { AlertService } from 'src/app/services/alert.service';
|
||||
import { EditGroupPage } from 'src/app/shared/chat/edit-group/edit-group.page';
|
||||
import * as Rx from "rxjs/Rx";
|
||||
import { Message } from 'src/app/models/message.model';
|
||||
import { Observable, Subject } from "rxjs/Rx";
|
||||
|
||||
@Component({
|
||||
selector: 'app-chat',
|
||||
@@ -78,8 +81,15 @@ export class ChatPage implements OnInit {
|
||||
|
||||
*/
|
||||
|
||||
SERVER_URL = 'wss://www.tabularium.pt/websocket';
|
||||
ws:any;
|
||||
subject: any;
|
||||
public messages: Subject<any>;
|
||||
|
||||
message = {
|
||||
"msg": "connect",
|
||||
"version": "1",
|
||||
"support": ["1"]
|
||||
};
|
||||
|
||||
|
||||
/* Fim websockets variables*/
|
||||
constructor(
|
||||
@@ -89,12 +99,13 @@ export class ChatPage implements OnInit {
|
||||
private authService: AuthService,
|
||||
private storage:Storage,
|
||||
private resolver: ComponentFactoryResolver,
|
||||
|
||||
) {
|
||||
){
|
||||
this.headers = new HttpHeaders();
|
||||
/* this.headers = this.headers.set('X-User-Id', 'GqjNWiLrGEHRna7Zn');
|
||||
this.headers = this.headers.set('X-Auth-Token', 'SJwIgtlqfloPK696fpc2VBvyDluipuIHKB_0Q6-9ycJ'); */
|
||||
chatService.messages.subscribe(msg => {
|
||||
console.log("Response from websocket: " + msg);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.segment = "Contactos";
|
||||
|
||||
@@ -103,49 +114,16 @@ export class ChatPage implements OnInit {
|
||||
console.log(this.loggedUser);
|
||||
this.load();
|
||||
});
|
||||
this.storage.get('userDataKey').then(val=> {
|
||||
let t = JSON.parse(unescape(atob(val)));
|
||||
this.loggedUser=t;
|
||||
//this.load();
|
||||
})
|
||||
|
||||
console.log(this.roomId);
|
||||
this.connect();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* websocket functions */
|
||||
connect() {
|
||||
this.ws = new WebSocket(this.SERVER_URL, []);
|
||||
console.log(this.ws);
|
||||
|
||||
/* this.ws.onmessage = handleMessageReceived;
|
||||
this.ws.onerror = handleError; */
|
||||
}
|
||||
handleMessageReceived(data) {
|
||||
// Simply call logMessage(), passing the received data.
|
||||
/* logMessage(data.data); */
|
||||
}
|
||||
handleConnected(data) {
|
||||
// Create a log message which explains what has happened and includes
|
||||
// the url we have connected too.
|
||||
var logMsg = 'Connected to server: ' + data.target.url;
|
||||
// Add the message to the log.
|
||||
/* logMessage(logMsg) */
|
||||
}
|
||||
handleError(err) {
|
||||
// Print the error to the console so we can debug it.
|
||||
console.log("Error: ", err);
|
||||
}
|
||||
logMessage(msg) {
|
||||
// $apply() ensures that the elements on the page are updated
|
||||
// with the new message.
|
||||
/* $scope.$apply(function() { */
|
||||
//Append out new message to our message log. The \n means new line.
|
||||
/* $scope.messageLog = $scope.messageLog + msg + "\n"; */
|
||||
// Update the scrolling (defined below).
|
||||
/*updateScrolling();*/
|
||||
/* S */
|
||||
//this.sendMsg();
|
||||
|
||||
/* Fim websocket functions */
|
||||
}
|
||||
sendMsg() {
|
||||
console.log("new message from client to websocket: ", this.message);
|
||||
this.chatService.messages.next(this.message);
|
||||
this.message.msg = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +156,7 @@ export class ChatPage implements OnInit {
|
||||
}
|
||||
openMessagesPage(rid) {
|
||||
if( window.innerWidth <= 1024){
|
||||
this.openMessagesModal(rid);
|
||||
//this.openMessagesModal(rid);
|
||||
}
|
||||
else{
|
||||
this.closeAllDesktopComponents();
|
||||
@@ -236,9 +214,8 @@ export class ChatPage implements OnInit {
|
||||
onSegmentChange(){
|
||||
this.load();
|
||||
}
|
||||
doRefresh(ev:any){
|
||||
doRefresh(){
|
||||
this.load();
|
||||
ev.target.complete();
|
||||
}
|
||||
load(){
|
||||
switch (this.segment)
|
||||
@@ -310,6 +287,7 @@ export class ChatPage implements OnInit {
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
async selectContact(){
|
||||
const modal = await this.modalController.create({
|
||||
component: ContactsPage,
|
||||
@@ -318,6 +296,7 @@ export class ChatPage implements OnInit {
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
async newGroup(){
|
||||
const modal = await this.modalController.create({
|
||||
component: NewGroupPage,
|
||||
@@ -383,4 +362,5 @@ export class ChatPage implements OnInit {
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user