Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: Build examples against latest LiveKit SDK (via CMake)

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
name: linux-x64
- os: macos-latest
name: macos-arm64
- os: windows-latest
name: windows-x64

name: Build (${{ matrix.name }})
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

# ---------- deps ----------
- name: Install deps (Ubuntu)
if: runner.os == 'Linux'
shell: bash
run: |
set -eux
sudo apt-get update
sudo apt-get install -y \
cmake ninja-build pkg-config \
protobuf-compiler libprotobuf-dev \
libssl-dev \
curl

- name: Install deps (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
set -eux
brew update
brew install cmake ninja protobuf

- name: Install deps (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install -y ninja

- name: Setup MSVC (Windows)
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

# ---------- configure + build ----------
- name: Configure (Unix)
if: runner.os != 'Windows'
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -eux
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release

- name: Build (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
set -eux
cmake --build build --config Release

- name: Configure (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cmake -S . -B build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_C_COMPILER=cl `
-DCMAKE_CXX_COMPILER=cl

- name: Build (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cmake --build build --config Release

# ---------- smoke test ----------
- name: Smoke test (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail

sdk_root="$(ls -d build/_deps/livekit-sdk/* | head -n 1)"
echo "SDK root: ${sdk_root}"
ls -la "${sdk_root}/lib" || true
# Locate executable (it may not be directly under build/)
exe="$(find build -type f -name basic_room -perm -111 | head -n 1)"
if [[ -z "${exe}" ]]; then
echo "basic_room executable not found under build/"
find build -maxdepth 3 -type f -print
exit 1
fi
echo "Running: ${exe} --self-test"
if [[ "$RUNNER_OS" == "Linux" ]]; then
export LD_LIBRARY_PATH="${sdk_root}/lib:${LD_LIBRARY_PATH:-}"
else
export DYLD_LIBRARY_PATH="${sdk_root}/lib:${DYLD_LIBRARY_PATH:-}"
fi
"${exe}" --self-test


- name: Smoke test (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Locate SDK root
$sdkRoot = Get-ChildItem -Directory "build/_deps/livekit-sdk" | Select-Object -First 1
if (-not $sdkRoot) {
throw "SDK root not found under build/_deps/livekit-sdk"
}
Write-Host "SDK root: $($sdkRoot.FullName)"
# Make sure DLLs are found at runtime
$env:PATH = "$($sdkRoot.FullName)\bin;$($sdkRoot.FullName)\lib;$env:PATH"
# Locate the built executable
$exe = Get-ChildItem -Recurse build -Filter basic_room.exe | Select-Object -First 1
if (-not $exe) {
throw "basic_room.exe not found in build directory"
}
Write-Host "Running $($exe.FullName) --help"
# Try to execute it. We only care that it launches.
$out = & $exe.FullName --self-test 2>&1
$code = $LASTEXITCODE
if ($code -ne 0) {
Write-Host $out
throw "basic_room.exe --self-test failed with exit code $code"
}
Write-Host $out

# ---------- upload build output ----------
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: basic_room-${{ matrix.name }}
path: |
build/basic_room*
build/basic_room.exe
retention-days: 7
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.cache/
CMakeFiles/
CMakeCache.txt
.DS_Store
Makefile
cmake_install.cmake
out
build/
build-debug/
build-release/
vcpkg_installed/
received_green.avif
docs/*.bak
docs/html/
docs/latex/
.vs/
.vscode/
# Compiled output
bin/
lib/
*.lib
*.a
*.so
*.dylib
*.dll
*.exe
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.20)
project(livekit_cpp_example_collection LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Make "include(LiveKitSDK)" search in ./cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(LIVEKIT_SDK_VERSION "latest" CACHE STRING "LiveKit C++ SDK version (e.g. 0.2.0 or latest)")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(LiveKitSDK)

livekit_sdk_setup(
VERSION "${LIVEKIT_SDK_VERSION}"
SDK_DIR "${CMAKE_BINARY_DIR}/_deps/livekit-sdk"
GITHUB_TOKEN "$ENV{GITHUB_TOKEN}"
)

find_package(LiveKit CONFIG REQUIRED)
add_subdirectory(basic_room)
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,73 @@
# cpp-example-collection
A collection of small examples for the LiveKit C++ SDK: https://github.com/livekit/client-sdk-cpp
This repository contains a collection of small, self-contained examples for the
[LiveKit C++ SDK](https://github.com/livekit/client-sdk-cpp).

The goal of these examples is to demonstrate common usage patterns of the
LiveKit C++ SDK (connecting to a room, publishing tracks, RPC, data streams,
etc.) without requiring users to build the SDK from source.


## How the SDK is provided

These examples **automatically download a prebuilt LiveKit C++ SDK release**
from GitHub at CMake configure time.

This is handled by the cmake helper: [LiveKitSDK.cmake ](https://github.com/livekit-examples/cpp-example-collection/cmake/LiveKitSDK.cmake)

## Selecting a LiveKit SDK version

By default, the examples download the **latest released** LiveKit C++ SDK.

You can pin a specific SDK version using the `LIVEKIT_SDK_VERSION` CMake option.

### Examples

Use the latest release:
```bash
cmake -S . -B build
# Or use a specific version (recommended for reproducibility):
cmake -S . -B build -DLIVEKIT_SDK_VERSION=0.2.0
```

Reconfigure to change versions:
```bash
rm -rf build
cmake -S . -B build -DLIVEKIT_SDK_VERSION=0.3.1
```


### Building the examples
#### macOS / Linux
```bash
cmake -S . -B build # add -DLIVEKIT_SDK_VERSION=0.2.0 if using a specific version
cmake --build build
```

#### Windows (Visual Studio generator)
```powershell
cmake -S . -B build # add -DLIVEKIT_SDK_VERSION=0.2.0 if using a specific version
cmake --build build --config Release
```

The Livekit Release SDK is downloaded into **build/_deps/livekit-sdk/**

### Running the examples

After building, example binaries are located under:
```bash
build/<example-name>/
```

For example:
```bash
./build/basic_room/basic_room --url <ws-url> --token <token>
```

### Supported platforms

Prebuilt SDKs are downloaded automatically for:
* Windows: x64
* macOS: x64, arm64 (Apple Silicon)
* Linux: x64

If no matching SDK is available for your platform, CMake configuration will fail with a clear error.
45 changes: 45 additions & 0 deletions basic_room/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
add_executable(basic_room
main.cpp
capture_utils.cpp
capture_utils.h
)

target_include_directories(basic_room PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(basic_room PRIVATE LiveKit::livekit)

# Make -llivekit_ffi resolvable
get_filename_component(_lk_cmake_dir "${LiveKit_DIR}" DIRECTORY) # .../lib/cmake
get_filename_component(_lk_lib_dir "${_lk_cmake_dir}" DIRECTORY) # .../lib
target_link_directories(basic_room PRIVATE "${_lk_lib_dir}")



# Nice-to-have: copy runtime DLLs next to the exe on Windows for "run from build dir".
# Only do this if your exported package provides these targets.
if(WIN32)
# livekit_ffi.dll
if(TARGET LiveKit::livekit_ffi)
add_custom_command(TARGET basic_room POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:LiveKit::livekit_ffi>"
"$<TARGET_FILE_DIR:basic_room>"
)
endif()

# If you also export protobuf/abseil runtime targets, copy them too (optional).
if(TARGET protobuf::libprotobuf)
add_custom_command(TARGET basic_room POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:protobuf::libprotobuf>"
"$<TARGET_FILE_DIR:basic_room>"
)
endif()

if(TARGET absl::abseil_dll)
add_custom_command(TARGET basic_room POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:absl::abseil_dll>"
"$<TARGET_FILE_DIR:basic_room>"
)
endif()
endif()
Loading
Loading