melodic-zoo-29246
02/12/2026, 8:09 PMtall-airline-16756
02/12/2026, 8:10 PMtall-airline-16756
02/12/2026, 8:10 PMfor/await on a TextStreamReader rather than readAll()).
You can process each chunk as it arrives by iterating the TextStreamReader with an asynchronous for/await loop. This keeps latency low and lets you update UI or state incrementally (good for chat, transcriptions, or live feedback).
Example implementation:
room.registerTextStreamHandler('lk.chat', async (reader, participantIdentity) => {
try {
// Process each chunk as it arrives
for await (const chunk of reader) {
console.log('Received chunk:', chunk);
// Update UI or state with this chunk (append to buffer / render partial text)
}
console.log('Stream completed.');
} catch (error) {
console.error('Error reading text stream:', error);
}
});
Notes and suggestions:
• Handle partial chunks: append each chunk to a buffer or update your UI incrementally so text appears smoothly.
• Error handling: catch stream errors and show a user-friendly message or retry logic if needed.
• Backpressure/flow: if UI updates are expensive, consider batching small chunks or debouncing renders to avoid jank.
• Cleanup: if your component unmounts, ensure any related resources or listeners are cleaned up so you don’t attempt to update unmounted components.
If you want, tell me:
• Which UI pattern you’re using (functional components with hooks or class components).
• Whether chunks should be appended continuously or only displayed after reaching sentence/paragraph boundaries.
I can then show a small React Native component example that integrates this loop and updates state safely.
Sources: Text and transcriptions | LiveKit Documentation | LiveKit coming to React Native!