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:
@@ -1,12 +1,14 @@
|
||||
import { HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from "rxjs"
|
||||
import { AuthService } from './auth.service';
|
||||
import { HttpService } from './http.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { HttpClient, HttpHeaderResponse } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { Message } from 'src/app/models/message.model';
|
||||
import { Observable, Subject } from "rxjs/Rx";
|
||||
import { WebsocketService } from './websocket.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -17,6 +19,9 @@ export class ChatService {
|
||||
options1:any;
|
||||
X_User_Id:any;
|
||||
X_Auth_Token:any;
|
||||
|
||||
SERVER_URL = 'wss://www.tabularium.pt/websocket';
|
||||
public messages: Subject<any>;
|
||||
|
||||
|
||||
constructor(
|
||||
@@ -24,11 +29,11 @@ export class ChatService {
|
||||
private httpService: HttpService,
|
||||
private authService: AuthService,
|
||||
private storage: Storage,
|
||||
private storageService:StorageService,) {
|
||||
private storageService:StorageService,
|
||||
private wsService: WebsocketService,
|
||||
)
|
||||
{
|
||||
this.headers = new HttpHeaders();
|
||||
/* this.headers = this.headers.set('X-User-Id', 'GqjNWiLrGEHRna7Zn');
|
||||
this.headers = this.headers.set('X-Auth-Token', 'dAM0ZOTAy8jzQA_vS25z2IrnSc6sYLfi5rmaa35YNUz'); */
|
||||
-
|
||||
this.authService.userData$.subscribe((res:any)=>{
|
||||
this.headers = this.headers.set('X-User-Id', res.userId);
|
||||
this.headers = this.headers.set('X-Auth-Token', res.authToken);
|
||||
@@ -36,6 +41,16 @@ export class ChatService {
|
||||
this.options = {
|
||||
headers: this.headers,
|
||||
};
|
||||
|
||||
this.messages = <Subject<any>>this.wsService.connect(this.SERVER_URL).map((response: MessageEvent): any => {
|
||||
let data = JSON.parse(response.data);
|
||||
console.log(data);
|
||||
|
||||
return {
|
||||
id: data.id,
|
||||
msg: data.msg
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/* getUser(){
|
||||
|
||||
Reference in New Issue
Block a user