webrtc_test: Add support for connecting to a signaling server 00/243500/9
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 7 Sep 2020 14:38:09 +0000 (23:38 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 11 Sep 2020 06:21:57 +0000 (15:21 +0900)
A menu for this is added to the test application.
 : cs. Connect to the signaling server

We assume that the signaling server provides websocket interface.
The logics for handshaking from a peer to the server can be
different in each server. The upcoming patch will address this
handshaking protocol for demo server.

[Version] 0.1.15
[Issue Type] Test application

Change-Id: I95ed1ab2d0b6cf44d5d24cd39b8559d6be0024c4
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
test/CMakeLists.txt
test/webrtc_test.c

index ffb976febb7c110b4b679a0e3ce839b3f422e337..35303b4337456080d3c53caa3d37e2b226128aa0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.1.13
+Version:    0.1.15
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -16,6 +16,7 @@ BuildRequires:  pkgconfig(gstreamer-webrtc-1.0)
 BuildRequires:  pkgconfig(appcore-efl)
 BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(json-glib-1.0)
+BuildRequires:  pkgconfig(libsoup-2.4)
 
 %description
 A WebRTC library in Tizen Native API.
index 05a5d9c46d7a72eb4a2abf6c3968cb6295df3675..9d92b8d41b0a4bef43616906b4746fc5a8fbbcc8 100644 (file)
@@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(../include)
 link_directories(${CMAKE_SOURCE_DIR}/../)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0 appcore-efl elementary)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 appcore-efl elementary libsoup-2.4)
 FOREACH(flag ${${fw_test}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
index 241cc54e97a89846e195f06783d5c02e2ae28010..d8d89066db7ac5463d1b41999c700f2bd23358d8 100644 (file)
@@ -19,6 +19,7 @@
 #include <appcore-efl.h>
 #include <Elementary.h>
 #include <glib.h>
+#include <libsoup/soup.h>
 
 #ifdef PACKAGE
 #undef PACKAGE
@@ -468,6 +469,92 @@ static void _setting_uri(gchar *dest_arr, char *uri)
        }
 }
 
+static void __close_websocket(SoupWebsocketConnection *conn, const gchar *message)
+{
+       if (!conn)
+               return;
+
+       if (message)
+               g_printerr("%s\n", message);
+
+       if (soup_websocket_connection_get_state(conn) == SOUP_WEBSOCKET_STATE_OPEN)
+               soup_websocket_connection_close(conn, 1000, "");
+       else
+               g_object_unref(conn);
+}
+
+static void __websocket_closed_cb(SoupWebsocketConnection *conn, gpointer user_data)
+{
+       g_print("[%s] is closed\n", g_signaling_server);
+       __close_websocket(conn, "websocket connection closed");
+}
+
+static void __websocket_message_cb(SoupWebsocketConnection *conn, SoupWebsocketDataType type, GBytes *message, gpointer user_data)
+{
+       gchar *text;
+       gsize size;
+       const gchar *data;
+
+       if (type != SOUP_WEBSOCKET_DATA_TEXT) {
+               g_printerr("invalid data type(%d)\n", type);
+               return;
+       }
+       data = g_bytes_get_data(message, &size);
+       text = g_strndup(data, size);
+       g_print("\nreceived message, [%s]\n", text);
+
+       /* NOTE: Logics below can be different in each server */
+
+       g_free(text);
+}
+
+static void __websocket_connected_cb(SoupSession *session, GAsyncResult *res, SoupMessage *message)
+{
+       GError *error = NULL;
+       SoupWebsocketConnection *ws_conn;
+
+       g_print("\n[%s] is connected\n", g_signaling_server);
+       ws_conn = soup_session_websocket_connect_finish(session, res, &error);
+       if (error) {
+               __close_websocket(ws_conn, error->message);
+               g_print("failed to soup_session_websocket_connect_finish()\n");
+               g_error_free(error);
+               return;
+       }
+
+       g_signal_connect(ws_conn, "closed", G_CALLBACK(__websocket_closed_cb), NULL);
+       g_signal_connect(ws_conn, "message", G_CALLBACK(__websocket_message_cb), NULL);
+}
+
+static void _connect_signaling_server(void)
+{
+       SoupMessage *message;
+       SoupSession *session;
+       SoupURI *proxy_uri;
+       const char *https_aliases[] = {"wss", NULL};
+
+       if (strlen(g_proxy) == 0) {
+               session = soup_session_new_with_options(SOUP_SESSION_SSL_STRICT, TRUE,
+                       SOUP_SESSION_HTTPS_ALIASES, https_aliases, NULL);
+       } else {
+               g_print("use proxy [%s]\n", g_proxy);
+               proxy_uri = soup_uri_new(g_proxy);
+               session = soup_session_new_with_options(SOUP_SESSION_SSL_STRICT, TRUE,
+                       SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
+                       SOUP_SESSION_PROXY_URI, proxy_uri,
+                       SOUP_SESSION_SSL_CA_FILE, "/opt/var/lib/ca-certificates/ca-bundle.pem",
+                       SOUP_SESSION_HTTPS_ALIASES, https_aliases, NULL);
+                       soup_uri_free(proxy_uri);
+       }
+
+       message = soup_message_new(SOUP_METHOD_GET, g_signaling_server);
+
+       g_print("connecting to signaling server[%s]...\n", g_signaling_server);
+
+       soup_session_websocket_connect_async(session, message, NULL, NULL, NULL,
+               (GAsyncReadyCallback) __websocket_connected_cb, message);
+}
+
 void quit_program()
 {
        if (g_webrtc != NULL) {
@@ -508,16 +595,7 @@ void _interpret_main_menu(char *cmd)
                }
 
        } else if (len == 2) {
-               if (strncmp(cmd, "st", 2) == 0) {
-                       g_menu_state = CURRENT_STATUS_SET_STUN_SERVER;
-
-               } else if (strncmp(cmd, "ss", 2) == 0) {
-                       g_menu_state = CURRENT_STATUS_SETTING_SIGNALING_SERVER;
-
-               } else if (strncmp(cmd, "px", 2) == 0) {
-                       g_menu_state = CURRENT_STATUS_SETTING_PROXY;
-
-               } else if (strncmp(cmd, "se", 2) == 0) {
+               if (strncmp(cmd, "se", 2) == 0) {
                        _webrtc_set_error_cb();
 
                } else if (strncmp(cmd, "ue", 2) == 0) {
@@ -547,6 +625,18 @@ void _interpret_main_menu(char *cmd)
                } else if (strncmp(cmd, "sr", 2) == 0) {
                        g_menu_state = CURRENT_STATUS_SET_REMOTE_DESCRIPTION;
 
+               } else if (strncmp(cmd, "st", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_SET_STUN_SERVER;
+
+               } else if (strncmp(cmd, "ss", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_SETTING_SIGNALING_SERVER;
+
+               } else if (strncmp(cmd, "px", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_SETTING_PROXY;
+
+               } else if (strncmp(cmd, "cs", 2) == 0) {
+                       _connect_signaling_server();
+
                } else {
                        g_print("unknown menu \n");
                }
@@ -583,6 +673,7 @@ void display_sub_basic()
        g_print("----------------------------------- App. Setting ----------------------------------------\n");
        g_print("ss. Set signaling server URL\n");
        g_print("px. Set proxy URL\n");
+       g_print("cs. Connect to the signaling server\n");
        g_print("-----------------------------------------------------------------------------------------\n");
        g_print("=========================================================================================\n");
 }