Skip to content

Commit 2b9345e

Browse files
committed
fix(mosq): Add WebRTC implementation of peer_backend
1 parent 79b8ab5 commit 2b9345e

11 files changed

+304
-325
lines changed

components/mosquitto/examples/serverless_mqtt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
77
# Setup ESP-PEER from GitHub repo (but it's supported only on certain targets)
88
set(ESP_PEER_COMPATIBLE_TARGETS "esp32s2" "esp32s3" "esp32p4" "esp32")
99
if(IDF_TARGET IN_LIST ESP_PEER_COMPATIBLE_TARGETS)
10-
execute_process(COMMAND ${CMAKE_BINARY_DIR}/../esp_peer_setup.sh
10+
execute_process(COMMAND ${CMAKE_BINARY_DIR}/../esp_peer_setup/install.sh
1111
${CMAKE_BINARY_DIR}
1212
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
1313
RESULT_VARIABLE script_result)
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
From 06b15a30e860daef303b6c6541a2cae858c17e6c Mon Sep 17 00:00:00 2001
1+
From cdc43a56f5ea1ab1935f55f47f8644f5dd30825e Mon Sep 17 00:00:00 2001
22
From: David Cermak <cermak@espressif.com>
33
Date: Thu, 10 Jul 2025 11:09:57 +0200
44
Subject: [PATCH] fix(media_lib): Remove deprecated freeRTOS header
55

66
---
7-
components/media_lib_sal/port/media_lib_os_freertos.c | 2 +-
8-
1 file changed, 1 insertion(+), 1 deletion(-)
7+
components/media_lib_sal/port/media_lib_os_freertos.c | 4 ++++
8+
1 file changed, 4 insertions(+)
99

1010
diff --git a/components/media_lib_sal/port/media_lib_os_freertos.c b/components/media_lib_sal/port/media_lib_os_freertos.c
11-
index d248d59..7b588ca 100644
11+
index d248d59..aea0527 100644
1212
--- a/components/media_lib_sal/port/media_lib_os_freertos.c
1313
+++ b/components/media_lib_sal/port/media_lib_os_freertos.c
14-
@@ -40,7 +40,7 @@
14+
@@ -40,8 +40,12 @@
1515
#include "esp_idf_version.h"
1616

1717
#if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT
18-
-#include "freertos/task_snapshot.h"
18+
+#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0))
1919
+#include "esp_private/freertos_debug.h"
20+
+#else
21+
#include "freertos/task_snapshot.h"
2022
#endif
23+
+#endif
2124

2225
#ifdef __XTENSA__
26+
#include "esp_debug_helpers.h"
2327
--
2428
2.43.0

components/mosquitto/examples/serverless_mqtt/esp_peer_setup.sh renamed to components/mosquitto/examples/serverless_mqtt/esp_peer_setup/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COMPONENTS_SRC="${EXTRACTED_DIR}/components"
1414
COMPONENTS_DST="${ESP_PEER_DIR}/components"
1515
PATCH_FILE_1="${THIS_DIR}/Add-default-event-to-http-client-handler.patch"
1616
PATCH_FILE_2="${THIS_DIR}/Remove-deprecated-freeRTOS-header.patch"
17+
PATCH_FILE_3="${THIS_DIR}/libpeer-Add-direct-dependency-to-libsrtp.patch"
1718

1819
# Download if not exists
1920
if [ ! -d "$EXTRACTED_DIR" ]; then
@@ -22,6 +23,7 @@ if [ ! -d "$EXTRACTED_DIR" ]; then
2223
unzip -o "$ZIP_PATH" -d "$ESP_PEER_DIR"
2324
patch -p1 -d "$EXTRACTED_DIR" < "$PATCH_FILE_1"
2425
patch -p1 -d "$EXTRACTED_DIR" < "$PATCH_FILE_2"
26+
patch -p1 -d "$EXTRACTED_DIR" < "$PATCH_FILE_3"
2527
mv ${EXTRACTED_DIR}/components ${ESP_PEER_DIR}
2628
mv ${ESP_PEER_DIR}/components/esp_webrtc/impl/peer_default ${ESP_PEER_DIR}/components
2729
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From 695e057000698f4897b6c5802851499842e2fe31 Mon Sep 17 00:00:00 2001
2+
From: David Cermak <cermak@espressif.com>
3+
Date: Fri, 11 Jul 2025 16:59:21 +0200
4+
Subject: [PATCH] fix(libpeer): Add direct dependency to libsrtp
5+
6+
---
7+
components/esp_webrtc/impl/peer_default/CMakeLists.txt | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/components/esp_webrtc/impl/peer_default/CMakeLists.txt b/components/esp_webrtc/impl/peer_default/CMakeLists.txt
11+
index 2af35cf..3fb4615 100644
12+
--- a/components/esp_webrtc/impl/peer_default/CMakeLists.txt
13+
+++ b/components/esp_webrtc/impl/peer_default/CMakeLists.txt
14+
@@ -2,6 +2,6 @@ idf_component_register(INCLUDE_DIRS ./include)
15+
16+
get_filename_component(BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR} NAME)
17+
add_prebuilt_library(${BASE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/${IDF_TARGET}/libpeer_default.a"
18+
- PRIV_REQUIRES ${BASE_DIR} esp_timer)
19+
+ PRIV_REQUIRES ${BASE_DIR} esp_timer espressif__esp_libsrtp)
20+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/libs/${IDF_TARGET}")
21+
target_link_libraries(${COMPONENT_LIB} INTERFACE peer_default)
22+
--
23+
2.43.0

