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 (room_id) {
ESP_LOGI(TAG, "Created meeting roomId = %s", result.room_id);
free(result.room_id);
} else {
ESP_LOGE(TAG, "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

This function must be called before starting publish or subscribe operations.

init_config_t init_cfg = {
.meetingID = "Your meeting id ",
.token = "your authentication token",
.displayName = "ESP32-Device",
.audioCodec = AUDIO_CODEC_OPUS,
};

init(&init_cfg);

  • 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 will accept String type value.
  • 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 for the system, where PCMA and PCMU are standard telephony codecs, and OPUS is a modern codec optimized for real-time audio.
typedef enum {
AUDIO_CODEC_PCMA,
AUDIO_CODEC_PCMU,
AUDIO_CODEC_OPUS,
} audio_codec_t;
tip
  • The default audio codec is OPUS. It can be configured via audio_codec_t.
    Example: .audioCodec = AUDIO_CODEC_PCMA

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 (room_id) {
ESP_LOGI(TAG, "Created meeting roomId = %s", result.room_id);
free(result.room_id);
} else {
ESP_LOGE(TAG, "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 metting id npm run dev",
.displayName = "ESP32-Device",
.audioCodec = AUDIO_CODEC_PCMA,
};

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