Skip to content

Commit aedb6f4

Browse files
Merge branch 'bugfix/clang-tidy' of github.com:livekit/client-sdk-cpp into bugfix/clang-tidy
2 parents 897fcfa + 54599fb commit aedb6f4

27 files changed

Lines changed: 882 additions & 114 deletions

.token_helpers/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Overview
2+
Examples of generating tokens
3+
4+
## gen_and_set.bash
5+
Generate tokens and then set them as env vars for the current terminal session
6+
7+
## set_data_track_test_tokens.bash
8+
Generate tokens for data track integration tests and set them as env vars for the current terminal session.

.token_helpers/gen_and_set.bash

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026 LiveKit, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Generate a LiveKit access token via `lk` and set LIVEKIT_TOKEN (and LIVEKIT_URL)
17+
# for your current shell session.
18+
#
19+
# source examples/tokens/gen_and_set.bash --id PARTICIPANT_ID --room ROOM_NAME [--view-token]
20+
# eval "$(bash examples/tokens/gen_and_set.bash --id ID --room ROOM [--view-token])"
21+
#
22+
# Optional env: LIVEKIT_API_KEY, LIVEKIT_API_SECRET, LIVEKIT_VALID_FOR.
23+
24+
# When sourced, we must NOT enable errexit/pipefail on the interactive shell — a
25+
# failing pipeline (e.g. sed|head SIGPIPE) or any error would close your terminal.
26+
27+
_sourced=0
28+
if [[ -n "${BASH_VERSION:-}" ]] && [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
29+
_sourced=1
30+
elif [[ -n "${ZSH_VERSION:-}" ]] && [[ "${ZSH_EVAL_CONTEXT:-}" == *:file* ]]; then
31+
_sourced=1
32+
fi
33+
34+
_fail() {
35+
echo "gen_and_set.bash: $1" >&2
36+
if [[ "$_sourced" -eq 1 ]]; then
37+
return "${2:-1}"
38+
fi
39+
exit "${2:-1}"
40+
}
41+
42+
_usage() {
43+
echo "Usage: ${0##*/} --id PARTICIPANT_IDENTITY --room ROOM_NAME [--view-token]" >&2
44+
echo " --id LiveKit participant identity (required)" >&2
45+
echo " --room Room name (required; not read from env)" >&2
46+
echo " --view-token Print the JWT to stderr after generating" >&2
47+
}
48+
49+
if [[ "$_sourced" -eq 0 ]]; then
50+
set -euo pipefail
51+
fi
52+
53+
_view_token=0
54+
LIVEKIT_IDENTITY=""
55+
LIVEKIT_ROOM="robo_room"
56+
while [[ $# -gt 0 ]]; do
57+
case "$1" in
58+
--view-token)
59+
_view_token=1
60+
shift
61+
;;
62+
--id)
63+
if [[ $# -lt 2 ]]; then
64+
_usage
65+
_fail "--id requires a value" 2
66+
fi
67+
LIVEKIT_IDENTITY="$2"
68+
shift 2
69+
;;
70+
--room)
71+
if [[ $# -lt 2 ]]; then
72+
_usage
73+
_fail "--room requires a value" 2
74+
fi
75+
LIVEKIT_ROOM="$2"
76+
shift 2
77+
;;
78+
-h | --help)
79+
_usage
80+
if [[ "$_sourced" -eq 1 ]]; then
81+
return 0
82+
fi
83+
exit 0
84+
;;
85+
*)
86+
_usage
87+
_fail "unknown argument: $1" 2
88+
;;
89+
esac
90+
done
91+
92+
if [[ -z "$LIVEKIT_IDENTITY" ]]; then
93+
_usage
94+
_fail "--id is required" 2
95+
fi
96+
if [[ -z "$LIVEKIT_ROOM" ]]; then
97+
_usage
98+
_fail "--room is required" 2
99+
fi
100+
101+
LIVEKIT_API_KEY="${LIVEKIT_API_KEY:-devkey}"
102+
LIVEKIT_API_SECRET="${LIVEKIT_API_SECRET:-secret}"
103+
LIVEKIT_VALID_FOR="${LIVEKIT_VALID_FOR:-99999h}"
104+
_grant_json='{"canPublish":true,"canSubscribe":true,"canPublishData":true}'
105+
106+
if ! command -v lk >/dev/null 2>&1; then
107+
_fail "'lk' CLI not found. Install: https://docs.livekit.io/home/cli/" 2
108+
fi
109+
110+
# Run lk inside bash so --grant JSON (with embedded ") is safe when this file is
111+
# sourced from zsh; zsh misparses --grant "$json" on the same line.
112+
_out="$(
113+
bash -c '
114+
lk token create \
115+
--api-key "$1" \
116+
--api-secret "$2" \
117+
-i "$3" \
118+
--join \
119+
--valid-for "$4" \
120+
--room "$5" \
121+
--grant "$6" 2>&1
122+
' _ "$LIVEKIT_API_KEY" "$LIVEKIT_API_SECRET" "$LIVEKIT_IDENTITY" \
123+
"$LIVEKIT_VALID_FOR" "$LIVEKIT_ROOM" "$_grant_json"
124+
)"
125+
_lk_st=$?
126+
if [[ "$_lk_st" -ne 0 ]]; then
127+
echo "$_out" >&2
128+
_fail "lk token create failed" 1
129+
fi
130+
131+
# Avoid sed|head pipelines (pipefail + SIGPIPE can kill a sourced shell).
132+
LIVEKIT_TOKEN=""
133+
LIVEKIT_URL=""
134+
while IFS= read -r _line || [[ -n "${_line}" ]]; do
135+
if [[ "$_line" == "Access token: "* ]]; then
136+
LIVEKIT_TOKEN="${_line#Access token: }"
137+
elif [[ "$_line" == "Project URL: "* ]]; then
138+
LIVEKIT_URL="${_line#Project URL: }"
139+
fi
140+
done <<< "$_out"
141+
142+
if [[ -z "$LIVEKIT_TOKEN" ]]; then
143+
echo "gen_and_set.bash: could not parse Access token from lk output:" >&2
144+
echo "$_out" >&2
145+
_fail "missing Access token line" 1
146+
fi
147+
148+
if [[ "$_view_token" -eq 1 ]]; then
149+
echo "$LIVEKIT_TOKEN" >&2
150+
fi
151+
152+
_apply() {
153+
export LIVEKIT_TOKEN
154+
export LIVEKIT_URL
155+
}
156+
157+
_emit_eval() {
158+
printf 'export LIVEKIT_TOKEN=%q\n' "$LIVEKIT_TOKEN"
159+
[[ -n "$LIVEKIT_URL" ]] && printf 'export LIVEKIT_URL=%q\n' "$LIVEKIT_URL"
160+
}
161+
162+
if [[ "$_sourced" -eq 1 ]]; then
163+
_apply
164+
echo "LIVEKIT_TOKEN and LIVEKIT_URL set for this shell." >&2
165+
[[ -n "$LIVEKIT_URL" ]] || echo "gen_and_set.bash: warning: no Project URL in output; set LIVEKIT_URL manually." >&2
166+
else
167+
_emit_eval
168+
echo "gen_and_set.bash: for this shell run: source $0 --id ... --room ... or: eval \"\$(bash $0 ...)\"" >&2
169+
fi
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026 LiveKit, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Generate two LiveKit access tokens via `lk` and set the environment variables
17+
# required by src/tests/integration/test_data_track.cpp.
18+
#
19+
# source examples/tokens/set_data_track_test_tokens.bash
20+
# eval "$(bash examples/tokens/set_data_track_test_tokens.bash)"
21+
#
22+
# Exports:
23+
# LK_TOKEN_TEST_A
24+
# LK_TOKEN_TEST_B
25+
# LIVEKIT_URL=ws://localhost:7880
26+
#
27+
28+
_sourced=0
29+
if [[ -n "${BASH_VERSION:-}" ]] && [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
30+
_sourced=1
31+
elif [[ -n "${ZSH_VERSION:-}" ]] && [[ "${ZSH_EVAL_CONTEXT:-}" == *:file* ]]; then
32+
_sourced=1
33+
fi
34+
35+
_fail() {
36+
echo "set_data_track_test_tokens.bash: $1" >&2
37+
if [[ "$_sourced" -eq 1 ]]; then
38+
return "${2:-1}"
39+
fi
40+
exit "${2:-1}"
41+
}
42+
43+
if [[ "$_sourced" -eq 0 ]]; then
44+
set -euo pipefail
45+
fi
46+
47+
LIVEKIT_ROOM="cpp_data_track_test"
48+
LIVEKIT_IDENTITY_A="cpp-test-a"
49+
LIVEKIT_IDENTITY_B="cpp-test-b"
50+
LIVEKIT_CALLER_IDENTITY="caller"
51+
LIVEKIT_RECEIVER_IDENTITY="receiver"
52+
53+
if [[ $# -ne 0 ]]; then
54+
_fail "this script is hard-coded and does not accept arguments" 2
55+
fi
56+
57+
LIVEKIT_API_KEY="devkey"
58+
LIVEKIT_API_SECRET="secret"
59+
LIVEKIT_VALID_FOR="99999h"
60+
LIVEKIT_URL="ws://localhost:7880"
61+
_grant_json='{"canPublish":true,"canSubscribe":true,"canPublishData":true}'
62+
63+
if ! command -v lk >/dev/null 2>&1; then
64+
_fail "'lk' CLI not found. Install: https://docs.livekit.io/home/cli/" 2
65+
fi
66+
67+
_create_token() {
68+
local identity="$1"
69+
local output=""
70+
local command_status=0
71+
local token=""
72+
73+
output="$(
74+
bash -c '
75+
lk token create \
76+
--api-key "$1" \
77+
--api-secret "$2" \
78+
-i "$3" \
79+
--join \
80+
--valid-for "$4" \
81+
--room "$5" \
82+
--grant "$6" 2>&1
83+
' _ "$LIVEKIT_API_KEY" "$LIVEKIT_API_SECRET" "$identity" \
84+
"$LIVEKIT_VALID_FOR" "$LIVEKIT_ROOM" "$_grant_json"
85+
)"
86+
command_status=$?
87+
if [[ "$command_status" -ne 0 ]]; then
88+
echo "$output" >&2
89+
_fail "lk token create failed for identity '$identity'" 1
90+
fi
91+
92+
while IFS= read -r line || [[ -n "${line}" ]]; do
93+
if [[ "$line" == "Access token: "* ]]; then
94+
token="${line#Access token: }"
95+
break
96+
fi
97+
done <<< "$output"
98+
99+
if [[ -z "$token" ]]; then
100+
echo "$output" >&2
101+
_fail "could not parse Access token for identity '$identity'" 1
102+
fi
103+
104+
printf '%s' "$token"
105+
}
106+
107+
LK_TOKEN_TEST_A="$(_create_token "$LIVEKIT_IDENTITY_A")"
108+
LK_TOKEN_TEST_B="$(_create_token "$LIVEKIT_IDENTITY_B")"
109+
LIVEKIT_CALLER_TOKEN="$(_create_token "$LIVEKIT_CALLER_IDENTITY")"
110+
LIVEKIT_RECEIVER_TOKEN="$(_create_token "$LIVEKIT_RECEIVER_IDENTITY")"
111+
_apply() {
112+
export LK_TOKEN_TEST_A
113+
export LK_TOKEN_TEST_B
114+
export LIVEKIT_CALLER_TOKEN
115+
export LIVEKIT_RECEIVER_TOKEN
116+
export LIVEKIT_URL
117+
}
118+
119+
_emit_eval() {
120+
printf 'export LK_TOKEN_TEST_A=%q\n' "$LK_TOKEN_TEST_A"
121+
printf 'export LK_TOKEN_TEST_B=%q\n' "$LK_TOKEN_TEST_B"
122+
printf 'export LIVEKIT_CALLER_TOKEN=%q\n' "$LIVEKIT_CALLER_TOKEN"
123+
printf 'export LIVEKIT_RECEIVER_TOKEN=%q\n' "$LIVEKIT_RECEIVER_TOKEN"
124+
printf 'export LIVEKIT_URL=%q\n' "$LIVEKIT_URL"
125+
}
126+
127+
if [[ "$_sourced" -eq 1 ]]; then
128+
_apply
129+
echo "LK_TOKEN_TEST_A, LK_TOKEN_TEST_B, LIVEKIT_CALLER_TOKEN, LIVEKIT_RECEIVER_TOKEN, and LIVEKIT_URL set for this shell." >&2
130+
else
131+
_emit_eval
132+
echo "set_data_track_test_tokens.bash: for this shell run: source $0 or: eval \"\$(bash $0 ...)\"" >&2
133+
fi

AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ All source files must have the LiveKit Apache 2.0 copyright header. Use the curr
145145
- Use `LK_LOG_WARN` for non-fatal unexpected conditions.
146146
- Use `Result<T, E>` for operations that can fail with typed errors (e.g., data track publish/subscribe).
147147

148+
### Integer Types
149+
150+
- Prefer fixed-width integer types from `<cstdint>` (`std::int32_t`, `std::uint64_t`, etc.) over raw primitive integer types when size or signedness matters.
151+
- This applies in public APIs, FFI/protobuf-facing code, serialized payloads, handles, timestamps, IDs, and any cross-platform boundary where integer width must be explicit.
152+
- Use raw primitive integer types only when the value is intentionally platform-sized or when preserving an existing public API is necessary for backwards compatibility.
153+
- Do not change an existing public API from a raw primitive integer type to a fixed-width type for style consistency alone unless the compatibility impact has been reviewed.
154+
148155
### Git Practices
149156

150157
- Use `git mv` when moving or renaming files.

client-sdk-rust

include/livekit/local_track_publication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Track;
2828

2929
class LocalTrackPublication : public TrackPublication {
3030
public:
31-
/// Note, this RemoteTrackPublication is constructed internally only;
31+
/// Note, this LocalTrackPublication is constructed internally only;
3232
/// safe to accept proto::OwnedTrackPublication.
3333
explicit LocalTrackPublication(const proto::OwnedTrackPublication &owned);
3434

include/livekit/remote_video_track.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class RemoteVideoTrack : public Track {
5050
/// Returns a concise, human-readable string summarizing the track,
5151
/// including its SID and name. Useful for debugging and logging.
5252
std::string to_string() const;
53-
54-
private:
5553
};
5654

5755
} // namespace livekit

include/livekit/room.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,39 @@ class Room {
245245
*/
246246
void setOnAudioFrameCallback(const std::string &participant_identity,
247247
TrackSource source, AudioFrameCallback callback,
248-
AudioStream::Options opts = {});
248+
const AudioStream::Options &opts = {});
249249

250250
/**
251251
* @brief Sets the audio frame callback via SubscriptionThreadDispatcher.
252252
*/
253253
void setOnAudioFrameCallback(const std::string &participant_identity,
254254
const std::string &track_name,
255255
AudioFrameCallback callback,
256-
AudioStream::Options opts = {});
256+
const AudioStream::Options &opts = {});
257257

258258
/**
259259
* @brief Sets the video frame callback via SubscriptionThreadDispatcher.
260260
*/
261261
void setOnVideoFrameCallback(const std::string &participant_identity,
262262
TrackSource source, VideoFrameCallback callback,
263-
VideoStream::Options opts = {});
263+
const VideoStream::Options &opts = {});
264264

265265
/**
266266
* @brief Sets the video frame callback via SubscriptionThreadDispatcher.
267267
*/
268268
void setOnVideoFrameCallback(const std::string &participant_identity,
269269
const std::string &track_name,
270270
VideoFrameCallback callback,
271-
VideoStream::Options opts = {});
271+
const VideoStream::Options &opts = {});
272+
273+
/**
274+
* @brief Sets the video frame event callback via
275+
* SubscriptionThreadDispatcher.
276+
*/
277+
void setOnVideoFrameEventCallback(const std::string &participant_identity,
278+
const std::string &track_name,
279+
VideoFrameEventCallback callback,
280+
const VideoStream::Options &opts = {});
272281

273282
/**
274283
* @brief Clears the audio frame callback via SubscriptionThreadDispatcher.

0 commit comments

Comments
 (0)