From 717e2c1af4fcd14ce6615d1971f33d64e1c1d739 Mon Sep 17 00:00:00 2001 From: shijing xian Date: Mon, 30 Nov 2026 21:21:02 -0800 Subject: [PATCH 1/4] fix: resolve the SDK version on every install layout PackageVersionEmbedder looked the package up by the literal path "Packages/io.livekit.livekit-sdk" and returned quietly when that found nothing. Only a registry install resolves there, so git-URL, local-path and vendored installs never got a version asset written, and every session from them reported its SDK version as "unknown". Resolve from this assembly instead, which works regardless of where the package lands, and fall back to reading package.json next to the source for copies vendored into Assets/. Failure is now a warning that says what it costs, rather than a Debug.Log. PackageVersion also treats an empty asset as missing -- the other way a version reached the server blank -- and warns once at runtime so a build that shipped without one is visible. Co-Authored-By: Claude Opus 5 (1M context) --- Editor/PackageVersionEmbedder.cs | 96 ++++++++++++++++++++-- Runtime/Scripts/Internal/PackageVersion.cs | 35 +++++++- 2 files changed, 121 insertions(+), 10 deletions(-) diff --git a/Editor/PackageVersionEmbedder.cs b/Editor/PackageVersionEmbedder.cs index a18dd1ad..670d0560 100644 --- a/Editor/PackageVersionEmbedder.cs +++ b/Editor/PackageVersionEmbedder.cs @@ -1,7 +1,16 @@ #if UNITY_EDITOR +using System.IO; using UnityEditor; +using UnityEditor.PackageManager; using UnityEngine; +/// +/// Writes the SDK version into a Resources text asset so the runtime can report it +/// to the server during the join handshake; see LiveKit.Internal.PackageVersion. +/// +/// When this does not run, every session reports its SDK version as "unknown" and the +/// install cannot be told apart from any other in per-release telemetry. +/// [InitializeOnLoad] public static class PackageVersionEmbedder { @@ -9,23 +18,92 @@ public static class PackageVersionEmbedder const string ResourcePath = "Assets/Resources"; const string AssetName = "LiveKitSdkVersionInfo"; + [System.Serializable] + class Manifest + { + public string version; + } + [InitializeOnLoadMethod] static void Embed() { - // FindForAssetPath works with any asset inside the package - var info = UnityEditor.PackageManager.PackageInfo.FindForAssetPath($"Packages/{PackageName}"); - if (info == null) + var version = ResolveVersion(); + if (string.IsNullOrEmpty(version)) { - Debug.Log($"Package {PackageName} not found"); + Debug.LogWarning( + $"LiveKit: could not determine the version of {PackageName}. Sessions will " + + "report their SDK version as \"unknown\", and this install will not be " + + "distinguishable from any other in per-release telemetry."); return; } - if (!System.IO.Directory.Exists(ResourcePath)) - System.IO.Directory.CreateDirectory(ResourcePath); - string path = $"{ResourcePath}/{AssetName}.txt"; - System.IO.File.WriteAllText(path, info.version); + if (File.Exists(path) && File.ReadAllText(path).Trim() == version) + { + // Already current. Skipping the write keeps this off the asset-import + // path on every domain reload. + return; + } + + Directory.CreateDirectory(ResourcePath); + File.WriteAllText(path, version); AssetDatabase.ImportAsset(path); } + + /// + /// Resolves the version however the SDK was installed: through Package Manager, + /// from a git URL, or vendored straight into Assets/. + /// + static string ResolveVersion() + { + // Resolving from this assembly rather than a literal "Packages/" path + // is what makes git-URL and local-path installs work: those resolve to a + // hashed or absolute directory, so the old lookup always returned null. + var info = PackageInfo.FindForAssembly(typeof(PackageVersionEmbedder).Assembly); + if (info != null && !string.IsNullOrEmpty(info.version)) + { + return info.version; + } + + // Vendored into Assets/: there is no package context at all, so read the + // manifest shipped next to the source. + return VersionFromVendoredManifest(); + } + + static string VersionFromVendoredManifest() + { + foreach (var guid in AssetDatabase.FindAssets($"{nameof(PackageVersionEmbedder)} t:MonoScript")) + { + var scriptPath = AssetDatabase.GUIDToAssetPath(guid); + if (!scriptPath.EndsWith($"/{nameof(PackageVersionEmbedder)}.cs", System.StringComparison.Ordinal)) + { + continue; + } + + // scriptPath is /Editor/PackageVersionEmbedder.cs, so the + // manifest sits two levels up. + var sdkRoot = Path.GetDirectoryName(Path.GetDirectoryName(scriptPath)); + if (string.IsNullOrEmpty(sdkRoot)) + { + continue; + } + + var manifestPath = Path.Combine(sdkRoot, "package.json"); + if (!File.Exists(manifestPath)) + { + continue; + } + + // JsonUtility ignores the manifest fields it cannot map, so a type with + // just the one field is enough. + var manifest = JsonUtility.FromJson(File.ReadAllText(manifestPath)); + if (!string.IsNullOrEmpty(manifest?.version)) + { + return manifest.version; + } + } + + return null; + } } -#endif \ No newline at end of file +#endif diff --git a/Runtime/Scripts/Internal/PackageVersion.cs b/Runtime/Scripts/Internal/PackageVersion.cs index 1ab2a91f..1926e46c 100644 --- a/Runtime/Scripts/Internal/PackageVersion.cs +++ b/Runtime/Scripts/Internal/PackageVersion.cs @@ -4,10 +4,43 @@ namespace LiveKit.Internal { public static class PackageVersion { + static bool _warned; + + /// + /// The SDK version reported to the server during the join handshake. + /// + /// The value is embedded at edit time by PackageVersionEmbedder. "unknown" means + /// that did not run, and the install cannot be told apart from any other in + /// per-release telemetry. + /// public static string Get() { var asset = Resources.Load("LiveKitSdkVersionInfo"); - return asset != null ? asset.text.Trim() : "unknown"; + var version = asset != null ? asset.text.Trim() : null; + if (!string.IsNullOrEmpty(version)) + { + return version; + } + + // Covers both a missing asset and one that was written empty; each reaches + // the server as an unidentifiable version. + WarnOnce(); + return "unknown"; + } + + static void WarnOnce() + { + if (_warned) + { + return; + } + _warned = true; + + Debug.LogWarning( + "LiveKit: SDK version resource is missing or empty, so sessions will report " + + "their version as \"unknown\". This is embedded at edit time by " + + "PackageVersionEmbedder; check the Editor log for the warning it emits when " + + "it cannot resolve the package."); } } } From beb8f33bbc44665f6be310cc7789eaed74e45b74 Mon Sep 17 00:00:00 2001 From: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Date: Tue, 1 Dec 2026 10:44:32 +0100 Subject: [PATCH 2/4] Fix ambigous import --- Editor/PackageVersionEmbedder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/PackageVersionEmbedder.cs b/Editor/PackageVersionEmbedder.cs index 670d0560..cb425dc2 100644 --- a/Editor/PackageVersionEmbedder.cs +++ b/Editor/PackageVersionEmbedder.cs @@ -59,7 +59,7 @@ static string ResolveVersion() // Resolving from this assembly rather than a literal "Packages/" path // is what makes git-URL and local-path installs work: those resolve to a // hashed or absolute directory, so the old lookup always returned null. - var info = PackageInfo.FindForAssembly(typeof(PackageVersionEmbedder).Assembly); + var info = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(PackageVersionEmbedder).Assembly); if (info != null && !string.IsNullOrEmpty(info.version)) { return info.version; From 670540d8abe16dba1042756ac52c24f37ab6a682 Mon Sep 17 00:00:00 2001 From: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:15:03 +0100 Subject: [PATCH 3/4] fix: read the version file from disk in the Editor on first load PackageVersionEmbedder writes LiveKitSdkVersionInfo.txt during the same domain reload in which FfiClient initializes, but the AssetDatabase import it requests is deferred until the reload ends. Resources.Load therefore returned null and the first Editor session after the file was created reported its SDK version as "unknown". Fall back to the file on disk in the Editor; player builds still read the packed Resources asset. Co-Authored-By: Claude Opus 5.5 --- Runtime/Scripts/Internal/PackageVersion.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Runtime/Scripts/Internal/PackageVersion.cs b/Runtime/Scripts/Internal/PackageVersion.cs index 1926e46c..c1707bc8 100644 --- a/Runtime/Scripts/Internal/PackageVersion.cs +++ b/Runtime/Scripts/Internal/PackageVersion.cs @@ -17,6 +17,16 @@ public static string Get() { var asset = Resources.Load("LiveKitSdkVersionInfo"); var version = asset != null ? asset.text.Trim() : null; +#if UNITY_EDITOR + // PackageVersionEmbedder writes the file during the same domain reload that + // initializes FFI, but its import is deferred until the reload ends, so + // Resources.Load cannot see it yet. The file itself is already on disk. + const string editorPath = "Assets/Resources/LiveKitSdkVersionInfo.txt"; + if (string.IsNullOrEmpty(version) && System.IO.File.Exists(editorPath)) + { + version = System.IO.File.ReadAllText(editorPath).Trim(); + } +#endif if (!string.IsNullOrEmpty(version)) { return version; From f7f45b3d825d4b77c59477758a521c8c6e925698 Mon Sep 17 00:00:00 2001 From: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:26:14 +0100 Subject: [PATCH 4/4] docs: correct why PackageVersionEmbedder resolves from the assembly The old comment said git-URL and local-path installs failed the "Packages/" lookup. They do not: Package Manager exposes every source under that virtual path. Only a copy vendored into Assets/ was missed. Co-Authored-By: Claude Opus 5.5 --- Editor/PackageVersionEmbedder.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Editor/PackageVersionEmbedder.cs b/Editor/PackageVersionEmbedder.cs index cb425dc2..a6e3e369 100644 --- a/Editor/PackageVersionEmbedder.cs +++ b/Editor/PackageVersionEmbedder.cs @@ -56,9 +56,8 @@ static void Embed() /// static string ResolveVersion() { - // Resolving from this assembly rather than a literal "Packages/" path - // is what makes git-URL and local-path installs work: those resolve to a - // hashed or absolute directory, so the old lookup always returned null. + // Covers every Package Manager source (registry, git URL, local path, embedded). + // Returns null only when the source sits under Assets/. var info = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(PackageVersionEmbedder).Assembly); if (info != null && !string.IsNullOrEmpty(info.version)) {