All Projects → ably → ably-dotnet

ably / ably-dotnet

Licence: Apache-2.0 license
.NET, Xamarin and Mono client library SDK for Ably realtime messaging service

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to ably-dotnet

PCLExt.FileStorage
Portable Storage APIs
Stars: ✭ 35 (+9.38%)
Mutual labels:  xamarin, uwp, mono
streamr-client-javascript
JS library for interacting with Streamr APIs: publishing and subscribing to data, creating streams, etc.
Stars: ✭ 35 (+9.38%)
Mutual labels:  realtime, realtime-messaging, client-library
Mvvmcross
The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
Stars: ✭ 3,594 (+11131.25%)
Mutual labels:  xamarin, uwp, mono
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+18740.63%)
Mutual labels:  xamarin, uwp, mono
uno.toolkit.ui
A set of custom controls for the WinUI and the Uno Platform not offered out of the box by WinUI, such as Card, TabBar, NavigationBar, etc.
Stars: ✭ 45 (+40.63%)
Mutual labels:  xamarin, uwp, mono
Ably Js
Javascript, Node, Typescript client library SDK for Ably realtime messaging service
Stars: ✭ 99 (+209.38%)
Mutual labels:  realtime, realtime-messaging, client-library
Uno.playground
Source code for the Uno Gallery apps and Uno Playground (made in Wasm)
Stars: ✭ 184 (+475%)
Mutual labels:  xamarin, uwp, mono
Ably Go
Go client library SDK for Ably realtime messaging service
Stars: ✭ 29 (-9.37%)
Mutual labels:  realtime, realtime-messaging, client-library
Xamarin Forms Gtk Movies Sample
The Movie DB Xamarin.Forms Sample
Stars: ✭ 83 (+159.38%)
Mutual labels:  xamarin, uwp, mono
Uno.ch9
Ch9 - Uno Reference Implementation project
Stars: ✭ 45 (+40.63%)
Mutual labels:  xamarin, uwp, mono
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+2603.13%)
Mutual labels:  xamarin, uwp, mono
ably-cocoa
iOS, tvOS and macOS Objective-C and Swift client library SDK for Ably realtime messaging service
Stars: ✭ 33 (+3.13%)
Mutual labels:  realtime, realtime-messaging, client-library
Megaapiclient
MegaApiClient is a C# .Net library to access http://mega.co.nz / http://mega.nz cloud storage and file hosting service.
Stars: ✭ 151 (+371.88%)
Mutual labels:  xamarin, uwp, mono
Portable-WebDAV-Library
Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETS…
Stars: ✭ 45 (+40.63%)
Mutual labels:  xamarin, uwp, mono
Standard.licensing
Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and Xamarin products
Stars: ✭ 239 (+646.88%)
Mutual labels:  xamarin, mono
Xamarin Demos
This repository contains the Syncfusion Xamarin UI control’s samples and the guide to use them.
Stars: ✭ 218 (+581.25%)
Mutual labels:  xamarin, uwp
Sharpcaster
Chromecast C# SDK for Windows, Windows Phone, .NET 4.5.1, Xamarin.iOS and Xamarin.Android platforms.
Stars: ✭ 245 (+665.63%)
Mutual labels:  xamarin, uwp
Malclient
Not so small client app for Myanimelist.net - Windows 10 UWP & Android
Stars: ✭ 253 (+690.63%)
Mutual labels:  xamarin, uwp
Caliburn.micro
A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
Stars: ✭ 2,404 (+7412.5%)
Mutual labels:  xamarin, uwp
Connectivityplugin
Connectivity Plugin for Xamarin and Windows
Stars: ✭ 253 (+690.63%)
Mutual labels:  xamarin, uwp

ably-dotnet

NuGet version Windows - build and test MacOS - build and test Linux - build and test

Ably is the platform that powers synchronized digital experiences in realtime. Whether attending an event in a virtual venue, receiving realtime financial information, or monitoring live car performance data – consumers simply expect realtime digital experiences as standard. Ably provides a suite of APIs to build, extend, and deliver powerful digital experiences in realtime for more than 250 million devices across 80 countries each month. Organizations like Bloomberg, HubSpot, Verizon, and Hopin depend on Ably’s platform to offload the growing complexity of business-critical realtime data synchronization at global scale. For more information, see the Ably documentation.

This is a .NET client library for Ably. The library currently targets the Ably 1.1-beta client library specification. You can jump to the 'Known Limitations' section to see the features this client library does not yet support or or view our client library SDKs feature support matrix to see the list of all the available features.

Supported platforms

Partially supported platforms

Unity

Unity support is currently in beta.

