Skip to content
Snippets Groups Projects
Commit 281556b0 authored by Tom Käsler's avatar Tom Käsler
Browse files

add stomp to project

add feedback messages to communicate w/ backend
parent 0c064570
No related merge requests found
...@@ -24,6 +24,9 @@ import { LanguageService } from './services/util/language.service'; ...@@ -24,6 +24,9 @@ import { LanguageService } from './services/util/language.service';
import { MarkdownService, MarkedOptions } from 'ngx-markdown'; import { MarkdownService, MarkedOptions } from 'ngx-markdown';
import { NewLandingComponent } from './components/home/new-landing/new-landing.component'; import { NewLandingComponent } from './components/home/new-landing/new-landing.component';
import { HomePageComponent } from './components/home/home-page/home-page.component'; import { HomePageComponent } from './components/home/home-page/home-page.component';
import { InjectableRxStompConfig, RxStompService, rxStompServiceFactory } from '@stomp/ng2-stompjs';
import { myRxStompConfig } from './rx-stomp.config';
export function dialogClose(dialogResult: any) { export function dialogClose(dialogResult: any) {
} }
...@@ -54,6 +57,15 @@ export function dialogClose(dialogResult: any) { ...@@ -54,6 +57,15 @@ export function dialogClose(dialogResult: any) {
useClass: AuthenticationInterceptor, useClass: AuthenticationInterceptor,
multi: true multi: true
}, },
{
provide: InjectableRxStompConfig,
useValue: myRxStompConfig
},
{
provide: RxStompService,
useFactory: rxStompServiceFactory,
deps: [InjectableRxStompConfig]
},
NotificationService, NotificationService,
AuthenticationService, AuthenticationService,
AuthenticationGuard, AuthenticationGuard,
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthenticationService } from '../../../services/http/authentication.service'; import { AuthenticationService } from '../../../services/http/authentication.service';
import { UserRole } from '../../../models/user-roles.enum'; import { UserRole } from '../../../models/user-roles.enum';
import { NotificationService } from '../../../services/util/notification.service'; import { NotificationService } from '../../../services/util/notification.service';
import { RxStompService } from '@stomp/ng2-stompjs';
import { Message } from '@stomp/stompjs';
import { CreateFeedback } from '../../../models/messages/create-feedback';
import { GetFeedback } from '../../../models/messages/get-feedback';
/* ToDo: Use TranslateService */ /* ToDo: Use TranslateService */
...@@ -18,16 +23,29 @@ export class FeedbackBarometerPageComponent implements OnInit { ...@@ -18,16 +23,29 @@ export class FeedbackBarometerPageComponent implements OnInit {
{ state: 3, name: 'sentiment_very_dissatisfied', message: 'Abgehängt.', count: 0, } { state: 3, name: 'sentiment_very_dissatisfied', message: 'Abgehängt.', count: 0, }
]; ];
userRole: UserRole; userRole: UserRole;
roomId: string;
dummy = [2, 3, 2, 1]; // dummy data -> delete this with api implementation and add get-data
constructor( constructor(
private authenticationService: AuthenticationService, private authenticationService: AuthenticationService,
private notification: NotificationService, ) {} private notification: NotificationService,
private rxStompService: RxStompService,
private route: ActivatedRoute, ) {
this.roomId = this.route.snapshot.params.roomId;
}
ngOnInit() { ngOnInit() {
this.userRole = this.authenticationService.getRole(); this.userRole = this.authenticationService.getRole();
this.updateFeedback(this.dummy);
this.rxStompService.watch(`/room/${this.roomId}/feedback.stream`).subscribe((message: Message) => {
this.parseIncomingMessage(message);
});
const getFeedback = new GetFeedback();
this.rxStompService.publish({
destination: `/backend/room/${this.roomId}/feedback.query`,
body: JSON.stringify(getFeedback)
});
} }
private updateFeedback(data) { private updateFeedback(data) {
...@@ -38,10 +56,12 @@ export class FeedbackBarometerPageComponent implements OnInit { ...@@ -38,10 +56,12 @@ export class FeedbackBarometerPageComponent implements OnInit {
} }
} }
submitFeedback(state: string) { submitFeedback(state: number) {
this.dummy[state] += 1; // delete this with api implementation and add submit-data const createFeedback = new CreateFeedback(state);
this.updateFeedback(this.dummy); this.rxStompService.publish({
this.notification.show(`Feedback submitted to room.`); destination: `/backend/room/${this.roomId}/feedback.command`,
body: JSON.stringify(createFeedback)
});
} }
toggle() { toggle() {
...@@ -49,4 +69,9 @@ export class FeedbackBarometerPageComponent implements OnInit { ...@@ -49,4 +69,9 @@ export class FeedbackBarometerPageComponent implements OnInit {
const temp = 'stopped'; // add status variable const temp = 'stopped'; // add status variable
this.notification.show(`Feedback transmission ${ temp }.`); this.notification.show(`Feedback transmission ${ temp }.`);
} }
parseIncomingMessage(message: Message) {
const values = JSON.parse(message.body).payload.values;
this.updateFeedback(values);
}
} }
export class CreateFeedback {
type: string;
payload: {
value: number;
};
constructor(val: number) {
this.type = 'CreateFeedback';
this.payload = {
value: val
};
}
}
export class GetFeedback {
type: string;
constructor() {
this.type = 'GetFeedback';
}
}
import { InjectableRxStompConfig } from '@stomp/ng2-stompjs';
export const myRxStompConfig: InjectableRxStompConfig = {
// Which server?
brokerURL: `ws://${window.location.hostname}:8080/ws/websocket`,
// How often to heartbeat?
// Interval in milliseconds, set to 0 to disable
heartbeatIncoming: 0, // Typical value 0 - disabled
heartbeatOutgoing: 20000, // Typical value 20000 - every 20 seconds
// Wait in milliseconds before attempting auto reconnect
// Set to 0 to disable
// Typical value 500 (500 milli seconds)
reconnectDelay: 1000,
// Will log diagnostics on console
// It can be quite verbose, not recommended in production
// Skip this key to stop logging to console
debug: (msg: string): void => {
// console.log(new Date(), 'STOMP debug: ' + msg);
}
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment