Skip to content

Commit

Permalink
Create DataChannel by default
Browse files Browse the repository at this point in the history
  • Loading branch information
seaduboi-openai committed Jan 3, 2025
1 parent 87f96f7 commit 91790f1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/webrtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ void oai_send_audio_task(void *user_data) {
}
#endif

static void oai_ondatachannel_onmessage_task(char *msg, size_t len,
void *userdata, uint16_t sid) {
ESP_LOGI(LOG_TAG, "DataChannel Message: %s", msg);
}

static void oai_ondatachannel_onopen_task(void *userdata) {
if (peer_connection_create_datachannel(peer_connection, DATA_CHANNEL_RELIABLE,
0, 0, (char *)"", (char *)"") == -1) {
ESP_LOGE(LOG_TAG, "Failed to create DataChannel");
}
}

static void oai_onconnectionstatechange_task(PeerConnectionState state,
void *user_data) {
ESP_LOGI(LOG_TAG, "PeerConnectionState: %s",
Expand Down Expand Up @@ -56,7 +68,7 @@ void oai_webrtc() {
.ice_servers = {},
.audio_codec = CODEC_OPUS,
.video_codec = CODEC_NONE,
.datachannel = DATA_CHANNEL_NONE,
.datachannel = DATA_CHANNEL_STRING,
.onaudiotrack = [](uint8_t *data, size_t size, void *userdata) -> void {
#ifndef LINUX_BUILD
oai_audio_decode(data, size);
Expand All @@ -78,6 +90,10 @@ void oai_webrtc() {
peer_connection_oniceconnectionstatechange(peer_connection,
oai_onconnectionstatechange_task);
peer_connection_onicecandidate(peer_connection, oai_on_icecandidate_task);
peer_connection_ondatachannel(peer_connection,
oai_ondatachannel_onmessage_task,
oai_ondatachannel_onopen_task, NULL);

peer_connection_create_offer(peer_connection);

while (1) {
Expand Down

0 comments on commit 91790f1

Please sign in to comment.