mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 23:16:48 +00:00
Updates components to work with GCT
This commit is contained in:
@@ -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,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<button (click)="sendMsg()">Send Message via websocket</button>
|
||||
<button (click)="authenticate()">Authenticate</button>
|
||||
<button (click)="getSettings()">Get Settings</button>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user