Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 4.34 KB

README.md

File metadata and controls

76 lines (64 loc) · 4.34 KB

Ably Unity SDK

  • Supports both Mono and IL2CPP builds.
  • Supports Windows, MacOS, Linux, Android and iOS.

System Requirements

  • Unity 2019.x.x or newer
  • The following Unity Player settings must be applied:
    • Scripting Runtime Version should be '.NET 4.x Equivalent'
    • API Compatibility Level should be '.NET Standard 2.0'

Downloading Unity Package

  • Please download the latest Unity package from the GitHub releases page. All releases from 1.2.4 have .unitypackage included.

Importing Unity Package

  • You can import the package by going to Assets -> Import Package -> Custom Package in the Unity UI. For more detailed information on importing packages, visit https://docs.unity3d.com/Manual/AssetPackagesImport.html.
  • Make sure to disable assembly validation if your project fails to build due to conflicts with Unity's internal newtonsoft json library.
  • Please set ClientOptions.AutomaticNetworkStateMonitoring to false when instantiating the Ably Client Library, since this feature is not supported and will throw a runtime exception.
  • Custom NewtonSoft JSON DLLs under Plugins can be removed, in the case of conflict with other NewtonSoft DLLs in the project, or if the use of inbuilt Newtonsoft is preferred.
  • Configure SynchronizationContext to execute callbacks on Main/UI thread.
  • Sample code :
using System;
using System.Threading;
using IO.Ably;
using IO.Ably.Realtime;
using UnityEngine;
using UnityEngine.UI;

namespace Example.ChatApp
{
    public class AblyConsole : MonoBehaviour
    {
        private AblyRealtime _ably;
        private ClientOptions _clientOptions;

        // It's recommended to use other forms of authentication. E.g. JWT, Token Auth 
        // This is to avoid exposing root api key to a client
        private static string _apiKey = "ROOT_API_KEY_COPIED_FROM_ABLY_WEB_DASHBOARD";

        void Start()
        {
            InitializeAbly();
        }

        private void InitializeAbly()
        {
            _clientOptions = new ClientOptions
            {
                Key = _apiKey,
                // this will disable the library trying to subscribe to network state notifications
                AutomaticNetworkStateMonitoring = false,
                AutoConnect = false,
                // this will make sure to post callbacks on UnitySynchronization Context Main Thread
                CustomContext = SynchronizationContext.Current
            };

            _ably = new AblyRealtime(_clientOptions);
            _ably.Connection.On(args =>
            {
                Debug.Log($"Connection State is <b>{args.Current}</b>");
            });
        }
    }

Unsupported Platforms

Contributing