From 445d2d0821e3e4c69b9094f98c57c157c76137b7 Mon Sep 17 00:00:00 2001 From: zhaoxuan Date: Thu, 3 Dec 2026 02:12:40 +0000 Subject: [PATCH 1/2] Expose subscriber-side remote track enable/disable --- livekit-rtc/livekit/rtc/track_publication.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/livekit-rtc/livekit/rtc/track_publication.py b/livekit-rtc/livekit/rtc/track_publication.py index 2adbd67b4..2e4b3da49 100644 --- a/livekit-rtc/livekit/rtc/track_publication.py +++ b/livekit-rtc/livekit/rtc/track_publication.py @@ -119,6 +119,20 @@ def set_subscribed(self, subscribed: bool) -> None: req.set_subscribed.publication_handle = self._ffi_handle.handle FfiClient.instance.request(req) + def set_enabled(self, enabled: bool) -> None: + """Enable or disable media delivery for this subscribed remote track. + + Unlike changing the subscription, this retains the subscription and + requests a media delivery change without renegotiation. It does not + change the publisher's mute state or affect other subscribers. + Call this after the track is subscribed. The request is not a guarantee + that in-flight media has drained or that resumed media has arrived. + """ + req = proto_ffi.FfiRequest() + req.enable_remote_track_publication.track_publication_handle = self._ffi_handle.handle + req.enable_remote_track_publication.enabled = enabled + FfiClient.instance.request(req) + def set_video_quality(self, quality: "VideoQuality.ValueType") -> None: """For simulcasted video tracks, request a specific simulcast layer from the server. Use one of `rtc.VideoQuality.VIDEO_QUALITY_LOW` (q), From b60a051cea2163efac5f536d364bbcfa5c20a91e Mon Sep 17 00:00:00 2001 From: zhaoxuan Date: Thu, 3 Dec 2026 02:12:51 +0000 Subject: [PATCH 2/2] Test enable and disable FFI requests --- .../test_remote_track_publication_enabled.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 livekit-rtc/tests/test_remote_track_publication_enabled.py diff --git a/livekit-rtc/tests/test_remote_track_publication_enabled.py b/livekit-rtc/tests/test_remote_track_publication_enabled.py new file mode 100644 index 000000000..c23f4f61d --- /dev/null +++ b/livekit-rtc/tests/test_remote_track_publication_enabled.py @@ -0,0 +1,37 @@ +# Copyright 2026 LiveKit, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from types import SimpleNamespace +from unittest.mock import patch + +import pytest + +from livekit.rtc import RemoteTrackPublication + + +@pytest.mark.parametrize("enabled", [False, True]) +def test_set_enabled_sends_publication_request(enabled: bool) -> None: + publication = object.__new__(RemoteTrackPublication) + publication._ffi_handle = SimpleNamespace(handle=123) # type: ignore[assignment] + publication._subscribed = True + + with patch("livekit.rtc.track_publication.FfiClient") as ffi: + publication.set_enabled(enabled) + + ffi.instance.request.assert_called_once() + request = ffi.instance.request.call_args.args[0] + assert request.WhichOneof("message") == "enable_remote_track_publication" + assert request.enable_remote_track_publication.track_publication_handle == 123 + assert request.enable_remote_track_publication.enabled is enabled + assert publication.subscribed