Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
- private messageSubject$ = new BehaviorSubject<string>('default message');
- // Connecting to WebSocket found in Spring Boot MS. Also checkout polyfill.ts
- connect(user: string, password: string) {
- console.log('Inside Connect. Guest and Password: ' + user + ' ' + password);
- const socket = new SockJs('http://localhost:8080/football-ws');
- this.stompClient = Stomp.over(socket);
- this.stompClient.connect(user, password, this.onConnected);
- console.log('Attempting to connect!');
- }
- onConnected = (frame: any) => {
- console.log('Frame: ' + frame);
- this.stompClient.subscribe('/topic/public', this.onMessageReceived);
- }
- onMessageReceived(message: any) {
- console.log('Message Received from MS: ' + message);
- try {
- this.messageSubject$.next(message.body);
- } catch (e) {
- console.log('Error: ' + e);
- }
- }
- getMessageSubject() {
- return this.messageSubject$.asObservable();
- }
- this.stompClient.connect(user, password, (frame: any) => this.onConnected(frame));
- this.stompClient.subscribe('/topic/public', (message: any) => this.onMessageReceived(message));
- this.stompClient.connect(user, password, (frame: any) => {
- console.log('Frame: ' + frame);
- this.stompClient.subscribe('/topic/public', (message: any) => {
- console.log('Message Received from MS: ' + message);
- try {
- this.messageSubject$.next(message.body);
- } catch (e) {
- console.log('Error: ' + e);
- }
- });
- });
Add Comment
Please, Sign In to add comment