[NUI] Add WebView DeviceListGet,SetDefaultAudio
authordongsug.song <dongsug.song@samsung.com>
Mon, 23 Dec 2024 05:51:15 +0000 (14:51 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 23 Dec 2024 07:51:11 +0000 (16:51 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs
src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/WebView/WebSettings.cs
src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/WebView/WebView.cs

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs
new file mode 100755 (executable)
index 0000000..c5dbf5e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright(c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using global::System.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class WebDeviceList
+        {
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_DeviceListGet")]
+            public static extern void Delete(HandleRef obj);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetTypeAndConnect")]
+            public static extern void GetTypeAndConnect(HandleRef obj, out int type, out bool connect, int idx);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetDeviceId")]
+            public static extern string GetDeviceId(HandleRef obj, int idx);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DeviceListGet_GetDeviceLabel")]
+            public static extern string GetDeviceLabel(HandleRef obj, int idx);
+        }
+    }
+}
index 6599ead16363971e88d5a66918e361dd827aa0a5..c3dc9b6f77cf83d7dffca1a04508c9b04bd8fc69 100755 (executable)
@@ -187,6 +187,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebSettings_IsExtraFeatureEnabled")]
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
             public static extern bool IsExtraFeatureEnabled(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebSettings_SetDefaultAudioInputDevice")]
+            public static extern void SetDefaultAudioInputDevice(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
         }
     }
 }
index 7c2a7a7d1600555495a913e8188c87428a85a753..afe48bf3695d5c1880ef297000aaa43bf6d2bde4 100755 (executable)
@@ -358,6 +358,12 @@ namespace Tizen.NUI
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_FeedMouseWheel")]
             public static extern void FeedMouseWheel(global::System.Runtime.InteropServices.HandleRef webViewRef, bool yDirection, int step, int x, int y);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterDeviceConnectionChangedCallback")]
+            public static extern void RegisterDeviceConnectionChangedCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterDeviceListGetCallback")]
+            public static extern void RegisterDeviceListGetCallback(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
         }
     }
 }
