Make WS work with Auth
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { RxStompService } from './rx-stomp.service';
|
||||
import { rxStompConfig } from './rx-stomp.config';
|
||||
import { createRxStompConfig } from './rx-stomp.config';
|
||||
import {AuthService} from '../../core/service/auth.service';
|
||||
|
||||
export function rxStompServiceFactory() {
|
||||
const rxStomp = new RxStompService();
|
||||
rxStomp.configure(rxStompConfig);
|
||||
rxStomp.activate();
|
||||
export function rxStompServiceFactory(authService: AuthService) {
|
||||
const rxStomp = new RxStompService(authService);
|
||||
const stompConfig = createRxStompConfig(authService);
|
||||
rxStomp.configure(stompConfig);
|
||||
return rxStomp;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,18 @@
|
||||
import {RxStompConfig} from '@stomp/rx-stomp';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import { RxStompConfig } from '@stomp/rx-stomp';
|
||||
import { API_CONFIG } from '../../config/api-config';
|
||||
import {AuthService} from '../../core/service/auth.service';
|
||||
|
||||
export const rxStompConfig: RxStompConfig = {
|
||||
// Which server?
|
||||
brokerURL: API_CONFIG.BROKER_URL,
|
||||
|
||||
// Headers
|
||||
// Typical keys: login, passcode, host
|
||||
connectHeaders: {
|
||||
login: 'guest',
|
||||
passcode: 'guest',
|
||||
},
|
||||
|
||||
// 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: 200,
|
||||
|
||||
// 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(), msg);
|
||||
},
|
||||
};
|
||||
export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||
return {
|
||||
brokerURL: API_CONFIG.BROKER_URL,
|
||||
connectHeaders: {
|
||||
Authorization: `Bearer ${authService.getToken()}`,
|
||||
},
|
||||
heartbeatIncoming: 0,
|
||||
heartbeatOutgoing: 20000,
|
||||
reconnectDelay: 200,
|
||||
debug: (msg: string): void => {
|
||||
//console.log(new Date(), msg);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RxStomp } from '@stomp/rx-stomp';
|
||||
import { AuthService } from '../../core/service/auth.service';
|
||||
import { createRxStompConfig } from './rx-stomp.config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RxStompService extends RxStomp {
|
||||
|
||||
constructor() {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
const stompConfig = createRxStompConfig(this.authService);
|
||||
this.configure(stompConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user