Skip to content

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

@mahayash315

Description

@mahayash315

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}")

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