Skip to content

Commit 78dc1ca

Browse files
authored
Improve connection reliability (#18)
* Create minimal example * Wip * Connect signal * Signal refactor * Connect primary peer * Remove dead code * Use event queue approach * Introduce timer * Proper cleanup * Implement reconnecting state * Remove disconnecting state * Reintroduce all features * Add additional transitions * Docs and organization * Remove any state handler * Change event memory model * Store local participant ID * Consolidate event detail cases * Cleanup session state * Engine refactor - Handle all signal responses in state machine - Helper functions for protocol messages * Simplify state machine memory model Always discard events * Helper methods for data packets * Allow engine to take ownership of data packet * Process data packets via state machine * Notify of engine state change * Add documentation * Allow handlers to take ownership of events * Exponential backoff * Create helper to enqueue events * Zero initialize protobuf structs * Ignore non-binary messages silently * Make engine state internal * Document * Handle and expose failure reason - Do not retry for client errors - Expose failure reason through public API * Extract into helpers * Unify peer state change handling * Free event if cannot enqueue * URL build options struct * Map disconnect reason to failure reason * Send leave on user-initiated close * Separate session state * Reenable track subscription * Decode tag on fail * Ignore proto messages * Add markers * Fix state reporting bug Optimizer causes issue where enum return value cannot be -1 * Improve signal state handling - Signal state enum with failure reason - Handle normal WS closure * Remove unneeded includes * Retry on peer disconnect in addition to fail * Remove unneeded config * Refactor signal client - Handle ping timeout - Use FreeRTOS timer instead of esp_timer (ms accuracy is sufficient) - Ensure cleanup under abnormal closure conditions (e.g. WiFi disconnect) * Cleanup signal client init * Cleanup engine init * Use protocol helper for encoding requests * Use protocol helpers for encoding data packets * Inline remaining protocol helpers * Use consistent naming convention * Make nanopb encode/decode includes private * Simplify internal API * Send data packets * Zero only * Remove state guards for sub audio Audio stream can begin while still in connecting state * Handle room and participant update in connecting state Early participant update messages are necessary to subscribe to remote track * Cleanup previous connection in backoff Perform same cleanup steps when entering both disconnected and backoff * Handle ICE servers Reintroduce support for dynamically setting ICE servers, use hardcoded for now. * Use SAFE_FREE macro * Remove dead code * Do not handle data packets in FSM * Add basic connection time benchmarking * Queue peer SDP messages * Clean up * Increase timer stack depth * Fix typo * Document how to get failure reason * Data packet optimization - Ignore types that are not supported yet - Fixed length sender SID * Signal response optimization - Ignore types that are not supported yet * Fix incorrect field type * Fix voice agent example agent join * Demonstrate getting failure reason in all examples * Consistent sdkconfig defaults between examples * Bump version
1 parent 550bec8 commit 78dc1ca

37 files changed

+2254
-909
lines changed

components/livekit/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ idf_component_register(
88
PRIV_REQUIRES
99
esp_codec_dev
1010
esp_netif
11-
esp_timer
1211
esp_websocket_client
1312
esp_webrtc
1413
json

components/livekit/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
menu "LiveKit"
2+
config LK_MAX_RETRIES
3+
int "Maximum connection retries"
4+
range 0 100
5+
default 7
6+
config LK_MAX_ICE_SERVERS
7+
int "Maximum number of ICE servers"
8+
default 3
9+
config LK_BENCHMARK
10+
bool "Benchmark connection time"
11+
default n
12+
config LK_ENGINE_QUEUE_SIZE
13+
int "Number of engine events to queue"
14+
default 32
15+
config LK_PUB_INTERVAL_MS
16+
int "How often to capture and send AV frames"
17+
default 20
18+
config LK_PUB_AUDIO_TRACK_NAME
19+
string "Name of the published audio track"
20+
default "Audio"
21+
config LK_PUB_VIDEO_TRACK_NAME
22+
string "Name of the published video track"
23+
default "Video"
24+
endmenu

components/livekit/core/common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
extern "C" {
1010
#endif
1111

12-
/// State of an engine component or the engine itself.
12+
/// State of a connection.
1313
typedef enum {
14-
CONNECTION_STATE_DISCONNECTED = 0, /*!< Disconnected */
15-
CONNECTION_STATE_CONNECTING = 1, /*!< Establishing connection */
16-
CONNECTION_STATE_CONNECTED = 2, /*!< Connected */
17-
CONNECTION_STATE_RECONNECTING = 3, /*!< Connection was previously established, but was lost */
18-
CONNECTION_STATE_FAILED = 4 /*!< Connection failed */
14+
CONNECTION_STATE_DISCONNECTED = 0, /// Disconnected
15+
CONNECTION_STATE_CONNECTING = 1, /// Establishing connection
16+
CONNECTION_STATE_CONNECTED = 2, /// Connected
17+
CONNECTION_STATE_RECONNECTING = 3, /// Connection was previously established, but was lost
18+
CONNECTION_STATE_FAILED = 4 /// Connection failed
1919
} connection_state_t;
2020

2121
typedef struct {

0 commit comments

Comments
 (0)