Updates components to work with GCT

This commit is contained in:
GloriousCode
2017-09-04 20:06:07 +10:00
parent e193258710
commit fcefa80cc8
4 changed files with 23 additions and 16 deletions

View File

@@ -5,8 +5,8 @@ import { WebsocketService } from './websocket/websocket.service';
const CHAT_URL = 'ws://localhost:9050/ws';
export interface Message {
author: string,
message: string
Event: string,
data:object,
}
@Injectable()
@@ -19,8 +19,8 @@ export class ChatService {
.map((response: MessageEvent): Message => {
let data = JSON.parse(response.data);
return {
author: data.author,
message: data.message
Event: data.Event,
data: data.data,
}
});
}

View File

@@ -17,12 +17,12 @@ export class WebsocketService {
private create(url): Rx.Subject<MessageEvent> {
let ws = new WebSocket(url);
let observable = Rx.Observable.create(
(obs: Rx.Observer<MessageEvent>) => {
ws.onmessage = obs.next.bind(obs);
ws.onerror = obs.error.bind(obs);
ws.onclose = obs.complete.bind(obs);
ws.onclose = obs.complete.bind(obs);
return ws.close.bind(ws);
})
let observer = {

View File

@@ -1 +1,2 @@
<button (click)="sendMsg()">Send Message via websocket</button>
<button (click)="authenticate()">Authenticate</button>
<button (click)="getSettings()">Get Settings</button>

View File

@@ -17,18 +17,24 @@ export class ChatbuttonComponent implements OnInit {
ngOnInit() {
}
private message = {
author: 'tutorialedge',
message: 'this is a test message',
private getSettingsMessage = {
Event:'GetConfig',
data:null,
}
private authenticateMessage = {
Event:'auth',
username:'user',
password:'password'
data:{"username":"username","password":"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"},
}
authenticate():void {
console.log('new message from client to websocket: ', this.authenticateMessage);
this.chatService.messages.next(this.authenticateMessage);
}
sendMsg():void {
console.log('new message from client to websocket: ', this.message);
this.chatService.messages.next(this.message);
this.message.message = '';
getSettings():void {
console.log('new message from client to websocket: ', this.getSettingsMessage);
this.chatService.messages.next(this.getSettingsMessage);
}
}