diff --git a/CHANGES.md b/CHANGES.md index 4b26c49..68844f1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,8 @@ - @melpon - [ADD] ハードウェアエンコーダを利用するかどうかを設定する `UseHardwareEncoder` を追加 - @melpon +- [ADD] `SelectedSignalingURL` と `ConnectedSignalingURL` プロパティを追加 + - @melpon ## 2023.3.0 (2023-08-08) diff --git a/Sora/Sora.cs b/Sora/Sora.cs index 669197e..c5a68d0 100644 --- a/Sora/Sora.cs +++ b/Sora/Sora.cs @@ -768,6 +768,28 @@ public bool VideoEnabled set { sora_set_video_enabled(p, value ? 1 : 0); } } + public string SelectedSignalingURL + { + get + { + int size = sora_get_selected_signaling_url_size(p); + byte[] buf = new byte[size]; + sora_get_selected_signaling_url(p, buf, size); + return System.Text.Encoding.UTF8.GetString(buf); + } + } + + public string ConnectedSignalingURL + { + get + { + int size = sora_get_connected_signaling_url_size(p); + byte[] buf = new byte[size]; + sora_get_connected_signaling_url(p, buf, size); + return System.Text.Encoding.UTF8.GetString(buf); + } + } + #if UNITY_IOS && !UNITY_EDITOR private const string DllName = "__Internal"; #else @@ -834,4 +856,12 @@ public bool VideoEnabled private static extern int sora_get_video_enabled(IntPtr p); [DllImport(DllName)] private static extern void sora_set_video_enabled(IntPtr p, int enabled); + [DllImport(DllName)] + private static extern int sora_get_selected_signaling_url_size(IntPtr p); + [DllImport(DllName)] + private static extern int sora_get_connected_signaling_url_size(IntPtr p); + [DllImport(DllName)] + private static extern void sora_get_selected_signaling_url(IntPtr p, [Out] byte[] buf, int size); + [DllImport(DllName)] + private static extern void sora_get_connected_signaling_url(IntPtr p, [Out] byte[] buf, int size); } diff --git a/src/sora.cpp b/src/sora.cpp index a880340..c27352e 100644 --- a/src/sora.cpp +++ b/src/sora.cpp @@ -871,4 +871,18 @@ void Sora::SetVideoEnabled(bool enabled) { video_track_->set_enabled(enabled); } +std::string Sora::GetSelectedSignalingURL() const { + if (signaling_ == nullptr) { + return ""; + } + return signaling_->GetSelectedSignalingURL(); +} + +std::string Sora::GetConnectedSignalingURL() const { + if (signaling_ == nullptr) { + return ""; + } + return signaling_->GetConnectedSignalingURL(); +} + } // namespace sora_unity_sdk diff --git a/src/sora.h b/src/sora.h index c570ea6..d928ab6 100644 --- a/src/sora.h +++ b/src/sora.h @@ -72,6 +72,9 @@ class Sora : public std::enable_shared_from_this, bool GetVideoEnabled() const; void SetVideoEnabled(bool enabled); + std::string GetSelectedSignalingURL() const; + std::string GetConnectedSignalingURL() const; + private: void* GetAndroidApplicationContext(void* env); static sora_conf::ErrorCode ToErrorCode(sora::SoraSignalingErrorCode ec); diff --git a/src/unity.cpp b/src/unity.cpp index 3e6b72c..e332927 100644 --- a/src/unity.cpp +++ b/src/unity.cpp @@ -246,6 +246,27 @@ void sora_set_video_enabled(void* p, unity_bool_t enabled) { wsora->sora->SetVideoEnabled(enabled); } +// get_*_signaling_url_size() から get_*_signaling_url() までの間に値が変わった場合、 +// 落ちることは無いが、文字列が切り詰められる可能性があるので注意 +int sora_get_selected_signaling_url_size(void* p) { + auto wsora = (SoraWrapper*)p; + return wsora->sora->GetSelectedSignalingURL().size(); +} +int sora_get_connected_signaling_url_size(void* p) { + auto wsora = (SoraWrapper*)p; + return wsora->sora->GetConnectedSignalingURL().size(); +} +void sora_get_selected_signaling_url(void* p, void* buf, int size) { + auto wsora = (SoraWrapper*)p; + std::string str = wsora->sora->GetSelectedSignalingURL(); + std::memcpy(buf, str.c_str(), std::min(size, (int)str.size())); +} +void sora_get_connected_signaling_url(void* p, void* buf, int size) { + auto wsora = (SoraWrapper*)p; + std::string str = wsora->sora->GetConnectedSignalingURL(); + std::memcpy(buf, str.c_str(), std::min(size, (int)str.size())); +} + // iOS の場合は static link で名前が被る可能性があるので、別の名前にしておく void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API #if defined(SORA_UNITY_SDK_IOS) diff --git a/src/unity.h b/src/unity.h index 3007cf2..cc55467 100644 --- a/src/unity.h +++ b/src/unity.h @@ -106,6 +106,15 @@ UNITY_INTERFACE_EXPORT unity_bool_t sora_get_video_enabled(void* p); UNITY_INTERFACE_EXPORT void sora_set_video_enabled(void* p, unity_bool_t enabled); +UNITY_INTERFACE_EXPORT int sora_get_selected_signaling_url_size(void* p); +UNITY_INTERFACE_EXPORT int sora_get_connected_signaling_url_size(void* p); +UNITY_INTERFACE_EXPORT void sora_get_selected_signaling_url(void* p, + void* buf, + int size); +UNITY_INTERFACE_EXPORT void sora_get_connected_signaling_url(void* p, + void* buf, + int size); + #ifdef __cplusplus } #endif