Skip to content
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ channel.Subscribe(message =>
await channel.PublishAsync("test-event", "Hello World!");
```

Enable logging using a new class that implements `ILoggerSink` interface.

```csharp
class CustomLogHandler : ILoggerSink
{
public void LogEvent(LogLevel level, string message)
{
Console.WriteLine($"Handler LogLevel : {level}, Data :{message}");
}
}
```

Update clientOptions for `LogLevel` and `LogHandler`.

```csharp
clientOpts.LogLevel = LogLevel.Debug;
clientOpts.LogHandler = new CustomLogHandler();
```

### Unity usage

- Download latest `ably.io.*.unitypackage` from [releases section](https://github.com/ably/ably-dotnet/releases) and include it in the unity project.
- For more information, check [Unity README](./unity/README.md)

## Releases

The [CHANGELOG.md](./CHANGELOG.md) contains details of the latest releases for this SDK. You can also view all Ably releases on [changelog.ably.com](https://changelog.ably.com).
Expand Down
61 changes: 61 additions & 0 deletions cake-build/tasks/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,62 @@ Task("_Xamarin_Build")
MSBuild(paths.XamarinSolution, settings);
});

Task("_Build_Ably_Unity_Dll")
.Description("Create merged Unity DLL with all dependencies")
.Does(() =>
{
Information("Merging Unity dependencies into IO.Ably.dll...");

var netStandard20BinPath = paths.Src
.Combine("IO.Ably.NETStandard20")
.Combine("bin/Release/netstandard2.0");

if (!DirectoryExists(netStandard20BinPath))
{
throw new Exception($"NETStandard2.0 bin directory not found: {netStandard20BinPath}. Please build the project first.");
}

var primaryDll = netStandard20BinPath.CombineWithFilePath("IO.Ably.dll");

if (!FileExists(primaryDll))
{
throw new Exception($"Primary DLL not found: {primaryDll}. Please build the IO.Ably.NETStandard20 project first.");
}

var newtonsoftDll = paths.Root
.Combine("lib/unity/AOT")
.CombineWithFilePath("Newtonsoft.Json.dll");

if (!FileExists(newtonsoftDll))
{
throw new Exception($"Newtonsoft.Json.dll not found at: {newtonsoftDll}");
}

var dllsToMerge = new[]
{
netStandard20BinPath.CombineWithFilePath("IO.Ably.DeltaCodec.dll"),
netStandard20BinPath.CombineWithFilePath("System.Runtime.CompilerServices.Unsafe.dll"),
netStandard20BinPath.CombineWithFilePath("System.Threading.Channels.dll"),
netStandard20BinPath.CombineWithFilePath("System.Threading.Tasks.Extensions.dll"),
newtonsoftDll
};

var unityOutputPath = paths.Root.Combine("unity/Assets/Ably/Plugins");
var outputDll = unityOutputPath.CombineWithFilePath("IO.Ably.dll");

// Delete existing output DLL if it exists
if (FileExists(outputDll))
{
DeleteFile(outputDll);
Information($"Deleted existing DLL: {outputDll}");
}

// Merge all dependencies into primary DLL in one go
ilRepackHelper.MergeDLLs(primaryDll, dllsToMerge, outputDll);

Information($"✓ Unity DLL created at: {outputDll}");
});

///////////////////////////////////////////////////////////////////////////////
// PUBLIC TARGETS
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -129,3 +185,8 @@ Task("Build.Xamarin")
.IsDependentOn("_Clean")
.IsDependentOn("_Restore_Xamarin")
.IsDependentOn("_Xamarin_Build");

// Public task: Update Ably DLLs inside unity project
Task("Update.AblyUnity")
.Description("Update Ably DLLs inside unity project")
.IsDependentOn("_Build_Ably_Unity_Dll");
Binary file removed lib/UnityEngine.dll
Binary file not shown.
Binary file added lib/unity/AOT/Newtonsoft.Json.dll
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/IO.Ably.NETStandard20/IO.Ably.NETStandard20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
<ProjectReference Include="..\..\lib\delta-codec\IO.Ably.DeltaCodec\IO.Ably.DeltaCodec.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="UnityEngine">
<HintPath>..\..\lib\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<!-- Copy all NuGet dependencies to output directory when building for unity package -->
<!-- This ensures ILRepack can find all referenced assemblies via the /lib argument -->
<PropertyGroup Condition=" $(DefineConstants.Contains('UNITY_PACKAGE')) ">
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

</Project>
108 changes: 28 additions & 80 deletions src/IO.Ably.Shared/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Runtime.InteropServices;

#if NETSTANDARD2_0_OR_GREATER && UNITY_PACKAGE
using UnityEngine; // lib/UnityEngine.dll - 2019.4.40 LTS compile time, at runtime unity player version will be used.
using IO.Ably.Unity;
#endif

namespace IO.Ably
Expand Down Expand Up @@ -36,14 +36,32 @@ public static class OS
internal const string AblyAgentHeader = "Ably-Agent";
private static readonly string AblySdkIdentifier = $"ably-dotnet/{Defaults.LibraryVersion}"; // RSC7d1

private static readonly Lazy<string> _dotnetRuntimeIdentifier =
new Lazy<string>(() => GetDotnetRuntimeIdentifier());

private static readonly Lazy<string> _osIdentifier =
new Lazy<string>(() => GetOsIdentifier());

/// <summary>
/// Gets the cached .NET runtime identifier string.
/// The value is computed once on first access and cached for subsequent calls.
/// </summary>
internal static string DotnetRuntimeIdentifier => _dotnetRuntimeIdentifier.Value;

/// <summary>
/// Gets the cached OS identifier string.
/// The value is computed once on first access and cached for subsequent calls.
/// </summary>
internal static string OsIdentifier => _osIdentifier.Value;

/// <summary>
/// This returns dotnet platform as per ably-lib mappings defined in agents.json.
/// https://github.com/ably/ably-common/blob/main/protocol/agents.json.
/// This is required since we are migrating from 'X-Ably-Lib' header (RSC7b) to agent headers (RSC7d).
/// Please note that uwp platform is Deprecated and removed as a part of https://github.com/ably/ably-dotnet/pull/1101.
/// </summary>
/// <returns> Clean Platform Identifier. </returns>
internal static string DotnetRuntimeIdentifier()
private static string GetDotnetRuntimeIdentifier()
{
string DotnetRuntimeName()
{
Expand Down Expand Up @@ -86,77 +104,7 @@ string DotnetRuntimeVersion()
dotnetRuntimeName : $"{dotnetRuntimeName}/{dotnetRuntimeVersion}";
}

#if NETSTANDARD2_0_OR_GREATER && UNITY_PACKAGE
internal static string UnityPlayerIdentifier()
{
return Application.unityVersion.IsEmpty() ?
"unity" : $"unity/{Application.unityVersion}";
}

public static class UnityOS
{
public const string Windows = "unity-windows";
public const string MacOS = "unity-macOS";
public const string Linux = "unity-linux";
public const string Android = "unity-android";
public const string IOS = "unity-iOS";
public const string TvOS = "unity-tvOS";
public const string WebGL = "unity-webGL";
public const string Switch = "unity-nintendo-switch";
public const string PS4 = "unity-PS4";
public const string PS5 = "unity-PS5";
public const string Xbox = "unity-xbox";
}

internal static string UnityOsIdentifier()
{
try
{
// lib/UnityEngine.dll - 2019.4.40 LTS compile time.
// Added cases for consistent platforms for future versions of unity.
// At runtime unity player version >= 2019.x.x will be used.
switch (Application.platform)
{
case RuntimePlatform.OSXEditor:
return UnityOS.MacOS;
case RuntimePlatform.OSXPlayer:
return UnityOS.MacOS;
case RuntimePlatform.WindowsPlayer:
return UnityOS.Windows;
case RuntimePlatform.WindowsEditor:
return UnityOS.Windows;
case RuntimePlatform.IPhonePlayer:
return UnityOS.IOS;
case RuntimePlatform.Android:
return UnityOS.Android;
case RuntimePlatform.LinuxPlayer:
return UnityOS.Linux;
case RuntimePlatform.LinuxEditor:
return UnityOS.Linux;
case RuntimePlatform.WebGLPlayer:
return UnityOS.WebGL;
case RuntimePlatform.PS4:
return UnityOS.PS4;
case RuntimePlatform.XboxOne:
return UnityOS.Xbox;
case RuntimePlatform.tvOS:
return UnityOS.TvOS;
case RuntimePlatform.Switch:
return UnityOS.Switch;
case RuntimePlatform.PS5:
return UnityOS.PS5;
}
}
catch
{
// ignored, If enum case is not found for future versions of unity
}

return string.Empty;
}
#endif

internal static string OsIdentifier()
private static string GetOsIdentifier()
{
switch (IoC.PlatformId)
{
Expand All @@ -166,6 +114,10 @@ internal static string OsIdentifier()
return OS.IOS;
}

#if NETSTANDARD2_0_OR_GREATER && UNITY_PACKAGE
return UnityHelper.OsIdentifier;
#endif
Comment thread
sacOO7 marked this conversation as resolved.

// Preprocessors defined as per https://learn.microsoft.com/en-us/dotnet/standard/frameworks#preprocessor-symbols
// Get operating system as per https://stackoverflow.com/a/66618677 for .NET5 and greater
#if NET5_0_OR_GREATER
Expand Down Expand Up @@ -210,10 +162,6 @@ internal static string OsIdentifier()
}
#endif

#if NETSTANDARD2_0_OR_GREATER && UNITY_PACKAGE
return UnityOsIdentifier();
#endif

#pragma warning disable CS0162 // Disable code unreachable warning when above conditional statement is true
try
{
Expand Down Expand Up @@ -274,13 +222,13 @@ void AddAgentIdentifier(ICollection<string> currentAgentComponents, string produ

var agentComponents = new List<string>();
AddAgentIdentifier(agentComponents, AblySdkIdentifier);
AddAgentIdentifier(agentComponents, DotnetRuntimeIdentifier());
AddAgentIdentifier(agentComponents, DotnetRuntimeIdentifier);

#if NETSTANDARD2_0_OR_GREATER && UNITY_PACKAGE
AddAgentIdentifier(agentComponents, UnityPlayerIdentifier());
AddAgentIdentifier(agentComponents, UnityHelper.UnityIdentifier);
#endif

AddAgentIdentifier(agentComponents, OsIdentifier());
AddAgentIdentifier(agentComponents, OsIdentifier);

if (additionalAgents == null)
{
Expand Down
2 changes: 2 additions & 0 deletions src/IO.Ably.Shared/IO.Ably.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Types\PresenceMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Types\ProtocolMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Types\SemanticVersion.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Unity\UnityAdapter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Unity\UnityHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\ActionOnDispose.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\ActionUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\ConnectionChangeAwaiter.cs" />
Expand Down
Loading
Loading