components/mosquitto/examples/serverless_mqtt/main/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
if(CONFIG_EXAMPLE_PEER_LIB_ESP_PEER)
2-
set(PEER_BACKEND_SRC "webrtc.c")
2+
set(PEER_BACKEND_SRC "peer_impl_webrtc.c")
3+
else()
4+
set(PEER_BACKEND_SRC "peer_impl_juice.c")
35
endif()
46

5-
idf_component_register(SRCS "serverless_mqtt.c" "peer_impl.c"
7+
idf_component_register(SRCS "serverless_mqtt.c"
68
"wifi_connect.c"
79
"${PEER_BACKEND_SRC}"
810
INCLUDE_DIRS "."

components/mosquitto/examples/serverless_mqtt/main/Kconfig.projbuild

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,55 @@ menu "Example Configuration"
3333
WiFi station password for the example to use.
3434
endmenu
3535

36+
choice EXAMPLE_PEER_LIB
37+
prompt "Choose peer library"
38+
default EXAMPLE_PEER_LIB_LIBJUICE
39+
help
40+
Choose the peer library to use for WebRTC communication.
41+
libjuice: Use libjuice library for ICE/STUN/TURN (Performs manual signalling)
42+
esp_peer: Use ESP-IDF specific peer library
43+
44+
config EXAMPLE_PEER_LIB_ESP_PEER
45+
bool "esp_peer"
46+
47+
config EXAMPLE_PEER_LIB_LIBJUICE
48+
bool "libjuice"
49+
endchoice
50+
51+
config EXAMPLE_WEBRTC_URL
52+
string "WebRTC server URL"
53+
depends on EXAMPLE_PEER_LIB_ESP_PEER
54+
default "https://webrtc.espressif.com/join/"
55+
help
56+
URL of WebRTC remote endpoint.
57+
58+
config EXAMPLE_WEBRTC_ROOM_ID
59+
string "WebRTC room ID"
60+
depends on EXAMPLE_PEER_LIB_ESP_PEER
61+
default "12345"
62+
help
63+
Room ID for WebRTC synchronisation.
64+
Could be a random number, but the same for both peers.
65+
66+
3667
config EXAMPLE_MQTT_BROKER_URI
3768
string "MQTT Broker URL"
69+
depends on EXAMPLE_PEER_LIB_LIBJUICE
3870
default "mqtt://mqtt.eclipseprojects.io"
3971
help
4072
URL of the mqtt broker use for synchronisation and exchanging
4173
ICE connect info (description and candidates).
4274

4375
config EXAMPLE_MQTT_SYNC_TOPIC
4476
string "MQTT topic for synchronisation"
77+
depends on EXAMPLE_PEER_LIB_LIBJUICE
4578
default "/topic/serverless_mqtt"
4679
help
4780
MQTT topic used fo synchronisation.
4881

4982
config EXAMPLE_STUN_SERVER
5083
string "Hostname of STUN server"
84+
depends on EXAMPLE_PEER_LIB_LIBJUICE
5185
default "stun.l.google.com"
5286
help
5387
STUN server hostname.
@@ -67,6 +101,7 @@ menu "Example Configuration"
67101

68102
choice EXAMPLE_SERVERLESS_ROLE
69103
prompt "Choose your role"
104+
depends on EXAMPLE_PEER_LIB_LIBJUICE
70105
default EXAMPLE_SERVERLESS_ROLE_PEER1
71106
help
72107
Choose either peer1 or peer2.
@@ -82,19 +117,4 @@ menu "Example Configuration"
82117
bool "peer2"
83118
endchoice
84119

85-
choice EXAMPLE_PEER_LIB
86-
prompt "Choose peer library"
87-
default EXAMPLE_PEER_LIB_LIBJUICE
88-
help
89-
Choose the peer library to use for WebRTC communication.
90-
libjuice: Use libjuice library for ICE/STUN/TURN (Performs manual signalling)
91-
esp_peer: Use ESP-IDF specific peer library
92-
93-
config EXAMPLE_PEER_LIB_ESP_PEER
94-
bool "esp_peer"
95-
96-
config EXAMPLE_PEER_LIB_LIBJUICE
97-
bool "libjuice"
98-
endchoice
99-
100120
endmenu

components/mosquitto/examples/serverless_mqtt/main/idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dependencies:
33
espressif/mosquitto:
44
override_path: ../../..
55
espressif/sock_utils: "*"
6+
espressif/esp_libsrtp: "~1.0.0"

components/mosquitto/examples/serverless_mqtt/main/peer_impl.c renamed to components/mosquitto/examples/serverless_mqtt/main/peer_impl_juice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ esp_err_t peer_init(on_peer_recv_t cb)
6666
{
6767
esp_err_t ret = ESP_FAIL;
6868
ESP_GOTO_ON_FALSE(cb, ESP_ERR_INVALID_ARG, err, TAG, "Invalid peer receive callback");
69+
s_on_recv = cb;
6970
ESP_GOTO_ON_ERROR(create_candidates(), err, TAG, "Failed to create juice candidates");
7071
ESP_GOTO_ON_ERROR(sync_peers(), err, TAG, "Failed to sync with the other peer");
7172
EventBits_t bits = xEventGroupWaitBits(s_state, PEER_FAIL | PEER_CONNECTED, pdFALSE, pdFALSE, pdMS_TO_TICKS(90000));

0 commit comments

Comments
 (0)