Skip to content

Latest commit

 

History

History

README.md

Ably Unity SDK

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

System Requirements

  • Unity 2019.x.x or newer
  • 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

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,
                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