Shortcomings & Considerations:

  • This library is currently only tested manually on Unity for Windows, we are however actively working towards automated testing by integrating Unity Cloud Build into our .NET CI pipeline.
  • Installation requires developers to import a custom Unity package that includes all of Ably's dependencies.

Unity Requirements:

  • Unity 2018.2.0 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'

Please download the latest Unity package from the GitHub releases page. All releases from 1.1.16 will include a Unity package as well.

The library creates a number of threads and all callbacks are executed on non UI threads. This makes it difficult to update UI elements inside any callback executed by Ably. To make it easier we support capturing the SynchronizationContext and synchronizing callbacks to the UI thread.

Push notification

The Ably.net library fully supports Ably's push notifications. The feature set consists of two distinct areas: Push Admin, Device Push Notifications.

The Push Notifications Readme describes:

  • How to setup Push notifications for Xamarin mobile apps
  • How to use the Push Admin api to send push notifications directly to a devices or a client
  • How to subscribe to channels that support push notification
  • How to send Ably messages that include a notification

Known Limitations

  • Browser push notifications in Blazor are not supported.

Documentation

Visit https://ably.com/docs for a complete API reference and more examples.

Installation

The client library is available as a nuget package.

You can install it from the Package Manager Console using this command

PM> Install-Package ably.io

or using the .NET CLI in your project directory using

dotnet add package ably.io

Using the Realtime API

Introduction

All examples assume a client has been created as follows:

// Using basic auth with API key
var realtime = new AblyRealtime("<api key>");
// Using token auth with token string
var realtime = new AblyRealtime(new ClientOptions { Token = "token" });

If you do not have an API key, sign up for a free API key now

Connection

Connecting and observing connection state changes. By default the library automatically initializes a connection.

realtime.Connection.On(ConnectionEvent.Connected, args =>
{
    // Do stuff  
});

To disable the default automatic connect behavior of the library, set AutoConnect = false when initializing the client.

var realtime = new AblyRealtime(new ClientOptions("<api key>") { AutoConnect = false });
// Some code
realtime.Connect();

Subscribing to connection state changes and observing errors:

realtime.Connection.On(args =>
{
    var currentState = args.Current; // Current state the connection transitioned to
    var previousState = args.Previous; // Previous state
    var error = args.Reason; // If the connection error-ed the Reason object will be populated.
});

Subscribing to a channel

Create a channel

IRealtimeChannel channel = realtime.Channels.Get("test");

Subscribing to all events:

channel.Subscribe(message =>
{
    var name = message.Name;
    var data = message.Data;
});

Subscribing to specific events:

channel.Subscribe("myEvent", message =>
{
    var name = message.Name;
    var data = message.Data;
});

Observing channel state changes and errors:

channel.On(args =>
{
    var state = args.NewState; // Current channel State
    var error = args.Error; // If the channel error-ed it will be reflected here
});

or

channel.On(ChannelState.Attached, args =>
{
    // Do stuff when channel is attached
});

Subscribing to a channel in delta mode

Subscribing to a channel in delta mode enables delta compression. This is a way for a client to subscribe to a channel so that message payloads sent contain only the difference (ie the delta) between the present message and the previous message on the channel.

Request a Vcdiff formatted delta stream using channel options when you get the channel:

var channelParams = new ChannelParams();
channelParams.Add("delta", "vcdiff");
var channelOptions = new ChannelOptions();
channelOptions.Params = channelParams;
IRealtimeChannel channel = ably.Channels.Get(ChannelName, channelOptions);

Beyond specifying channel options, the rest is transparent and requires no further changes to your application. The message.Data instances that are delivered to your Action<Message> handler continue to contain the values that were originally published.

If you would like to inspect the Message instances in order to identify whether the Data they present was rendered from a delta message from Ably then you can see if Extras.Delta.Format equals "vcdiff".

Publishing to a channel

The client support a callback and async publishing. The simplest way to publish is:

channel.Publish("greeting", "Hello World!");

with a callback:

channel.Publish("greeting", "Hello World!", (success, error) =>
{
    // If publish succeeded 'success' is 'true'
    // if publish failed 'success' is 'false' and 'error' will contain the specific error
});

and the async version which if you await it will complete when the message has been acknowledged or rejected by the Ably service:

var result = await channel.PublishAsync("greeting", "Hello World!");
// You can check if the message failed
if (result.IsFailure)
{
    var error = result.Error; // The error reason can be accessed as well
}

Getting channel history

Calling history returns a paginated list of message. The object is of type PaginatedResult<Message> and can be iterated through as a normal list.

var history = await channel.HistoryAsync();
// Loop through current history page
foreach (var message in history.Items)
{
    // Do something with message
}
// Get next page.
var nextPage = await history.NextAsync();