diff --git a/src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs b/src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs
new file mode 100755 (executable)
index 0000000..27977cc
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+using System.Collections.Generic;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// WebDeviceList.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WebDeviceList : Disposable
+    {
+        internal WebDeviceList(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        /// This will not be public opened.
+        /// <param name="swigCPtr"></param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            Interop.WebDeviceList.Delete(swigCPtr);
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal void GetTypeAndConnect(out int type, out bool connect, int idx)
+        {
+            Interop.WebDeviceList.GetTypeAndConnect(SwigCPtr, out type, out connect, idx);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal string GetDeviceId(int idx)
+        {
+            string ret = Interop.WebDeviceList.GetDeviceId(SwigCPtr, idx);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal string GetDeviceLabel(int idx)
+        {
+            string ret = Interop.WebDeviceList.GetDeviceLabel(SwigCPtr, idx);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public List<WebDeviceListItem> Get(int size)
+        {
+            List<WebDeviceListItem> ret = new List<WebDeviceListItem>();
+
+            for (int i = 0; i < size; i++)
+            {
+                WebDeviceListItem item = new WebDeviceListItem();
+                item.Id = GetDeviceId(i);
+                item.Label = GetDeviceLabel(i);
+
+                int type = -1;
+                bool connect = false;
+                GetTypeAndConnect(out type, out connect, i);
+                item.Type = (WebMediaDeviceType)type;
+                item.Connected = connect;
+                Tizen.Log.Fatal("NT", $"@@@ [{i}] id={item.Id}, label={item.Label}, type={item.Type}, conn={item.Connected}");
+                ret.Add(item);
+            }
+
+            Tizen.Log.Fatal("NT", $"list size={ret.Count}");
+            return ret;
+        }
+    }
+
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct WebDeviceListItem
+    {
+        public string Id;
+        public string Label;
+        public WebMediaDeviceType Type;
+        public bool Connected;
+    }
+
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum WebMediaDeviceType
+    {
+        Unknown = -1,
+        AudioInput = 0,
+        VideoInput,
+        AudioOutput,
+    }
+}
index b9eceb1128902ac76bf4725f9fbadd643291f7fb..526da505e9a604e00c942f7405d6ecddc8d52f46 100755 (executable)
@@ -571,5 +571,12 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetDefaultAudioInputDevice(string deviceId)
+        {
+            Interop.WebSettings.SetDefaultAudioInputDevice(SwigCPtr, deviceId);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
     }
 }
diff --git a/src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs b/src/Tizen.NUI/src/internal/WebView/WebViewDeviceConnectionChangedEventArgs.cs
new file mode 100755 (executable)
index 0000000..c20b8f8
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// Event arguments that DeviceConnectionChanged.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WebViewDeviceConnectionChangedEventArgs : EventArgs
+    {
+        internal WebViewDeviceConnectionChangedEventArgs(int deviceType)
+        {
+            DeviceType = deviceType;
+        }
+
+        /// <summary>
+        /// Gets Device Type.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int DeviceType { get; }
+    }
+}
index 96bb4601ddb03ab842d7c06ff77998de4c811556..7706b475cf87eb52776cccf608a33c55a049fc50 100755 (executable)
@@ -170,6 +170,9 @@ namespace Tizen.NUI.BaseComponents
         private WebContext webContext = null;
         private WebCookieManager webCookieManager = null;
 
+        private EventHandler<WebViewDeviceConnectionChangedEventArgs> deviceConnectionChangedEventHandler;
+        private webViewDeviceConnectionChangedCallback deviceConnectionChangedCallback;
+
         /// <summary>
         /// Default constructor to create a WebView.
         /// </summary>
@@ -439,6 +442,15 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate void WebViewUserMediaPermissionRequestCallback(IntPtr permission, string message);
        
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void webViewDeviceConnectionChangedCallback(int deviceType);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        private delegate void internalWebViewDeviceListGetCallback(IntPtr list, int size);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void WebViewDeviceListGetCallback(WebDeviceList list, int size);
+        private WebViewDeviceListGetCallback deviceListGetCallbackForUser;
 
         /// <summary>
         /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
@@ -1110,6 +1122,44 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WebViewDeviceConnectionChangedEventArgs> DeviceConnectionChanged
+        {
+            add
+            {
+                if (deviceConnectionChangedEventHandler == null)
+                {
+                    deviceConnectionChangedCallback = OnDeviceConnectionChanged;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(deviceConnectionChangedCallback);
+                    Interop.WebView.RegisterDeviceConnectionChangedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                deviceConnectionChangedEventHandler += value;
+            }
+            remove
+            {
+                deviceConnectionChangedEventHandler -= value;
+                if (deviceConnectionChangedEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterUserMediaPermissionRequestCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetDeviceListGetCallback(WebViewDeviceListGetCallback callback)
+        {
+            deviceListGetCallbackForUser = callback;
+
+            internalWebViewDeviceListGetCallback cb = deviceListGet;
+            IntPtr ip = Marshal.GetFunctionPointerForDelegate(cb);
+            Interop.WebView.RegisterDeviceListGetCallback(SwigCPtr, new HandleRef(this, ip));
+        }
+
+        private void deviceListGet(IntPtr list, int size)
+        {
+            deviceListGetCallbackForUser?.Invoke(new WebDeviceList(list, true), size);
+        }
 
         /// <summary>
         /// Options for searching texts.
@@ -3265,5 +3315,10 @@ namespace Tizen.NUI.BaseComponents
             userMediaPermissionRequestEventHandler?.Invoke(this, new WebViewUserMediaPermissionRequestEventArgs(new WebUserMediaPermissionRequest(permission, true), message));
         }
 
+        private void OnDeviceConnectionChanged(int deviceType)
+        {
+            deviceConnectionChangedEventHandler?.Invoke(this, new WebViewDeviceConnectionChangedEventArgs(deviceType));
+        }
+
     }
 }