Mercurial > hg > ugly-duckling
changeset 62:2171dd56756c
Use VampTestPlugin for now. Also set up Collect method calls for the worker. Currently use the same stream for both process and collect extraction.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 09 Dec 2016 14:06:04 +0000 |
parents | 8b8f794942d1 |
children | dc07ec243491 |
files | src/app/services/feature-extraction/FeatureExtractionWorker.ts src/app/services/feature-extraction/feature-extraction.service.ts |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/services/feature-extraction/FeatureExtractionWorker.ts Fri Dec 09 11:39:14 2016 +0000 +++ b/src/app/services/feature-extraction/FeatureExtractionWorker.ts Fri Dec 09 14:06:04 2016 +0000 @@ -5,6 +5,7 @@ import {ListResponse, EmscriptenProxy} from 'piper'; import {PiperSimpleClient} from 'piper/HigherLevelUtilities'; import { VampExamplePlugins } from 'piper/ext/VampExamplePluginsModule'; +import { VampTestPlugin } from 'piper/ext/VampTestPluginModule'; // TODO TypeScript has a .d.ts file for webworkers, but for some reason it clashes with the typings for dom and causes compiler errors @@ -23,7 +24,7 @@ constructor(workerScope: WorkerGlobalScope) { this.workerScope = workerScope; - this.piperClient = new PiperSimpleClient(new EmscriptenProxy(VampExamplePlugins())); + this.piperClient = new PiperSimpleClient(new EmscriptenProxy(VampTestPlugin())); this.workerScope.onmessage = (ev: MessageEvent) => { const sendResponse = (result) => this.workerScope.postMessage({ method: ev.data.method, @@ -35,6 +36,9 @@ break; case 'process': this.piperClient.process(ev.data.params).then(sendResponse); + break; + case 'collect': + this.piperClient.collect(ev.data.params).then(sendResponse); } }; }
--- a/src/app/services/feature-extraction/feature-extraction.service.ts Fri Dec 09 11:39:14 2016 +0000 +++ b/src/app/services/feature-extraction/feature-extraction.service.ts Fri Dec 09 14:06:04 2016 +0000 @@ -2,7 +2,7 @@ import { ListResponse, ListRequest } from "piper"; -import {SimpleRequest} from "piper/HigherLevelUtilities"; +import {SimpleRequest, FeatureCollection} from "piper/HigherLevelUtilities"; import {FeatureList} from "piper/Feature"; import {Subject} from "rxjs/Subject"; import {Observable} from "rxjs"; @@ -17,16 +17,18 @@ result: ResponseType; } +export type Extracted = FeatureList | FeatureCollection; + @Injectable() export class FeatureExtractionService { private worker: Worker; - private featuresExtracted: Subject<FeatureList>; - featuresExtracted$: Observable<FeatureList>; + private featuresExtracted: Subject<Extracted>; + featuresExtracted$: Observable<Extracted>; constructor() { this.worker = new Worker('bootstrap-feature-extraction-worker.js'); - this.featuresExtracted = new Subject<FeatureList>(); + this.featuresExtracted = new Subject<Extracted>(); this.featuresExtracted$ = this.featuresExtracted.asObservable(); } @@ -47,6 +49,16 @@ }); } + collect(request: SimpleRequest): Promise<FeatureCollection> { + return this.request<SimpleRequest, FeatureCollection>( + {method: 'collect', params: request}, + (ev: MessageEvent) => ev.data.method === 'collect' + ).then(msg => { + this.featuresExtracted.next(msg.result); + return msg.result; + }); + } + private request<Req, Res>(request: RequestMessage<Req>, predicate: (ev: MessageEvent) => boolean) : Promise<ResponseMessage<Res>> {