Mercurial > hg > ugly-duckling
annotate src/app/services/feature-extraction/FeatureExtractionWorker.ts @ 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 | 933c64ebcd13 |
children | 270f59ef3b83 |
rev | line source |
---|---|
dev@40 | 1 /** |
dev@40 | 2 * Created by lucas on 01/12/2016. |
dev@40 | 3 */ |
dev@40 | 4 |
dev@44 | 5 import {ListResponse, EmscriptenProxy} from 'piper'; |
dev@44 | 6 import {PiperSimpleClient} from 'piper/HigherLevelUtilities'; |
dev@44 | 7 import { VampExamplePlugins } from 'piper/ext/VampExamplePluginsModule'; |
dev@62 | 8 import { VampTestPlugin } from 'piper/ext/VampTestPluginModule'; |
dev@44 | 9 |
dev@44 | 10 |
dev@40 | 11 // TODO TypeScript has a .d.ts file for webworkers, but for some reason it clashes with the typings for dom and causes compiler errors |
dev@40 | 12 interface WorkerGlobalScope { |
dev@40 | 13 onmessage: (this: this, ev: MessageEvent) => any; |
dev@40 | 14 postMessage(data: any): void; |
dev@40 | 15 } |
dev@40 | 16 |
dev@40 | 17 interface MessageEvent { |
dev@40 | 18 readonly data: any; |
dev@40 | 19 } |
dev@40 | 20 |
dev@40 | 21 export default class FeatureExtractionWorker { |
dev@40 | 22 private workerScope: WorkerGlobalScope; |
dev@44 | 23 private piperClient: PiperSimpleClient; |
dev@40 | 24 |
dev@40 | 25 constructor(workerScope: WorkerGlobalScope) { |
dev@40 | 26 this.workerScope = workerScope; |
dev@62 | 27 this.piperClient = new PiperSimpleClient(new EmscriptenProxy(VampTestPlugin())); |
dev@44 | 28 this.workerScope.onmessage = (ev: MessageEvent) => { |
dev@47 | 29 const sendResponse = (result) => this.workerScope.postMessage({ |
dev@47 | 30 method: ev.data.method, |
dev@47 | 31 result: result |
dev@47 | 32 }); |
dev@44 | 33 switch (ev.data.method) { |
dev@44 | 34 case 'list': |
dev@47 | 35 this.piperClient.list({}).then(sendResponse); |
dev@47 | 36 break; |
dev@47 | 37 case 'process': |
dev@47 | 38 this.piperClient.process(ev.data.params).then(sendResponse); |
dev@62 | 39 break; |
dev@62 | 40 case 'collect': |
dev@62 | 41 this.piperClient.collect(ev.data.params).then(sendResponse); |
dev@44 | 42 } |
dev@44 | 43 }; |
dev@40 | 44 } |
dev@44 | 45 |
dev@40 | 46 } |