mirror of
https://github.com/aurora-opensource/xviz.git
synced 2026-01-18 14:07:46 +00:00
2.3 KiB
2.3 KiB
parseXVIZMessage
import {parseXVIZMessage, XVIZ_MESSAGE} from '@xviz/parser';
parseXVIZMessage({
message,
onResult: data => {
switch (data.type) {
case XVIZ_MESSAGE.METADATA: // do something
case XVIZ_MESSAGE.TIMESLICE: // do something
case XVIZ_MESSAGE.INCOMPLETE: // do something
}
},
onError: console.error,
worker: true
maxConcurrency: 4
});
Parameters:
opts(Object)message(Object|String|ArrayBuffer) - XVIZ message to decode.onResult(Function) - callback if the message is parsed successfully. Receives a single argumentdata.data.typeis one ofXVIZ_MESSAGE.onError(Function) - callback if the parser encouters an error.debug(Function) - callback to log debug info.worker(Boolean|String) - use Web Wroker to parse the message. Enabling worker is recommended to improve loading performance in production. Defaultfalse.- boolean: whether to use the default worker. Note that callbacks in XVIZ config are ignored by the default worker. If you need to inject custom hooks into the parsing process, create a custom worker using streamDataWorker.
- string: a custom worker URL to use.
maxConcurrency(Number) - the max number of workers to use. Has no effect ifworkeris set tofalse. Default4.capacity(Number) - the limit on the number of messages to queue for the workers to process, has no effect if set otnull. Defaultnull.
XVIZ_MESSAGE
Enum of stream message types.
METADATATIMESLICEERRORINCOMPLETEDONE
streamDataWorker (experimental)
Create a custom worker for message parsing. This allows an app to inject callback hooks into the parsing process.
// worker.js
import {streamDataWorker} from './stream-data-worker';
streamDataWorker({
preProcessPrimitive: primitive => {
if (primitive.type === 'circle') {
primitive.center[2] += 0.1;
}
}
})(self);
streamDataWorker(config)
Returns a function that initializes a WorkerGlobalScope to talk to the XVIZ parser on the main thread.
Parameters:
- config (Object) - an XVIZ config object.