Skip to main content
Version: 0.0.x

Initialise Meeting - IoT

To configure a VideoSDK meeting you require two things, first the token which will be used for Authentication purpose and a meetingId which will be used to specify where a participant will join. Let's see each of the steps closely.

Generating Token

You can generate a token in two ways:

  1. Temporary Token : You can visit Dashboard's API Key section and generate the temporary token from there.

  2. Server : You can setup JWT in backend and make an API call to get the token from your server.

To learn more about Authentication and token in detail you can follow this guide.

TOKEN GENERATION
const jwt = require('jsonwebtoken');

const API_KEY = <YOUR API KEY>;
const SECRET = <YOUR SECRET>;

const options = {
expiresIn: '120m',
algorithm: 'HS256'
};
const payload = {
apikey: API_KEY,
permissions: [`allow_join`], // `ask_join` || `allow_mod`
version: 2, //OPTIONAL
roomId: `2kyv-gzay-64pg`, //OPTIONAL
participantId: `lxvdplwt`, //OPTIONAL
roles: ['crawler', 'rtc'], //OPTIONAL
};

const token = jwt.sign(payload, SECRET, options);
console.log(token);

Generating Meeting Id

For generating the meetingId you can use the function present in the IoT Sdk which is create_meeting which will return create_meeting_result_t.

  • create_meeting_result_t contains two fields:
    1. Result Code
    2. room_id
note

If there is any error in the code, the function will stop performing its task and it will return the result code defined in result_t (please refer to this) in such cases, it will return NULL in room_id.

char * token = "Generated token from Dashboard/API";
create_meeting_result_t result = create_meeting(token);
if (result.room_id) {
ESP_LOGI("IOT-SDK", "Created meeting roomId = %s", result.room_id);
free(result.room_id);
} else {
ESP_LOGE("IOT-SDK", "Failed to create meeting");
}

Initialization of Meeting

  • This function initiates the VideoSDK IoT client with the configuration provided in an init_config_t structure.
  • If the initialization succeeds it will return 0; otherwise it returns an error.
note
  • init() must be called exactly once, before starting publish or subscribe operations.

  • Call the SDK from a single task (for example app_main). The API is not thread-safe, so do not call these methods concurrently from multiple tasks.

init_config_t init_cfg = {
.meetingID = "Your meeting id ",
.token = "your authentication token",
.displayName = "ESP32-Device",
.participantId = "your participant id", // "" or NULL => a random id is generated
.audioCodec = AUDIO_CODEC_PCMA, // PCMA, PCMU or OPUS
.videoCodec = VIDEO_CODEC_JPEG, // or VIDEO_CODEC_NONE for no video
};

init(&init_cfg);

tip

Register your callbacks right after init() and before the start* calls, so early events are delivered. Use setDataMessageHandler() for incoming messages and setConnectionStateHandler() for signaling connection changes.

  • MeetingId :

    • MeetingId is unique identifiers that allow participants to join a specific meeting or room.
    • It will be in the format of xxx-yyy-zzz and will be generated using the create_meeting method or VideoSDK's Room API.
  • token :

    • A unique token allocated for each user by the videosdk.
    • This token allows to authorize meeting participants.
  • displayName:

    • This will represent the name of the participant in the meeting.
    • It accepts a char* value. If you pass NULL or an empty string, the SDK generates one for you.
  • participantId:

    • The participant identity used for the whole session, shared by audio, video, subscribe and the message channel.
    • It accepts a char* value. If you pass NULL or an empty string, the SDK generates a random ID for you.
    • Each participant in a meeting must have a unique participantId.
  • audioCodec:

    • An audio codec is a software component that encodes and decodes digital audio data.
    • This enum audio_codec_t defines the supported audio codecs, where PCMA and PCMU are standard telephony codecs, and OPUS is a modern codec optimized for real-time audio.
typedef enum {
AUDIO_CODEC_PCMA = 0, // G.711 A-law, 8 kHz mono
AUDIO_CODEC_PCMU, // G.711 u-law, 8 kHz mono
AUDIO_CODEC_OPUS, // Opus
} audio_codec_t;
tip

The audio codec can be configured via audio_codec_t. Example: .audioCodec = AUDIO_CODEC_PCMA

  • videoCodec:

    • Declares the video format used when video is published. The video_codec_t enum defines the supported video codecs. Use VIDEO_CODEC_JPEG to enable video; VIDEO_CODEC_NONE (the default) is audio only.
    • See Publish Video to stream the device camera.
typedef enum {
VIDEO_CODEC_NONE = 0, // audio only (default)
VIDEO_CODEC_JPEG, // hardware-JPEG camera frames
} video_codec_t;
tip

Set .videoCodec = VIDEO_CODEC_JPEG when you plan to publish or subscribe to video.

Example code


void app_main(void) {
/*This function allow us to create a Meeting ID with the help of the token and
on passing the wrong token it returns an error "Failed to created meeting"
*/
char * token = "Generated token from Dashboard/API";
create_meeting_result_t result = create_meeting(token);
if (result.room_id) {
ESP_LOGI("IOT-SDK", "Created meeting roomId = %s", result.room_id);
free(result.room_id);
} else {
ESP_LOGE("IOT-SDK", "Failed to create meeting");
}
/* this function allow us to create a meeting by authenticating
the meetingID, token, audioCodec and dislayName */
init_config_t init_cfg = {
.meetingID = "your meeting id",
.token = "your authentication token",
.displayName = "ESP32-Device",
.participantId = "your participant id",
.audioCodec = AUDIO_CODEC_PCMA,
.videoCodec = VIDEO_CODEC_JPEG,
};

init(&init_cfg);

while (1) {
vTaskDelay(pdMS_TO_TICKS(10));
}
}

API Reference

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord