Skip to content

Commit

Permalink
SelectedSignalingURLConnectedSignalingURL プロパティを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Sep 5, 2023
1 parent 5a6634c commit 4251a91
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- @melpon
- [ADD] ハードウェアエンコーダを利用するかどうかを設定する `UseHardwareEncoder` を追加
- @melpon
- [ADD] `SelectedSignalingURL``ConnectedSignalingURL` プロパティを追加
- @melpon

## 2023.3.0 (2023-08-08)

Expand Down
30 changes: 30 additions & 0 deletions Sora/Sora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
14 changes: 14 additions & 0 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/sora.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Sora : public std::enable_shared_from_this<Sora>,
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);
Expand Down
21 changes: 21 additions & 0 deletions src/unity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4251a91

Please sign in to comment.