mirror of
https://github.com/aurora-opensource/xviz.git
synced 2026-01-18 14:07:46 +00:00
When processing data in real time if you fall behind the queue can grow unbounded, so you need the ability to cap it. You also want to know if you have dropped data so that is now reported as well.
2.3 KiB
2.3 KiB
parseStreamMessage
import {parseStreamMessage, LOG_STREAM_MESSAGE} from '@xviz/parser';
parseStreamMessage({
message,
onResult: data => {
switch (data.type) {
case LOG_STREAM_MESSAGE.METADATA: // do something
case LOG_STREAM_MESSAGE.TIMESLICE: // do something
case LOG_STREAM_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 ofLOG_STREAM_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.
LOG_STREAM_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.