Receive Message - IoT SDK
To receive application messages sent by other participants, register a handler with setDataMessageHandler(). Once a handler is set, the SDK delivers every incoming text or binary message to it. Without a handler, incoming messages are dropped.
Messages are sent by the other participant using sendMessage(). See Send Message.
setDataMessageHandler()
- The
setDataMessageHandler()function registers (or clears, by passingNULL) the callback invoked for each application message received from another participant. - Register the handler right after
init(), before yourstart*calls, so early messages are not missed.
This function takes one parameter:
- cb: a function pointer of type
data_message_cb_t, orNULLto clear a previously registered handler.
The callback has the following signature:
typedef void (*data_message_cb_t)(const uint8_t* data, size_t len,
int is_binary, uint16_t sid);
- data / len: the complete message and its length. Message reassembly is handled for you.
- is_binary:
1for a WebRTC binary message,0for a UTF-8 text message. - sid: the stream id the message arrived on.
Example
#include "videosdk.h"
#include "esp_log.h"
static const char *TAG = "IOT-SDK";
// Called for each application message from another participant.
static void on_data_message(const uint8_t *data, size_t len, int is_binary, uint16_t sid){
if (is_binary)
ESP_LOGI(TAG, "msg recv (binary) sid=%u len=%u", (unsigned)sid, (unsigned)len);
else
ESP_LOGI(TAG, "msg recv (text) sid=%u: %.*s", (unsigned)sid, (int)len, (const char *)data);
}
void app_main(){
// ... init(&init_cfg) ...
// Register the receive handler before starting streams.
setDataMessageHandler(on_data_message);
}
API Reference
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord

