-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove dead codes of it-decode
- Loading branch information
1 parent
08a3840
commit f405d45
Showing
3 changed files
with
10 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,19 @@ | ||
import type { EncodedBlock } from 'luby-transform' | ||
import type { DecoderWorkerFunctions } from './workers/lt-decode.worker' | ||
import type { LTDecoderWorkerFunctions } from './workers/lt-decode.worker' | ||
import { createBirpc } from 'birpc' | ||
import DecodeWorkerConstructor from './workers/lt-decode.worker?worker' | ||
import DecodeWorker from './workers/lt-decode.worker?worker' | ||
|
||
export function createDecodeWorker() { | ||
export function createLTDecodeWorker() { | ||
const worker = new DecodeWorker() | ||
|
||
const rpc = Object.assign(createBirpc<DecoderWorkerFunctions>({}, { | ||
post: worker.decodeWorker.postMessage.bind(worker.decodeWorker), | ||
on: fn => worker.decodeWorker.addEventListener('message', event => fn(event.data)), | ||
const rpc = Object.assign(createBirpc<LTDecoderWorkerFunctions>({}, { | ||
post: worker.postMessage.bind(worker), | ||
on: fn => worker.addEventListener('message', event => fn(event.data)), | ||
}), { | ||
worker, | ||
dispose() { | ||
worker.decodeWorker.terminate() | ||
worker.terminate() | ||
}, | ||
}) | ||
|
||
return rpc | ||
} | ||
|
||
class DecodeWorker { | ||
decodeWorker: Worker | ||
constructor() { | ||
this.decodeWorker = new DecodeWorkerConstructor() | ||
} | ||
|
||
initDecoder(data?: EncodedBlock[]) { | ||
this.decodeWorker.postMessage({ type: 'createDecoder', data }) | ||
} | ||
|
||
addBlock(data: EncodedBlock) { | ||
this.decodeWorker.postMessage({ type: 'addBlock', data }) | ||
} | ||
|
||
onDecoded(callback: (data: Uint8Array | undefined) => void) { | ||
const eventFn = (event: MessageEvent) => { | ||
const { type, data } = event.data | ||
if (type === 'decoded') { | ||
callback(data) | ||
} | ||
} | ||
this.decodeWorker.addEventListener('message', eventFn) | ||
|
||
return () => { | ||
this.decodeWorker.removeEventListener('message', eventFn) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters