mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-21 07:26:48 +00:00
A hubub of code to test websockets. To remove and refine
This commit is contained in:
1
web/src/app/shared/chatbutton/chatbutton.component.html
Normal file
1
web/src/app/shared/chatbutton/chatbutton.component.html
Normal file
@@ -0,0 +1 @@
|
||||
<button (click)="sendMsg()">Send Message via websocket</button>
|
||||
25
web/src/app/shared/chatbutton/chatbutton.component.spec.ts
Normal file
25
web/src/app/shared/chatbutton/chatbutton.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatbuttonComponent } from './chatbutton.component';
|
||||
|
||||
describe('ChatbuttonComponent', () => {
|
||||
let component: ChatbuttonComponent;
|
||||
let fixture: ComponentFixture<ChatbuttonComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ChatbuttonComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ChatbuttonComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
34
web/src/app/shared/chatbutton/chatbutton.component.ts
Normal file
34
web/src/app/shared/chatbutton/chatbutton.component.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ChatService } from './../../services/chat.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-chatbutton',
|
||||
templateUrl: './chatbutton.component.html',
|
||||
styleUrls: ['./chatbutton.component.scss']
|
||||
})
|
||||
export class ChatbuttonComponent implements OnInit {
|
||||
|
||||
constructor(private chatService: ChatService) {
|
||||
chatService.messages.subscribe(msg => {
|
||||
console.log("Response from websocket: " + JSON.stringify(msg));
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
private message = {
|
||||
author: 'tutorialedge',
|
||||
message: 'this is a test message',
|
||||
Event:'auth',
|
||||
username:'user',
|
||||
password:'password'
|
||||
}
|
||||
|
||||
sendMsg():void {
|
||||
console.log('new message from client to websocket: ', this.message);
|
||||
this.chatService.messages.next(this.message);
|
||||
this.message.message = '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user