python-sdks icon indicating copy to clipboard operation
python-sdks copied to clipboard

Server API SendData not delivered to Python data_received listeners in 1.0.16 (worked in 1.0.13)

Open mahayash315 opened this issue 3 months ago • 1 comments

Summary

Related Slack thread: https://livekit-users.slack.com/archives/C07FVFM5NA1/p1760636896172949

After upgrading livekit Python SDK from 1.0.13 → 1.0.16, data sent via RoomService SendData API (Server API) is not delivered to Python SDK listeners (room.on("data_received")).
Data sent by a participant via local_participant.publish_data(...) still triggers the event.

Looks like a regression since this works in Python SDK version 1.0.13.


Environment

  • Python SDK: 1.0.16 (works as expected on 1.0.13)
  • Python: 3.12
  • Server call: RoomService SendData (Python code example below, but issue should be independent of caller)

Expected behavior

RoomService.sendData(...) delivers data to connected participants and fires room.on("data_received") in the Python SDK, same as local_participant.publish_data(...).

Actual behavior

room.on("data_received") does not fire for messages sent via RoomService.sendData(...) (tested with kind=RELIABLE with destination = None and specific Identities).
local_participant.publish_data(...) continues to fire the event as expected.


Minimal repro

Client (python-sdk): basic_room.py example

Server API call:

import os
import requests
import base64

from livekit import api

from dotenv import load_dotenv
load_dotenv()
# ensure LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are set

if __name__ == "__main__":
    message = "Hello world"
    room_name = 'my-room'

    # Generate access token with room admin permissions
    token = api.AccessToken() \
        .with_identity("data-sender") \
        .with_grants(api.VideoGrants(
            room=room_name,
            room_join=True,
            room_admin=True,  # Required for RoomService API calls
            can_publish=True,  # Required to send data
            can_subscribe=True  # Good practice for bridge services
        )) \
        .to_jwt()
    
    # Convert WebSocket URL to HTTP API URL
    api_url = os.environ.get('LIVEKIT_URL').replace('wss://', 'https://').replace('ws://', 'http://')
    if not api_url.endswith('/'):
        api_url += '/'
    
    # Send data message via REST API
    url = f"{api_url}twirp/livekit.RoomService/SendData"
    
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json'
    }

    payload = {
        'room': room_name,
        'data': base64.b64encode(message.encode("utf-8")).decode("ascii"),
        'kind': 'reliable',  # Use reliable delivery
        'destination_identities': None,
    }
    
    response = requests.post(url, json=payload, headers=headers, timeout=10)
    
    if response.status_code == 200:
        print(f"Successfully sent message to room")
    else:
        print(f"Failed to send message. Status: {response.status_code}, Response: {response.text}")
        raise Exception(f"LiveKit API error: {response.status_code} - {response.text}")

mahayash315 avatar Oct 17 '25 16:10 mahayash315

Hi, thanks for the report. This is a bug on the Rust SDK, we will have a fix out in the next two days.

s-hamdananwar avatar Oct 21 '25 01:10 s-hamdananwar

Hi maintainers — any update on this regression?

We rely on Server API RoomService.SendData to control a Python participant/bot. After upgrading livekit python sdk from 1.0.13 to >=1.0.16, messages sent via RoomService.SendData no longer trigger room.on("data_received") on the Python side, while local_participant.publish_data still works.

This is blocking us in production (server->agent control channel). Could you please help triage / confirm whether this is a known issue and if there’s an intended replacement or workaround? Happy to test a patch or provide more logs.

lusess123 avatar Dec 16 '25 00:12 lusess123

Hey @lusess123, this has been fixed in the latest versions- I forgot to update here my apologies. Please update to the latest version and let me know if you are still seeing the issue

s-hamdananwar avatar Dec 16 '25 00:12 s-hamdananwar