From: Sangchul Lee Date: Tue, 26 Oct 2021 00:01:01 +0000 (+0900) Subject: webrtc_test: Support data channel in case of room join test X-Git-Tag: submit/tizen/20211028.055213~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20214aee40ba4af7719ce1a449fe0707d23d3c92;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_test: Support data channel in case of room join test It is now possible send/receive text message via data channel in case of room join test. 'zs', 'zb' menu can be used to send message to peers in the room. [Version] 0.2.141 [Issue Type] New feature Change-Id: Ia4847e8a91e55023c789bd113cbc6e4c6d8e1813 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index cee0194d..f8cd04d4 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.2.140 +Version: 0.2.141 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 44d9d006..fa6ce641 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -1082,51 +1082,38 @@ static int __copy_string_arr(gchar *dest_arr, char *string) 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); } @@ -3371,6 +3358,8 @@ static void __auto_configure_add_peer(gchar *peer_id, bool is_offer) _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: @@ -3434,6 +3423,7 @@ static void __auto_configure_release_peer(gchar *peer_id) return; _webrtc_stop(i); + _webrtc_destroy_data_channel(i); _webrtc_destroy(i); } @@ -4624,12 +4614,12 @@ static void interpret(char *cmd) 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; }