renamed sse endpoint to events. Using the technology name in the API isnt a good idea.
This commit is contained in:
parent
6a3afe150e
commit
74fc682dbf
|
@ -79,7 +79,7 @@ func (ae *AppEngine) Setup() (*gin.RouterGroup, *gin.Engine) {
|
||||||
secure.POST("/query", handler.QueryResourceFhir)
|
secure.POST("/query", handler.QueryResourceFhir)
|
||||||
|
|
||||||
//server-side-events handler
|
//server-side-events handler
|
||||||
secure.GET("/sse/stream", middleware.SSEHeaderMiddleware(), middleware.SSEEventBusServerMiddleware(), handler.SSEStream)
|
secure.GET("/events/stream", middleware.SSEHeaderMiddleware(), middleware.SSEEventBusServerMiddleware(), handler.SSEStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ae.Config.GetBool("web.allow_unsafe_endpoints") {
|
if ae.Config.GetBool("web.allow_unsafe_endpoints") {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import {Component, OnInit, TemplateRef} from '@angular/core';
|
import {Component, OnInit, TemplateRef} from '@angular/core';
|
||||||
import {ToastService} from '../../services/toast.service';
|
import {ToastService} from '../../services/toast.service';
|
||||||
|
import {AuthService} from '../../services/auth.service';
|
||||||
|
import {FastenApiService} from '../../services/fasten-api.service';
|
||||||
|
import {Subscription} from 'rxjs';
|
||||||
|
import {NavigationEnd, Router} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-toast',
|
selector: 'app-toast',
|
||||||
|
@ -7,9 +11,33 @@ import {ToastService} from '../../services/toast.service';
|
||||||
styleUrls: ['./toast.component.scss']
|
styleUrls: ['./toast.component.scss']
|
||||||
})
|
})
|
||||||
export class ToastComponent implements OnInit {
|
export class ToastComponent implements OnInit {
|
||||||
|
routerSubscription: Subscription | undefined;
|
||||||
|
|
||||||
constructor(public toastService: ToastService) {}
|
constructor(
|
||||||
|
public router: Router,
|
||||||
|
public toastService: ToastService,
|
||||||
|
public authService: AuthService,
|
||||||
|
public fastenApiService: FastenApiService,
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
ngAfterViewInit() {
|
||||||
|
//TODO: this is a bit kludgey.
|
||||||
|
// Ideally we want consistently listen to events, but only when the user is authenticated.
|
||||||
|
this.routerSubscription = this.router.events.subscribe((event) => {
|
||||||
|
if (event instanceof NavigationEnd) {
|
||||||
|
if(!event.url.startsWith("/auth") && this.authService.IsAuthenticated()){
|
||||||
|
console.log("user is authenticated, listening for notifications")
|
||||||
|
//user is authenticated, lets start listening for notifications
|
||||||
|
this.routerSubscription?.unsubscribe()
|
||||||
|
this.fastenApiService.listenEventBus().subscribe((event)=>{
|
||||||
|
console.log("eventbus event:", event)
|
||||||
|
//TODO: start toasts.
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import * as fhirpath from 'fhirpath';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {DashboardConfig} from '../models/widget/dashboard-config';
|
import {DashboardConfig} from '../models/widget/dashboard-config';
|
||||||
import {DashboardWidgetQuery} from '../models/widget/dashboard-widget-query';
|
import {DashboardWidgetQuery} from '../models/widget/dashboard-widget-query';
|
||||||
|
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -54,6 +55,29 @@ export class FastenApiService {
|
||||||
SECURE ENDPOINTS
|
SECURE ENDPOINTS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
listenEventBus(): Observable<any> {
|
||||||
|
let eventStreamUrl = `${GetEndpointAbsolutePath(globalThis.location, environment.fasten_api_endpoint_base)}/secure/events/stream`
|
||||||
|
|
||||||
|
return new Observable(observer => {
|
||||||
|
fetchEventSource(eventStreamUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${this.authService.GetAuthToken()}`
|
||||||
|
},
|
||||||
|
onmessage(ev) {
|
||||||
|
observer.next(ev.data);
|
||||||
|
},
|
||||||
|
onerror(event) {
|
||||||
|
observer.error(event)
|
||||||
|
},
|
||||||
|
}).then(
|
||||||
|
() => observer.complete(),
|
||||||
|
error => observer.error(error)
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getDashboards(): Observable<DashboardConfig[]> {
|
getDashboards(): Observable<DashboardConfig[]> {
|
||||||
return this._httpClient.get<any>(`${GetEndpointAbsolutePath(globalThis.location, environment.fasten_api_endpoint_base)}/secure/dashboards`, )
|
return this._httpClient.get<any>(`${GetEndpointAbsolutePath(globalThis.location, environment.fasten_api_endpoint_base)}/secure/dashboards`, )
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|
Loading…
Reference in New Issue