# HG changeset patch # User Lucas Thompson # Date 1492783965 -3600 # Node ID efa23f33393be79a7dfff36ab733e318a00645c1 # Parent 23db7139085a025f465937579261f54165f5e85a Remove redundant map & some naive logic for wrapping emscripten modules diff -r 23db7139085a -r efa23f33393b src/app/services/feature-extraction/FeatureExtractionWorker.ts --- a/src/app/services/feature-extraction/FeatureExtractionWorker.ts Fri Apr 21 13:06:56 2017 +0100 +++ b/src/app/services/feature-extraction/FeatureExtractionWorker.ts Fri Apr 21 15:12:45 2017 +0100 @@ -18,6 +18,7 @@ StreamingService } from "piper/StreamingService"; import {Observable} from "rxjs/Observable"; +import {EmscriptenModule} from "piper/PiperVampService"; interface MessageEvent { @@ -69,7 +70,6 @@ export default class FeatureExtractionWorker { private workerScope: DedicatedWorkerGlobalScope; - private services: Map; private remoteLibraries: Map; private server: WebWorkerStreamingServer; private service: AggregateStreamingService; @@ -77,7 +77,6 @@ constructor(workerScope: DedicatedWorkerGlobalScope, private requireJs: RequireJs) { this.workerScope = workerScope; - this.services = new Map(); this.remoteLibraries = new Map(); this.service = new AggregateStreamingService(); this.setupImportLibraryListener(); @@ -88,6 +87,7 @@ } private setupImportLibraryListener(): void { + this.workerScope.onmessage = (ev: MessageEvent) => { const sendResponse = (result) => { this.workerScope.postMessage({ @@ -100,13 +100,13 @@ const key: LibraryKey = ev.data.params; if (this.remoteLibraries.has(key)) { this.requireJs([this.remoteLibraries.get(key)], (plugin) => { - this.services.set( - key, - new PiperStreamingService( - new PiperVampService(plugin.createLibrary()) - ) - ); // TODO won't always be an emscripten module - this.service.addService(key, this.services.get(key)); + // TODO a factory with more logic probably belongs in piper-js + const lib: any | EmscriptenModule = plugin.createLibrary(); + const isEmscriptenModule = typeof lib.cwrap === 'function'; + const service = new PiperStreamingService( + isEmscriptenModule ? new PiperVampService(lib) : lib // TODO + ); + this.service.addService(key, service); this.service.list({}).then(sendResponse); }); } else {