webrtc_test: Support data channel in case of room join test 34/265634/2
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 26 Oct 2021 00:01:01 +0000 (09:01 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 26 Oct 2021 03:57:38 +0000 (12:57 +0900)
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 <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
test/webrtc_test.c

index cee0194deb29bd7d53a04f3570686731019b5b5f..f8cd04d48f560a08893b6c7a401a2e45e286baba 100644 (file)
@@ -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
index 44d9d0060401af52fbf6aa39be9ef70aabdd7507..fa6ce6418283f292d090657aa2fcdaab9d92c627 100644 (file)
@@ -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;
        }