Getting presence history

Getting presence history is similar to how message history works. You get back PaginatedResult<PresenceMessage> and can navigate or iterate through the page

var presenceHistory = await channel.Presence.HistoryAsync();
// Loop through the presence messages
foreach (var presence in presenceHistory.Items)
{
    // Do something with the messages
}

var presenceNextPage = await presenceHistory.NextAsync();

Getting the channel status

Getting the current status of a channel, including details of the current number of Publishers, Subscribers and PresenceMembers etc is simple

ChannelDetails details = channel.Status();
ChannelMetrics metrics = details.Status.Occupancy.Metrics;
// Do something with 'metrics.Publishers' etc

Symmetric end-to-end encrypted payloads on a channel

When a 128-bit or 256-bit key is provided to the library, all payloads are encrypted and decrypted automatically using that key on the channel. The secret key is never transmitted to Ably and thus it is the developer's responsibility to distribute a secret key to both publishers and subscribers.

var secret = Crypto.GetRandomKey();
var encryptedChannel = realtime.Get("encrypted", new ChannelOptions(secret));
encryptedChannel.Subscribe(message =>
{
    var data = message.data; // Sensitive data (encrypted before published)
});
encryptedChannel.Publish("name (not encrypted)", "sensitive data (encrypted before published)");

Using the REST API

Introduction

The rest client provides a fully async wrapper around the Ably service web api.

All examples assume a client and/or channel has been created as follows:

var client = new AblyRest("<api key>");
IRealtimeChannel channel = client.Channels.Get("test");

If you do not have an API key, sign up for a free API key now

Publishing a message to a channel

await channel.PublishAsync("name", "data");

If the publish is not successful an error will be thrown of type AblyException containing error codes and error description

try 
{
    await channel.PublishAsync("name", "errorData");
} 
catch(AblyException ablyError) 
{
    // Log error
}

Querying channel history

var historyPage = await channel.HistoryAsync();
foreach (var message in historyPage.Items)
{
    // Do something with each message
}
// Get the next page
var nextHistoryPage = await historyPage.NextAsync();

Current presence members on a channel

var presence = await channel.Presence.GetAsync();
var first = presence.Items.FirstOrDefault();
var clientId = first.clientId; // 'clientId' of the first member present
var nextPresencePage = await presence.NextAsync();
foreach (var presenceMessage in nextPresencePage.Items)
{
    // Do stuff with next page presence messages
}

Querying the presence history

// Presence history
var presenceHistory = await channel.Presence.HistoryAsync();
foreach (var presenceMessage in presenceHistory.Items)
{
    // Do stuff with presence messages
}

var nextPage = await presenceHistory.NextAsync();
foreach (var presenceMessage in nextPage.Items)
{
    // Do stuff with next page messages
}

Using the AuthCallback

A callback to obtain a signed TokenRequest string or a TokenDetails instance.

To use AuthCallback create a ClientOptions instance and assign an appropriate delegate to the AuthCallback property and pass the ClientOptions to a new AblyRealtime instance.

var options = new ClientOptions
{
    AuthCallback = async tokenParams =>
    {
        // Return a 'TokenDetails' instance or a preferably a 'TokenRequest' string.
        // Typically this method would wrap a request to your web server.
        return await GetTokenDetailsOrTokenRequestStringFromYourServer();        
    }
};
var client = new AblyRealtime(options);

Generate a TokenRequest

Token requests are issued by your servers and signed using your private API key. This is the preferred method of authentication as no secrets are ever shared, and the token request can be issued to trusted clients without communicating with Ably.

string tokenRequest = await client.Auth.CreateTokenRequestAsync();

Fetching your application's stats

var stats = await client.StatsAsync();
var firstItem = stats.Items.First();
var nextStatsPage = await stats.NextAsync();

Fetching the Ably service time

DateTimeOffset time = await client.TimeAsync();

Increase Transport send and receive buffers

In .NET Framework projects, we discovered issues with the .NET implementation of the web socket protocol during times of high load with large payloads (over 50kb). This is better described in https://github.com/ably/ably-dotnet/issues/446 To work around the problem, you need to adjust websocket library's buffer to it's maximum size of 64kb. Here is an example of how to do it.

var maxBufferSize = 64 * 1024;
var options = new ClientOptions();
var websocketOptions = new MsWebSocketOptions() { SendBufferInBytes = maxBufferSize, ReceiveBufferInBytes = maxBufferSize };
options.TransportFactory = new MsWebSocketTransport.TransportFactory(websocketOptions);
var realtime = new AblyRealtime(options);

Examples

  • More Examples can be found under examples directory.
  • While working with console app, make sure to put explicit await for async methods.

