I want to send custom message in audioplugin.For example, sending a broadcast message to everyone or a specific person.How should I modify the source code to achieve this function?
I added some code in the janus_audiobridge.c file:
response = janus_audiobridge_process_synchronous_request(session, root);
if(response != NULL) {
/* We got a response, send it back */
goto plugin_response;
} else if(!strcasecmp(request_text, "join") || !strcasecmp(request_text, "configure")
|| !strcasecmp(request_text, "changeroom") || !strcasecmp(request_text, "leave")
|| !strcasecmp(request_text, "hangup")|| !strcasecmp(request_text, "abcd")) {
/* These messages are handled asynchronously */
janus_audiobridge_message *msg = g_malloc(sizeof(janus_audiobridge_message));
msg->handle = handle;
msg->transaction = transaction;
msg->message = root;
msg->jsep = jsep;
g_async_queue_push(messages, msg);
return janus_plugin_result_new(JANUS_PLUGIN_OK_WAIT, NULL, NULL);
} else {
JANUS_LOG(LOG_VERB, "Unknown request '%s'\n", request_text);
error_code = JANUS_AUDIOBRIDGE_ERROR_INVALID_REQUEST;
g_snprintf(error_cause, 512, "Unknown request '%s'", request_text);
}
else if(!strcasecmp(request_text, "hangup")) {
janus_mutex_unlock(&sessions_mutex);
/* Get rid of an ongoing session */
gateway->close_pc(session->handle);
event = json_object();
json_object_set_new(event, "audiobridge", json_string("hangingup"));
} else if(!strcasecmp(request_text, "abcd")) {
janus_mutex_unlock(&sessions_mutex);
/* This participant is leaving */
janus_audiobridge_participant *participant = (janus_audiobridge_participant *)session->participant;
if(participant == NULL || participant->room == NULL) {
JANUS_LOG(LOG_ERR, "abcd (not in a room)\n");
error_code = JANUS_AUDIOBRIDGE_ERROR_NOT_JOINED;
goto error;
}
/* Tell everybody */
janus_mutex_lock(&rooms_mutex);
janus_audiobridge_room *audiobridge = participant->room;
if(audiobridge != NULL) {
janus_refcount_increase(&audiobridge->ref);
janus_mutex_lock(&audiobridge->mutex);
event = json_object();
json_object_set_new(event, "audiobridge", json_string("event"));
json_object_set_new(event, "room",
string_ids ? json_string(audiobridge->room_id_str) : json_integer(audiobridge->room_id));
json_object_set_new(event, "abcd",root);
GHashTableIter iter;
gpointer value;
g_hash_table_iter_init(&iter, audiobridge->participants);
while(g_hash_table_iter_next(&iter, NULL, &value)) {
janus_audiobridge_participant *p = value;
if(p == participant || g_atomic_int_get(&p->paused_events)) {
continue; /* Skip the new participant itself */
}
JANUS_LOG(LOG_ERR, "111 -> event = %p Notifying participant %s (%s)\n", event,p->user_id_str, p->display ? p->display : "??");
int ret = gateway->push_event(p->session->handle, &janus_audiobridge_plugin, NULL, event, NULL);
JANUS_LOG(LOG_VERB, "111 >> %d (%s)\n", ret, janus_get_api_error(ret));
}
json_decref(event);
}
/* Also notify event handlers */
if(notify_events && gateway->events_is_enabled()) {
json_t *info = json_object();
json_object_set_new(info, "event", json_string("abcd1"));
json_object_set_new(info, "room",
string_ids ? json_string(audiobridge->room_id_str) : json_integer(audiobridge->room_id));
json_object_set_new(info, "id",
string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id));
json_object_set_new(info, "display", json_string(participant->display));
gateway->notify_event(&janus_audiobridge_plugin, session->handle, info);
json_decref(info);
}
/* Done */
event = json_object();
json_object_set_new(event, "audiobridge", json_string("abcd2"));
if(audiobridge != NULL) {
json_object_set_new(event, "room",
string_ids ? json_string(audiobridge->room_id_str) : json_integer(audiobridge->room_id));
janus_mutex_unlock(&audiobridge->mutex);
janus_refcount_decrease(&audiobridge->ref);
}
json_object_set_new(event, "id",
string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id));
janus_mutex_unlock(&rooms_mutex);
} else if(!strcasecmp(request_text, "leave")) {
The above code will cause occasional crashes after I send the abcd message, causing the janus service to crash.During this time my network will change and I will re-enter the room.How should I solve this problem?