Skip to content

Commit 0183a3a

Browse files
authored
Embedding sdk version in txt file and sending at runtime (#196)
1 parent d0aacc3 commit 0183a3a

8 files changed

Lines changed: 86 additions & 1 deletion

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/PackageVersionEmbedder.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#if UNITY_EDITOR
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
[InitializeOnLoad]
6+
public static class PackageVersionEmbedder
7+
{
8+
const string PackageName = "io.livekit.livekit-sdk";
9+
const string ResourcePath = "Assets/Resources";
10+
const string AssetName = "LiveKitSdkVersionInfo";
11+
12+
[InitializeOnLoadMethod]
13+
static void Embed()
14+
{
15+
// FindForAssetPath works with any asset inside the package
16+
var info = UnityEditor.PackageManager.PackageInfo.FindForAssetPath($"Packages/{PackageName}");
17+
if (info == null)
18+
{
19+
Debug.Log($"Package {PackageName} not found");
20+
return;
21+
}
22+
23+
if (!System.IO.Directory.Exists(ResourcePath))
24+
System.IO.Directory.CreateDirectory(ResourcePath);
25+
26+
string path = $"{ResourcePath}/{AssetName}.txt";
27+
System.IO.File.WriteAllText(path, info.version);
28+
AssetDatabase.ImportAsset(path);
29+
}
30+
}
31+
#endif

Editor/PackageVersionEmbedder.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/livekit.unity.Editor.asmdef

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Editor"
3+
}

Editor/livekit.unity.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Internal/FFIClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ private static void InitializeSdk()
145145
const bool captureLogs = false;
146146
#endif
147147

148-
NativeMethods.LiveKitInitialize(FFICallback, captureLogs, "unity", ""); // TODO: Get SDK version
148+
var sdkVersion = PackageVersion.Get();
149+
NativeMethods.LiveKitInitialize(FFICallback, captureLogs, "unity", sdkVersion); // TODO: Get SDK version
149150

150151
Utils.Debug("FFIServer - Initialized");
151152
initialized = true;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using UnityEngine;
2+
3+
namespace LiveKit
4+
{
5+
public static class PackageVersion
6+
{
7+
public static string Get()
8+
{
9+
var asset = Resources.Load<TextAsset>("LiveKitSdkVersionInfo");
10+
return asset != null ? asset.text.Trim() : "unknown";
11+
}
12+
}
13+
}

Runtime/Scripts/Internal/PackageVersion.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)