Skip to content

[bug] sendText silently drops non-ASCII messages on receiver (emoji, Cyrillic) #1054

@bohdanudreambit

Description

@bohdanudreambit

Describe the bug

LocalParticipant.sendText method sets totalSize = text.codeUnits.length, but writer.write(text) encodes via splitUtf8() which produces UTF-8 bytes. For non-ASCII text, these counts differ: one emoji = 2 UTF-16 code units but 4 UTF-8 bytes.

validateBytesReceived() (introduced in v2.6.x) throws DataStreamError(LengthExceeded) on the receiver when received bytes exceed totalSize. The throw happens before onData?.call(data), so the chunk is silently dropped, and the stream never emits data to the application layer.

The sender is unaffected; they display their message via a local stream rather than the LiveKit-delivered one.

To Reproduce

  1. Two participants in a room using livekit_client >= 2.6.0
  2. Send a message with any non-ASCII character (emoji, Cyrillic, Chinese…)
  3. On the receiver side, the TextStreamReader stream emits no data
  4. Receiver's Flutter console shows:
DataStreamError: DataStreamErrorReason.LengthExceeded,
Extra chunk(s) received - expected 6 bytes of data total, received 12 bytes
    at validateBytesReceived (stream_reader.dart:43:7)
    at handleChunkReceived (stream_reader.dart:103:5)

Example: "😀😀😀" → codeUnits.length = 6, utf8.encode(...).length = 12.

Expected behavior

The receiver reads the full text stream. totalSize should equal the UTF-8 byte count that writer.write(text) actually transmits.

Suggested fix

In sendText, replace:

final textInBytes = text.codeUnits;

with:

final textInBytes = utf8.encode(text);

Platform information

Flutter version:

[✓] Flutter (Channel stable, 3.41.6, on macOS 15.1 24B83 darwin-arm64, locale
    en-UA) [498ms]
    • Flutter version 3.41.6 on channel stable at /Users/[reducted]/fvm/versions/3.41.6
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db50e20168 (3 weeks ago), 2026-03-25 16:21:00 -0700
    • Engine revision 425cfb54d0
    • Dart version 3.11.4
    • DevTools version 2.54.2
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop,
      enable-windows-desktop, enable-android, enable-ios, cli-animations,
      enable-native-assets, omit-legacy-version-file, enable-lldb-debugging,
      enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version
    36.1.0-rc1) [2.5s]
    • Android SDK at /Users/[reducted]/Library/Android/sdk
    • Emulator version 36.3.10.0 (build_id 14472402) (CL:N/A)
    • Platform android-36, build-tools 36.1.0-rc1
    • Java binary at: /opt/homebrew/opt/openjdk@17/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.15+0)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1) [1,165ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [5ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (3 available) [7.2s]
    • iPhone 16 Pro Max (mobile)        • F513E3EB-B7FB-4D44-93DA-DA5FE6A2413F •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-1 (simulator)
    • macOS (desktop)                   • macos                                •
      darwin-arm64   • macOS 15.1 24B83 darwin-arm64
    • Chrome (web)                      • chrome                               •
      web-javascript • Google Chrome 147.0.7727.56

[✓] Network resources [397ms]
    • All expected network resources are available.

• No issues found!

Plugin version: livekit_client 2.6.3
Flutter target OS: Web
Flutter target OS version:
Flutter console log: see above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions