return 0;
}
-static void _webrtc_data_channel_send_string(int index, const char *string)
+static void _webrtc_data_channel_send_string(const char *string, bool send_as_bytes)
{
- int ret = WEBRTC_ERROR_NONE;
- int i;
- gchar *string_with_peer_id;
- string_with_peer_id = g_strdup_printf("[%d] %s", g_signaling_server.local_peer_id, string);
-
- for (i = 0; i < MAX_CHANNEL_LEN; i++) {
- if (g_conns[index].channels[i] == NULL)
- continue;
- g_print("data_channel[%p], index[%d]: ", g_conns[index].channels[i], i);
- ret = webrtc_data_channel_send_string(g_conns[index].channels[i], string_with_peer_id);
- if (ret != WEBRTC_ERROR_NONE)
- g_print("failed to webrtc_data_channel_send_string(), string[%s]\n", string_with_peer_id);
- else
- g_print("webrtc_data_channel_send_string() success, string[%s]\n", string_with_peer_id);
- }
-
- if (g_conns[index].render.loopback_track_id > 0)
- __render_text_message(&g_text_eo_mine, 0, string_with_peer_id);
-
- g_free(string_with_peer_id);
-}
-
-static void _webrtc_data_channel_send_string_as_bytes(int index, const char *string)
-{
- int ret = WEBRTC_ERROR_NONE;
- int i;
+ int ret;
+ int i, j;
gchar *string_with_peer_id;
string_with_peer_id = g_strdup_printf("[%d] %s", g_signaling_server.local_peer_id, string);
- for (i = 0; i < MAX_CHANNEL_LEN; i++) {
- if (g_conns[index].channels[i] == NULL)
+ for (i = 0; i < MAX_CONNECTION_LEN; i++) {
+ if (!g_conns[i].webrtc)
continue;
- g_print("data_channel[%p], index[%d]: ", g_conns[index].channels[i], i);
- ret = webrtc_data_channel_send_bytes(g_conns[index].channels[i], string_with_peer_id, strlen(string_with_peer_id));
- if (ret != WEBRTC_ERROR_NONE)
- g_print("failed to webrtc_data_channel_send_bytes(), string[%s]\n", string_with_peer_id);
- else
- g_print("webrtc_data_channel_send_bytes() success, string[%s]\n", string_with_peer_id);
+ for (j = 0; j < MAX_CHANNEL_LEN; j++) {
+ if (!g_conns[i].channels[j])
+ continue;
+ g_print("[%d] data_channel[%p], index[%d]: ", i, g_conns[i].channels[j], j);
+ if (send_as_bytes) {
+ ret = webrtc_data_channel_send_bytes(g_conns[i].channels[j], string_with_peer_id, strlen(string_with_peer_id));
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_data_channel_send_bytes(), string[%s]\n", string_with_peer_id);
+ else
+ g_print("webrtc_data_channel_send_bytes() success, string[%s]\n", string_with_peer_id);
+ } else {
+ ret = webrtc_data_channel_send_string(g_conns[i].channels[j], string_with_peer_id);
+ if (ret != WEBRTC_ERROR_NONE)
+ g_print("failed to webrtc_data_channel_send_string(), string[%s]\n", string_with_peer_id);
+ else
+ g_print("webrtc_data_channel_send_string() success, string[%s]\n", string_with_peer_id);
+ }
+ }
+ if (g_conns[i].render.loopback_track_id > 0)
+ __render_text_message(&g_text_eo_mine, 0, string_with_peer_id);
}
- if (g_conns[index].render.loopback_track_id > 0)
- __render_text_message(&g_text_eo_mine, 0, string_with_peer_id);
-
g_free(string_with_peer_id);
}
_webrtc_set_ice_candidate_cb(i);
_webrtc_set_negotiation_needed_cb(i);
_webrtc_set_all_negotiation_state_change_cbs(i);
+ _webrtc_set_data_channel_cb(i);
+ _webrtc_create_data_channel(i);
switch (g_conns[i].room_source_type) {
case 1:
return;
_webrtc_stop(i);
+ _webrtc_destroy_data_channel(i);
_webrtc_destroy(i);
}
break;
}
case CURRENT_STATUS_DATA_CHANNEL_SEND_STRING: {
- _webrtc_data_channel_send_string(0, cmd);
+ _webrtc_data_channel_send_string(cmd, false);
reset_menu_state();
break;
}
case CURRENT_STATUS_DATA_CHANNEL_SEND_STRING_AS_BYTES: {
- _webrtc_data_channel_send_string_as_bytes(0, cmd);
+ _webrtc_data_channel_send_string(cmd, true);
reset_menu_state();
break;
}