Sample .NET Core implementation

using System;

using IO.Ably;

namespace testing_ably_console
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var realtime = new AblyRealtime("<api key>");
            IRealtimeChannel channel = realtime.Channels.Get("test");
            await channel.PublishAsync("greeting", "Hello World!");
            Console.WriteLine("Farewell World!");
        }
    }
}

Sample .NET Framework implementation (when you don't have async main method)*

using System;

using IO.Ably;

namespace testing_ably_console
{
    class Program
    {
        static void Main(string[] args)
        {
            MainAsync(args).GetAwaiter().GetResult();
        }

        static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Hello World!");
            var realtime = new AblyRealtime("<api key>");
            IRealtimeChannel channel = realtime.Channels.Get("test");
            await channel.PublishAsync("greeting", "Hello World!");
        }
    }
}

Dependencies

This library has dependencies that can differ depending on the target platform. See the nuget page for specifics.

Support, feedback and troubleshooting

Please visit https://ably.com/support for access to our knowledge-base and to ask for any assistance.

You can also view the community reported GitHub issues.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Ensure you have added suitable tests and the test suite is passing
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Building and Packaging

The build scripts are written using fake and need to be run on Windows with Visual Studio 2019 installed. Fake and nuget.exe can be installed via chocolatey

choco install fake
choco install nuget.commandline

Running .\build.cmd will start the build process and run the tests. By default it runs the NetFramework tests. To run the Netcore build and tests you can run .\build.cmd Test.NetStandard

Working from source

If you want to incorporate ably-dotnet into your project from source (perhaps to use a specific development branch) the simplest way to do so is to add references to the relevant ably-dotnet projects. The following steps are specific to Visual Studio 2019, but the principal should transfer to other IDEs

  1. Clone this repository to your local system (git clone --recurse-submodules https://github.com/ably/ably-dotnet.git)
  2. Open the solution you want to reference ably-dotnet from
  3. In Solution Explorer right click the root node (it will be labelled Solution 'YourSolutionName')
  4. Select Add > Existing Project from the context menu
  5. Browse to the ably-dotnet repository and add ably-dotnet\src\IO.Ably.Shared\IO.Ably.Shared.shproj
  6. Browse to the ably-dotnet repository and add the project that corresponds to your target platform, so if you are targeting .NET Framework (AKA Classic .NET) you would add ably-dotnet\src\IO.Ably.NETFramework\IO.Ably.NETFramework.csproj, if you are targeting .NET Core 2 then chose ably-dotnet\src\IO.Ably.NetStandard20\IO.Ably.NetStandard20.csproj and so on.
  7. In any project that you want to use ably-dotnet you need to add a project reference, to do so:
    1. Find your project in Solution Explorer and expand the tree so that the Dependencies node is visible
    2. Right click Dependencies and select Add Reference
    3. In the dialogue that opens you should see a list of the projects in your solution. Check the box next to IO.Ably.NETFramework (or whatever version you are trying to use) and click OK.

Spec

The dotnet library follows the Ably Client Library development guide. To ensure it is easier to look up whether a spec item has been implemented or not; we add a Trait attribute to tests that implement parts of the spec. The convention is to add [Trait("spec", "spec tag")] to unit tests.

To get a list of all spec items that appear in the tests you can run a script located in the tools directory. You need to have .NET Core 3.1 installed. It works on Mac, Linux and Windows. Run dotnet fsi tools/list-test-categories.fsx. It will produce a results.csv file which will include all spec items, which file it was found and on what line.

Release process

This library uses semantic versioning. For each release, the following needs to be done:

  1. Create a release branch named in the form release/1.2.3.
  2. Run github_changelog_generator to automate the update of the CHANGELOG. Once the CHANGELOG update has completed, manually change the Unreleased heading and link with the current version number such as v1.2.3. Also ensure that the Full Changelog link points to the new version tag instead of the HEAD. Commit this change.
  3. Update the version number and commit that change.
  4. Create a release PR (ensure you include an SDK Team Engineering Lead and the SDK Team Product Manager as reviewers) and gain approvals for it, then merge that to main.
  5. Run package.cmd to create the nuget package.
  6. Run nuget push ably.io.*.nupkg -Source https://www.nuget.org/api/v2/package (a private nuget API Key is required to complete this step, more information on publishing nuget packages can be found here)
  7. Against main, add a tag for the version and push to origin such as git tag 1.2.3 && git push origin 1.2.3.
  8. Visit https://github.com/ably/ably-dotnet/tags and Add release notes for the release including links to the changelog entry.
  9. Create the entry on the Ably Changelog (via headwayapp)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].