Repository navigation
build(livekit): [email protected] and build it from source, + - #23351
Conversation
Add more information to LK's screnshare bridge logs so that it's easier
to debug in production:
- Guarantee trackSid, streamData, source, streamId are present in all
relevant logs
- Refactor log messages to be more consistent with other LK bridges
The selective subscription hooks currently rely on remote participants only for defining the desired vs current subscription maps. Those remove participants are filtered to avoid spurious updates, but the filter is too restrictive and may be impacting our ability to react to subscription failures, upstream publication state changes et al. Extend the participant filters with additional events so that the local refs are more frequently updated. We'll track metrics and log data to see if this improves the subscription situation. Additionally: extend the camera bridge track filter as well for the same reasons above.
livekit-server's binary is currently pulled directly from GitHub. This works, but we'd like to have the ability to test LiveKit builds that are not necessarily tied to tags (e.g.: commits). Adjust bbb-livekit's build script so that livekit-server is built from source. Upstream's build instructions (via mage) were followed.
WalkthroughThe changes introduce new event handlers and enhance logging across several modules related to LiveKit integration. In the audio bridge, a handler for track subscription status changes is added, logging detailed track information. The screenshare bridge now handles local track publication events with enriched logging, and removes a redundant publication start log. Logging in error cases for media streams is improved by explicitly indicating stream validity. UI components for selective subscription and camera tracks expand their event filters to react to a broader set of LiveKit room and track events. The build script is overhauled to build LiveKit server and SIP components from source, update versioning, and improve robustness and error handling. The LiveKit configuration file is updated to add a new TCP fallback parameter, adjust audio active level, and include additional codecs. Sequence Diagram(s)LiveKitAudioBridge: Handling Track Subscription Status ChangessequenceDiagram
participant LiveKitRoom
participant LiveKitAudioBridge
LiveKitRoom->>LiveKitAudioBridge: TrackSubscriptionStatusChanged(publication, status)
LiveKitAudioBridge->>LiveKitAudioBridge: handleTrackSubscriptionStatusChanged(publication, status)
LiveKitAudioBridge->>LiveKitAudioBridge: Log track SID, name, role, and status
LiveKitScreenshareBridge: Handling Local Track Published EventsequenceDiagram
participant LocalParticipant
participant LiveKitScreenshareBridge
LocalParticipant->>LiveKitScreenshareBridge: LocalTrackPublished(publication)
LiveKitScreenshareBridge->>LiveKitScreenshareBridge: handleLocalTrackPublished(publication)
LiveKitScreenshareBridge->>LiveKitScreenshareBridge: Log track SID, name, and stream data
UI Components: Expanded Event Filtering for UpdatessequenceDiagram
participant LiveKitRoom
participant UIComponent
LiveKitRoom->>UIComponent: ParticipantConnected/Disconnected
LiveKitRoom->>UIComponent: ConnectionStateChanged
LiveKitRoom->>UIComponent: TrackPublished/Unpublished
LiveKitRoom->>UIComponent: TrackSubscriptionPermissionChanged
LiveKitRoom->>UIComponent: TrackSubscriptionStatusChanged
LiveKitRoom->>UIComponent: TrackSubscribed/Unsubscribed
LiveKitRoom->>UIComponent: TrackSubscriptionFailed
UIComponent->>UIComponent: Update state/UI as needed
Build Script: Building LiveKit Components from SourcesequenceDiagram
participant BuildScript
participant SourceArchive
participant BuildDir
participant StagingDir
BuildScript->>SourceArchive: Download livekit-server and livekit-sip source archives
BuildScript->>BuildDir: Extract archives
BuildScript->>BuildDir: Build livekit-server (bootstrap.sh, mage)
BuildScript->>BuildDir: Build livekit-sip (go build)
BuildDir->>StagingDir: Copy built binaries
BuildScript->>BuildDir: Clean up temporary directories
BuildScript->>BuildScript: Package binaries
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Tweak default configs with: - RED and RTX enable by default at the server side - TCP fallback disabled by default - Audio activity threshold slightly lowered
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (12)
build/packages-template/bbb-livekit/build.sh (12)
3-3: Avoid relying onpwdfor package metadata.
ParsingTARGETfrom the current working directory name is brittle—consider passing it as an explicit argument or validating its format before use.
5-5: Ensure consistent version prefixing.
SERVER_VERSIONis defined asv1.9.0whileCLI_VERSIONomits thevprefix. Unify version formatting across variables.
7-7: Consistent prefix forSIP_VERSION.
SIP_VERSIONincludes a leadingv; match the chosen versioning style (with or withoutv) for all components.
13-15: Use a dedicated temporary staging directory.
DefiningDESTDIRinside$PWDrisks polluting source folders. Consider usingmktemp -dfor the entire staging area and cleaning it up automatically.
25-27: Useinstallfor consistent file permissions.
Replacemkdir+cpwith:install -Dm644 livekit.nginx "$DESTDIR/usr/share/bigbluebutton/nginx/livekit.nginx"to set directory and file permissions in one step.
28-30: Useinstallfor systemd units.
Likewise, install service definitions with:install -Dm644 livekit-server.service livekit-sip.service "$DESTDIR/lib/systemd/system/"for cleaner permission handling.
46-49: Redirect error messages to stderr.
Echoing errors without redirecting can mix logs. Change:echo "Error: Could not find livekit-server directory in extracted archive"to
echo "Error: Could not find livekit-server directory in extracted archive" >&2
53-64: Streamline Go build environment setup.
Rather than exporting each variable in a subshell block, consider a one-liner:GOPATH="/tmp/go-${TARGET}" GOBIN="$GOPATH/bin" PATH="$GOBIN:$PATH" \ mage -vThis reduces boilerplate and ensures the environment is isolated.
66-68: Useinstallfor the built binary.
Replace:cp "$LIVEKIT_DIR/bin/livekit-server" "$DESTDIR/usr/bin"with:
install -Dm755 "$LIVEKIT_DIR/bin/livekit-server" "$DESTDIR/usr/bin/livekit-server"
79-82: Consistently redirect SIP errors to stderr.
Mirror the livekit-server error handling:echo "Error: Could not find livekit-sip directory in extracted archive" >&2; exit 1
86-90: Consider supporting moreTARGETPLATFORMvalues.
The script only handleslinux/arm64and defaults toamd64. If you plan to build forarm/v7or others, extend this logic or deriveGOARCHdirectly from$TARGETPLATFORM.
92-94: Optimize Go build flags and installation.
Strip debug symbols with-ldflags '-s -w'to reduce binary size, and useinstall:CGO_ENABLED=1 GOOS=linux GOARCH="${GOARCH}" go build -ldflags '-s -w' -o livekit-sip ./cmd/livekit-sip install -Dm755 livekit-sip "$DESTDIR/usr/bin/livekit-sip"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
bigbluebutton-html5/imports/api/audio/client/bridge/livekit.ts(4 hunks)bigbluebutton-html5/imports/api/screenshare/client/bridge/livekit.ts(11 hunks)bigbluebutton-html5/imports/ui/components/livekit/selective-subscription/hooks.ts(1 hunks)bigbluebutton-html5/imports/ui/components/video-provider/livekit-camera-bridge/component.tsx(1 hunks)bigbluebutton-html5/imports/utils/media-stream-utils.js(2 hunks)build/packages-template/bbb-livekit/build.sh(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
bigbluebutton-html5/imports/api/screenshare/client/bridge/livekit.ts (2)
bigbluebutton-html5/imports/ui/components/screenshare/service.js (5)
screenShareEndAlert(354-357)screenShareEndAlert(354-357)track(113-113)stream(250-250)stream(300-300)bigbluebutton-html5/imports/utils/media-stream-utils.js (1)
track(45-45)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build-package (bbb-html5)
- GitHub Check: build-package (others)
- GitHub Check: build-package (bbb-graphql-server)
- GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (18)
bigbluebutton-html5/imports/ui/components/video-provider/livekit-camera-bridge/component.tsx (1)
106-107: LGTM! Enhanced subscription event handlingThe addition of
TrackSubscriptionStatusChanged,TrackSubscriptionPermissionChanged, andTrackSubscriptionFailedevents to theupdateOnlyOnarray improves the component's responsiveness to track subscription lifecycle events. This aligns well with similar enhancements in other LiveKit components throughout the codebase.bigbluebutton-html5/imports/utils/media-stream-utils.js (2)
77-77: LGTM! Explicit validity indicationAdding the
valid: trueproperty to the success case provides explicit validity status for media stream data, improving error handling and logging throughout the application.
94-94: LGTM! Consistent error handlingThe
valid: falseproperty in the error case maintains consistency with the success case and provides clear validity indication for error scenarios.bigbluebutton-html5/imports/ui/components/livekit/selective-subscription/hooks.ts (1)
36-45: LGTM! Comprehensive event filteringThe expansion of
PARTICIPANTS_UPDATE_FILTERto include participant lifecycle events (ParticipantConnected,ParticipantDisconnected) and subscription-related events significantly improves the responsiveness of the selective subscription system. This aligns with the broader pattern of enhanced event handling across LiveKit components.bigbluebutton-html5/imports/api/audio/client/bridge/livekit.ts (4)
73-73: LGTM! Proper method bindingThe binding of
handleTrackSubscriptionStatusChangedin the constructor follows the established pattern in the class.
210-228: LGTM! Well-implemented event handlerThe
handleTrackSubscriptionStatusChangedmethod properly filters for microphone publications and provides detailed logging with relevant context including trackSid, trackName, and subscription status. The implementation is consistent with other event handlers in the class.
307-307: LGTM! Proper event registrationThe event listener registration for
TrackSubscriptionStatusChangedis correctly placed in theobserveLiveKitEventsmethod.
320-320: LGTM! Proper cleanupThe event listener deregistration in
removeLiveKitObserversensures proper cleanup and prevents memory leaks.bigbluebutton-html5/imports/api/screenshare/client/bridge/livekit.ts (8)
15-15: LGTM! Import additionThe addition of
ParticipantEventimport is necessary for the new local track published event handling.
114-114: LGTM! Proper method bindingThe binding of
handleLocalTrackPublishedin the constructor follows the established pattern.
242-258: LGTM! Dedicated local track publication handlerThe new
handleLocalTrackPublishedmethod provides dedicated logging for local track publications with comprehensive context including trackSid, trackName, and stream data. This improves observability for screen share events.
221-221: LGTM! Enhanced logging contextThe addition of
trackNameto the destructuring and inclusion ofstreamDatain the logging provides better traceability and debugging information for screen share unpublication events.Also applies to: 230-234
282-282: LGTM! Improved subscription loggingThe enhanced logging in
handleTrackSubscribedwithtrackNameandstreamIdprovides better context for debugging subscription events.Also applies to: 289-295
304-304: LGTM! Consistent unsubscription loggingThe enhanced logging in
handleTrackUnsubscribedmaintains consistency with the subscription handler and provides comprehensive context for debugging.Also applies to: 310-316
340-340: LGTM! Proper event handlingThe registration and deregistration of the
LocalTrackPublishedevent listener is correctly implemented, ensuring proper lifecycle management.Also applies to: 352-352
533-533: LGTM! Enhanced error logging contextThe addition of
streamId,contentType, andstreamDatato error logging provides valuable context for debugging screenshare initialization and exit issues.Also applies to: 593-595, 639-639
build/packages-template/bbb-livekit/build.sh (2)
35-35: (Trivialmkdir -p; no further changes needed.)
96-97: (Cleanup viarm -rf "$buildbase"is straightforward.)
| PACKAGE=$(echo "$TARGET" | cut -d'_' -f1) | ||
| VERSION=$(echo "$TARGET" | cut -d'_' -f2) | ||
| DISTRO=$(echo "$TARGET" | cut -d'_' -f3) | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Harden parsing of TARGET components.
Splitting TARGET on underscores breaks if any component contains _. Use a more robust method—e.g.,
IFS='_' read -r PACKAGE VERSION DISTRO <<< "$TARGET"or accept explicit parameters.
🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 9 to 12, the
current method of splitting the TARGET variable using cut with underscores fails
if any component contains underscores. Replace the three separate cut commands
with a single read command using IFS='_' to split TARGET into PACKAGE, VERSION,
and DISTRO variables robustly. This ensures correct parsing even if components
contain underscores.
| # shellcheck disable=SC1090 | ||
| . "./opts-$DISTRO.sh" |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Handle missing distro-specific options file.
Before sourcing opts-$DISTRO.sh, verify it exists to avoid a silent failure. For example:
if [[ -f "./opts-$DISTRO.sh" ]]; then
source "./opts-$DISTRO.sh"
else
echo "Error: opts-$DISTRO.sh not found" >&2; exit 1
fi🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 22 to 23, the
script sources the file opts-$DISTRO.sh without checking if it exists, which can
cause silent failures. Modify the script to first check if the file
./opts-$DISTRO.sh exists using a conditional test, and only source it if
present. If the file is missing, print an error message to stderr and exit the
script with a non-zero status to prevent further execution.
| rm -rf "$DESTDIR" | ||
| mkdir -p "$DESTDIR" |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add safety checks before rm -rf.
Unconditional rm -rf "$DESTDIR" may delete unintended paths if DESTDIR is empty or mis-set. Add a sanity check, e.g.:
[[ "$DESTDIR" =~ /staging$ ]] || { echo "Invalid DESTDIR" >&2; exit 1; }🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 19 to 20, the
script unconditionally runs rm -rf on the DESTDIR variable, which risks deleting
unintended directories if DESTDIR is empty or incorrect. Add a safety check
before the rm command to verify that DESTDIR ends with /staging or matches an
expected pattern. If the check fails, print an error message to stderr and exit
with a non-zero status to prevent accidental deletions.
| # Pull built lk cli from github | ||
| curl "https://github.com/livekit/livekit-cli/releases/download/v${CLI_VERSION}/lk_${CLI_VERSION}_linux_amd64.tar.gz" -Lo - | tar -C "$DESTDIR/usr/bin" -xzf - lk | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Improve robustness of curl download.
Add --fail --silent --show-error and retry logic to avoid partial downloads:
curl -fSL --retry 3 "https://github.com/livekit/livekit-cli/releases/download/v${CLI_VERSION}/lk_${CLI_VERSION}_linux_amd64.tar.gz" \
| tar -C "$DESTDIR/usr/bin" -xzf - lk🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 37 to 39, the curl
command downloading the livekit CLI lacks options for robust error handling and
retries. Update the curl command to include --fail, --silent, and --show-error
flags to properly handle HTTP errors and suppress unnecessary output, and add
--retry 3 to attempt the download up to three times on failure. This will
prevent partial or failed downloads and improve script reliability.
| buildbase=$(mktemp -d) | ||
| curl https://github.com/livekit/sip/archive/refs/tags/v${SIP_VERSION}.tar.gz -Lo - | tar -xzf - -C $buildbase | ||
| pushd $buildbase/sip-${SIP_VERSION} | ||
|
|
||
| if [ "$TARGETPLATFORM" = "linux/arm64" ]; then GOARCH=arm64; else GOARCH=amd64; fi && \ | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on go build -a -o livekit-sip ./cmd/livekit-sip | ||
|
|
||
| cp livekit-sip $DESTDIR/usr/bin | ||
|
|
||
| popd | ||
| rm -rf $buildbase | ||
|
|
||
| fpm -s dir -C $DESTDIR -n $PACKAGE \ | ||
| --version $VERSION --epoch 2 \ | ||
| --before-install before-install.sh \ | ||
| --after-install after-install.sh \ | ||
| --before-remove before-remove.sh \ | ||
| --after-remove after-remove.sh \ | ||
| curl "https://github.com/livekit/sip/archive/${SIP_VERSION}.tar.gz" -Lo - | tar -xzf - -C "$buildbase" | ||
| # Get livekit-sip's directory name from the extracted archive | ||
| SIP_DIR=$(find "$buildbase" -maxdepth 1 -type d -name "sip-*" | head -n 1) |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Improve curl invocation for SIP source.
Apply the same robust pattern to avoid incomplete downloads:
curl -fSL --retry 3 "https://github.com/livekit/sip/archive/${SIP_VERSION}.tar.gz" \
| tar -xzf - -C "$buildbase"🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 74 to 77, the curl
command downloading the SIP source lacks flags for robustness and retry logic.
Update the curl invocation to include -fSL and --retry 3 options to ensure it
fails on HTTP errors, follows redirects, shows progress, and retries up to 3
times on transient failures. Replace the current curl command with this improved
pattern while keeping the tar extraction unchanged.
| fpm -s dir -C "$DESTDIR" -n "$PACKAGE" \ | ||
| --version "$VERSION" --epoch 2 \ | ||
| --before-install before-install.sh \ | ||
| --after-install after-install.sh \ | ||
| --before-remove before-remove.sh \ | ||
| --after-remove after-remove.sh \ | ||
| --description "BigBlueButton build of LiveKit Server" \ | ||
| $DIRECTORIES \ | ||
| $DIRECTORIES \ |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Validate FPM variables and quoting.
Ensure $DIRECTORIES and $OPTS are defined and safely expanded; unquoted expansions can lead to word-splitting bugs. For example:
: "${DIRECTORIES:?DIRECTORIES is not set}"
: "${OPTS:?OPTS is not set}"
fpm -s dir -C "$DESTDIR" -n "$PACKAGE" \
--version "$VERSION" --epoch 2 \
--before-install before-install.sh \
--after-install after-install.sh \
--before-remove before-remove.sh \
--after-remove after-remove.sh \
--description "BigBlueButton build of LiveKit Server" \
"${DIRECTORIES[@]}" \
"${OPTS[@]}"🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 100 to 107, ensure
that the variables DIRECTORIES and OPTS are defined before use to prevent
errors. Add validation lines using parameter expansion to check if these
variables are set. Also, when passing these variables to the fpm command, quote
them properly as arrays (e.g., "${DIRECTORIES[@]}" and "${OPTS[@]}") to avoid
word-splitting and globbing issues.
| buildbase=$(mktemp -d) | ||
| curl "https://github.com/livekit/livekit/archive/${SERVER_VERSION}.tar.gz" -Lo - | tar -xzf - -C "$buildbase" | ||
| # Get livekit-server's directory name from the extracted archive | ||
| LIVEKIT_DIR=$(find "$buildbase" -maxdepth 1 -type d -name "livekit-*" | head -n 1) | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enable pipefail for safer pipelines.
Shebang uses -e, but pipelines may mask failures. Add set -o pipefail near the top to catch errors in curl | tar and similar constructs.
🤖 Prompt for AI Agents
In build/packages-template/bbb-livekit/build.sh around lines 41 to 45, the
script uses a pipeline with curl and tar but does not have pipefail enabled,
which can mask failures in the pipeline. To fix this, add `set -o pipefail` near
the top of the script, ideally after the shebang and any existing `set -e` to
ensure that any failure in a pipeline command is properly detected and causes
the script to exit.
|
Automated tests Summary✅ All the CI tests have passed! |



What does this PR do?
works, but we'd like to have the ability to test LiveKit builds that are
not necessarily tied to tags (e.g.: commits).
source. Upstream's build instructions (via mage) were followed
only for defining the desired vs current subscription maps.
the filter is too restrictive and may be impacting our ability to react
to subscription failures, upstream publication state changes et al.
refs are more frequently updated. We'll track metrics and log data to see
if this improves the subscription situation.
Closes Issue(s)
None
Motivation
#21059
How to test
More