diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 01984a5..704b745 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -24,8 +24,9 @@ import { ConfigReadyService, IdeConfigService, DashboardConfigService, - SiteConfigService + SiteConfigService, } from './services/config.service'; +import { FSMUpdateService } from './services/fsmupdate.service'; import { LoaderComponent } from './loader/loader.component'; @@ -59,7 +60,8 @@ import { LoaderComponent } from './loader/loader.component'; ConfigReadyService, IdeConfigService, DashboardConfigService, - SiteConfigService + SiteConfigService, + FSMUpdateService ], bootstrap: [ AppComponent diff --git a/src/app/console/console.component.ts b/src/app/console/console.component.ts index 5c07a78..ae2dd96 100644 --- a/src/app/console/console.component.ts +++ b/src/app/console/console.component.ts @@ -22,7 +22,7 @@ export class ConsoleComponent implements OnInit { ngOnInit() { this.webSocketService.connect(); - this.webSocketService.observeKey('console').subscribe( + this.webSocketService.observeControl('console').subscribe( message => this.command_handlers[message.key](message) ); } diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index d445b81..3faf602 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -6,6 +6,7 @@ import { WebSocketMessage } from '../message-types/websocket-message'; import { DashboardConfigService } from '../services/config.service'; import { HttpClient } from '@angular/common/http'; import { delay, retryWhen, tap } from 'rxjs/operators'; +import { FSMUpdateService } from '../services/fsmupdate.service'; @Component({ selector: 'app-dashboard', @@ -37,11 +38,13 @@ export class DashboardComponent implements OnInit, OnDestroy { private webSocketService: WebSocketService, private changeDetectorRef: ChangeDetectorRef, private http: HttpClient, - private configService: DashboardConfigService) {} + private configService: DashboardConfigService, + private fsmUpdateService: FSMUpdateService) {} ngOnInit() { this.webSocketService.connect(); this.configService.init(); + this.subscribeCheckSolution(); this.hideIframeUntilResponseOk(); this.subscribeResizeOnLayoutChange(); this.initCommandHandling(); @@ -49,6 +52,15 @@ export class DashboardComponent implements OnInit, OnDestroy { this.sendReady(); } + subscribeCheckSolution() { + this.fsmUpdateService.init(); + this.fsmUpdateService.in_accepted_state.subscribe(in_accepted_state => { + if (in_accepted_state) { + window.parent.postMessage('check solution', '*'); + } + }); + } + hideIframeUntilResponseOk() { // TODO: hide iframe and show it after this whole deal... this.reloadIframeWhenResponseOk(); @@ -62,7 +74,7 @@ export class DashboardComponent implements OnInit, OnDestroy { } initCommandHandling() { - this.webSocketService.observeKey('dashboard').subscribe(message => { + this.webSocketService.observeControl('dashboard').subscribe(message => { this.command_handlers[message.key](message); this.changeDetectorRef.detectChanges(); }); diff --git a/src/app/ide/ide.component.ts b/src/app/ide/ide.component.ts index 1a6b8c4..d64b0e4 100644 --- a/src/app/ide/ide.component.ts +++ b/src/app/ide/ide.component.ts @@ -67,18 +67,18 @@ export class IdeComponent implements OnInit { } subscribeWS() { - this.webSocketService.observeKey('ide').subscribe(message => { + this.webSocketService.observeControl('ide').subscribe(message => { this.command_handlers[message.key](message); this.changeDetectorRef.detectChanges(); }); - this.webSocketService.observeKey('deploy.finish').subscribe( + this.webSocketService.observeControl('deploy.finish').subscribe( message => this.deployHandler(message) ); } subscribeFirstLanguageDetection() { - this.webSocketService.observeKey('ide.read').pipe(first()).subscribe( + this.webSocketService.observeControl('ide.read').pipe(first()).subscribe( () => this.autoDetectEditorLanguage(this.filename) ); } diff --git a/src/app/message-types/fsm-update-message.ts b/src/app/message-types/fsm-update-message.ts new file mode 100644 index 0000000..3cb840c --- /dev/null +++ b/src/app/message-types/fsm-update-message.ts @@ -0,0 +1,6 @@ +import { WebSocketMessage } from './websocket-message'; + +export interface FSMUpdateMessage extends WebSocketMessage { + current_state: string; + in_accepted_state: boolean; +} diff --git a/src/app/messages/messages.component.ts b/src/app/messages/messages.component.ts index ecb7866..9600c1a 100644 --- a/src/app/messages/messages.component.ts +++ b/src/app/messages/messages.component.ts @@ -30,7 +30,7 @@ export class MessagesComponent implements OnInit { }); this.websocketService.connect(); - this.websocketService.observeKey('message.send').subscribe( + this.websocketService.observeControl('message.send').subscribe( message => this.newMessage.next(message) ); } diff --git a/src/app/services/config.service.base.ts b/src/app/services/config.service.base.ts index b0e4d2f..c32e47b 100644 --- a/src/app/services/config.service.base.ts +++ b/src/app/services/config.service.base.ts @@ -36,7 +36,7 @@ export abstract class ConfigServiceBase { subscribeConfigKeys() { this.webSocketService.connect(); this.keys.forEach(key => - this.webSocketService.observeKey(key).subscribe(this.handleConfig.bind(this)) + this.webSocketService.observeControl(key).subscribe(this.handleConfig.bind(this)) ); } diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index 30b638e..e28be78 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -70,7 +70,7 @@ export class ConfigReadyService { const recvdConfigDone = new Subject(); this.readyNotifiers.push(recvdConfigDone); - this.webSocketService.observeKey('frontend.ready').subscribe(() => { + this.webSocketService.observeControl('frontend.ready').subscribe(() => { recvdConfigDone.next(); recvdConfigDone.complete(); }); diff --git a/src/app/services/fsmupdate.service.ts b/src/app/services/fsmupdate.service.ts new file mode 100644 index 0000000..3d229af --- /dev/null +++ b/src/app/services/fsmupdate.service.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@angular/core'; +import { WebSocketService } from './websocket.service'; +import { FSMUpdateMessage } from '../message-types/fsm-update-message'; +import { Subject } from 'rxjs'; + +@Injectable() +export class FSMUpdateService { + public current_state = new Subject(); + public in_accepted_state = new Subject(); + + constructor(private websocketService: WebSocketService) {} + + public init() { + this.websocketService.connect(); + this.websocketService.observeAll('fsm.update').subscribe((message) => { + this.current_state.next(message.current_state); + this.in_accepted_state.next(message.in_accepted_state); + }); + } +} diff --git a/src/app/services/websocket.service.ts b/src/app/services/websocket.service.ts index ace7edf..353d2cc 100644 --- a/src/app/services/websocket.service.ts +++ b/src/app/services/websocket.service.ts @@ -28,10 +28,15 @@ export class WebSocketService { } } - public observeKey(key: string): Observable { + public observeControl(key: string): Observable { + return this.observeAll(key).pipe( + filter(message => message.intent !== Intent.EVENT) + ); + } + + public observeAll(key: string): Observable { return this.ws.pipe( filter(message => message.key.startsWith(key)), - filter(message => message.intent !== Intent.EVENT), map(message => message) ); } diff --git a/src/app/testmessenger/testmessenger.component.ts b/src/app/testmessenger/testmessenger.component.ts index 9a4d42f..147ebf5 100644 --- a/src/app/testmessenger/testmessenger.component.ts +++ b/src/app/testmessenger/testmessenger.component.ts @@ -13,7 +13,7 @@ export class TestmessengerComponent implements OnInit { ngOnInit() { this.webSocketService.connect(); - this.webSocketService.observeKey('').subscribe(); + this.webSocketService.observeControl('').subscribe(); } sendTestMessage() {