Client redirects via event.octant.dev/contentPath events
The server can emit `event.octant.dev/contentPath` events, which are
effectively redirects to a different path. If the current path is not
the contentPath in the event, navigate to the new path.
*/
import { Injectable } from '@angular/core';
+import { Router } from '@angular/router';
import {
BehaviorSubject,
ObjectUnsubscribedError,
@@ -62,8 +63,11 @@ export class WebsocketService implements BackendService {
private connectSignalID = new BehaviorSubject<string>('');
private opened = false;
- constructor(notifierService: NotifierService) {
+ private router: Router;
+
+ constructor(notifierService: NotifierService, router: Router) {
this.notifierSession = notifierService.createSession();
+ this.router = router;
this.registerHandler('event.octant.dev/alert', data => {
const alert = data as Alert;
@@ -77,6 +81,14 @@ export class WebsocketService implements BackendService {
}, diff);
}
});
+
+ this.registerHandler('event.octant.dev/contentPath', data => {
+ const payload = data as { contentPath: string };
+ const contentPath = payload.contentPath || '/';
+ if (this.router.url !== contentPath) {
+ this.router.navigateByUrl(contentPath);
+ }
+ });
}
registerHandler(name: string, handler: (data: {}) => void): () => void {
