} else if(!strcasecmp(request_text, "startrecording") || !strcasecmp(request_text, "stoprecording")) {
int starting = !strcasecmp(request_text, "startrecording") ? TRUE : FALSE;
janus_videoroom_participant *p = (janus_videoroom_participant *)session->participant;
if(p->room == NULL) {
JANUS_LOG(LOG_ERR, "No videoroom exists for participant %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
g_snprintf(error_cause, 512, "No videoroom exists for participant %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
goto error;
}
JANUS_LOG(LOG_INFO, "Locking room mutex...");
janus_mutex_lock(&rooms_mutex);
JANUS_LOG(LOG_INFO, "locked.\n");
janus_videoroom *videoroom = g_hash_table_lookup(rooms, &p->room->room_id);
if(videoroom->destroyed) {
JANUS_LOG(LOG_ERR, "No such room (%"SCNu64")\n", videoroom->room_id);
error_code = JANUS_VIDEOROOM_ERROR_NO_SUCH_ROOM;
g_snprintf(error_cause, 512, "Videoroom (%"SCNu64")", videoroom->room_id);
goto error;
}
if(videoroom->room_secret) {
/* A secret is required for this action */
json_t *secret = json_object_get(root, "secret");
if(!secret) {
JANUS_LOG(LOG_ERR, "Missing element (secret)\n");
error_code = JANUS_VIDEOROOM_ERROR_MISSING_ELEMENT;
g_snprintf(error_cause, 512, "Missing element (secret)");
goto error;
}
if(!json_is_string(secret)) {
JANUS_LOG(LOG_ERR, "Invalid element (secret should be a string)\n");
error_code = JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT;
g_snprintf(error_cause, 512, "Invalid element (secret should be a string)");
goto error;
}
if(!janus_strcmp_const_time(videoroom->room_secret, json_string_value(secret))) {
JANUS_LOG(LOG_ERR, "Unauthorized (wrong secret)\n");
error_code = JANUS_VIDEOROOM_ERROR_UNAUTHORIZED;
g_snprintf(error_cause, 512, "Unauthorized (wrong secret)");
goto error;
}
}
JANUS_LOG(LOG_INFO, "Unlocking rooms mutex...");
janus_mutex_unlock(&rooms_mutex);
JANUS_LOG(LOG_INFO, "done.\n");
janus_videoroom_set_recording_status(videoroom, starting, participant->user_id);
event = json_object();
json_object_set_new(event, "videoroom", json_string("event"));
json_object_set_new(event, "room", json_integer(participant->room->room_id));
if (starting) {
json_object_set_new(event, "startrecordingdone", json_string("ok"));
} else {
json_object_set_new(event, "stoprecordingdone", json_string("ok"));
}