clever-optician-10225
11/05/2025, 11:19 PMtall-airline-16756
11/05/2025, 11:19 PMtall-airline-16756
11/05/2025, 11:20 PM@livekit/components-js offers a reactive way to watch screen share tracks in a room. It listens for events like TrackSubscribed and TrackUnsubscribed to spot any changes. Here's a simple example:
import { screenShareObserver } from '@livekit/components-core';
screenShareObserver(room).subscribe((screenShares) => {
screenShares.forEach(({ participant, tracks }) => {
console.log(`${participant.identity} is sharing screen with ${tracks.length} track(s)`);
});
});
• Listening for Track Events: You can also listen directly for events like LocalTrackPublished and LocalTrackUnpublished for the local participant, or TrackSubscribed and TrackUnsubscribed for remote participants. Here’s how you might do it:
room.localParticipant.on('trackPublished', (publication) => {
if (publication.source === Track.Source.ScreenShare) {
console.log('Local user started screen sharing');
}
});
room.localParticipant.on('trackUnpublished', (publication) => {
if (publication.source === Track.Source.ScreenShare) {
console.log('Local user stopped screen sharing');
}
});
• Checking Local Screen Share State: Another quick way is to check the isScreenShareEnabled property to see if the local participant is currently sharing their screen:
const isEnabled = room.localParticipant.isScreenShareEnabled;
console.log(`Screen sharing is ${isEnabled ? 'on' : 'off'}`);
Using these methods, you'll be able to easily monitor and respond to screen sharing activity. If you have any questions or want to explore more, feel free to ask—I'm here to help!
Sources: Sources/LiveKit/Participant/LocalParticipant.swift | packages/core/src/observables/room.ts | Web Applications & Integration Examples | livekit/livekit_composite | DeepW... | Screen sharing | LiveKit docsclever-optician-10225
11/05/2025, 11:22 PMtall-airline-16756
11/05/2025, 11:22 PMtrack_published and track_unpublished events. These events are really helpful because they trigger whenever a participant publishes or unpublishes a track in the room. Here's a simple example to guide you:
import asyncio
import logging
from livekit import rtc
async def main():
room = rtc.Room()
@room.on("track_published")
def on_track_published(publication, participant):
if publication.source == rtc.Track.Source.SCREEN_SHARE:
logging.info(f"User {participant.identity} started screen sharing")
@room.on("track_unpublished")
def on_track_unpublished(publication, participant):
if publication.source == rtc.Track.Source.SCREEN_SHARE:
logging.info(f"User {participant.identity} stopped screen sharing")
await room.connect("LIVEKIT_URL", "ACCESS_TOKEN")
await asyncio.sleep(3600) # Keep the app running
asyncio.run(main())
Let me break it down for you:
• Event Handlers: The track_published event helps you catch when screen sharing starts, and track_unpublished lets you know when it stops.
• Source Filtering: By checking publication.source, you can confirm the track is specifically for screen sharing (SCREEN_SHARE).
• Connection: Just remember to replace LIVEKIT_URL and ACCESS_TOKEN with your actual server URL and access token.
This approach will help you keep a real-time eye on screen sharing activity, making your application more responsive and user-friendly. If you have any questions or need further assistance, feel free to ask—I'm here to help!
Sources: livekit-android-sdk/src/main/java/io/livekit/android/room/track/Track.kt | livekit-rtc/livekit/rtc/room.pyclever-optician-10225
11/05/2025, 11:25 PMtall-airline-16756
11/05/2025, 11:26 PMsource property on the track publication. For screen sharing, it will be set to rtc.TrackSource.SOURCE_SCREENSHARE.
Here’s a friendly example to guide you:
import livekit.rtc as rtc
@room.on("track_published")
def on_track_published(publication, participant):
if publication.source == rtc.TrackSource.SOURCE_SCREENSHARE:
print(f"Screen sharing started by {participant.identity}")
@room.on("track_unpublished")
def on_track_unpublished(publication, participant):
if publication.source == rtc.TrackSource.SOURCE_SCREENSHARE:
print(f"Screen sharing stopped by {participant.identity}")
@room.on("local_track_published")
def on_local_track_published(publication, track):
if publication.source == rtc.TrackSource.SOURCE_SCREENSHARE:
print("Local screen sharing started")
@room.on("local_track_unpublished")
def on_local_track_unpublished(publication):
if publication.source == rtc.TrackSource.SOURCE_SCREENSHARE:
print("Local screen sharing stopped")
Using this method, you’ll be able to track screen sharing activity smoothly for both yourself and others in the room. If you have any more questions or need further help, I’m here for you!
Sources: livekit-android-sdk/src/main/java/io/livekit/android/room/participant/Local... | lib/src/managers/broadcast_manager.dart | livekit-rtc/livekit/rtc/room.py | LiveKit Server Platform | livekit/livekit_composite | DeepWiki