Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI] Add WebView DeviceListGet,SetDefaultAudio #6527

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.WebDeviceList.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 3 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.WebSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ internal static partial class WebSettings
[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);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ internal static partial class WebView

[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);
}
}
}
107 changes: 107 additions & 0 deletions src/Tizen.NUI/src/internal/WebView/WebDeviceList.cs
Original file line number Diff line number Diff line change
@@ -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,
}
}
7 changes: 7 additions & 0 deletions src/Tizen.NUI/src/internal/WebView/WebSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,5 +571,12 @@ public bool IsExtraFeatureEnabled(string str)
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
56 changes: 56 additions & 0 deletions src/Tizen.NUI/src/public/WebView/WebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ static WebView()
private WebContext webContext = null;
private WebCookieManager webCookieManager = null;

private EventHandler<WebViewDeviceConnectionChangedEventArgs> deviceConnectionChangedEventHandler;
private webViewDeviceConnectionChangedCallback deviceConnectionChangedCallback;

/// <summary>
/// Default constructor to create a WebView.
/// </summary>
Expand Down Expand Up @@ -439,6 +442,16 @@ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef
[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)]
[EditorBrowsable(EditorBrowsableState.Never)]
public delegate void WebViewDeviceListGetCallback(WebDeviceList list, int size);
dongsug-song marked this conversation as resolved.
Show resolved Hide resolved
private WebViewDeviceListGetCallback deviceListGetCallbackForUser;

/// <summary>
/// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
Expand Down Expand Up @@ -1110,6 +1123,44 @@ public event EventHandler<WebViewUserMediaPermissionRequestEventArgs> UserMediaP
}
}

[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.
Expand Down Expand Up @@ -3265,5 +3316,10 @@ private void OnUserMediaPermissionRequset(IntPtr permission, string message)
userMediaPermissionRequestEventHandler?.Invoke(this, new WebViewUserMediaPermissionRequestEventArgs(new WebUserMediaPermissionRequest(permission, true), message));
}

private void OnDeviceConnectionChanged(int deviceType)
{
deviceConnectionChangedEventHandler?.Invoke(this, new WebViewDeviceConnectionChangedEventArgs(deviceType));
}

}
}
Loading