Skip to content

NPM v2.0.7-beta + Nuget v2.2.2-pre

Pre-release
Pre-release
Compare
Choose a tag to compare
@dsuryd dsuryd released this 22 Oct 05:30
· 1135 commits to master since this release

This release provides the integration with the latest SignalR for ASP.NET Core 2.0 (currently alpha2).

Upgrade from Previous Version

Both the client and server must be upgraded. Your ASP.NET Core Web project must target .NET Core 2.0. In Startup.cs, update the call UseSignalR() to:

UseSignalR(route => route.MapDotNetifyHub());

The latest SignalR for .NET Core is not compatible with SignalR for .NET Framework. While dotNetify client-side library can be used for both, make sure the client matches the server it connects with. The .NET Core library is assumed by default. To switch to the other library, add this to the entry point:

import signalR from 'dotnetify/dist/signalR-netfx';  
dotnetify.hubLib = signalR;

If you use Webpack with babel loader, the loader will need exclude: /node_modules/ to avoid bundling error.

Transport Fallback

SignalR for .NET Core no longer provides transport fallback, i.e. falling back to SSE or HTTP long polling if WebSocket is not supported. However, this feature is now being fulfilled by dotNetify. By default, dotNetify will fall back to long polling when WebSocket fails. The fallback order and type can be configured as below:

dotnetify.hubOptions = { transport: ["webSockets", "serverSentEvent", "longPolling"] };

Note that SSE has been observed in some environments to exhibit long delay during the initial connection. The exact cause is still unknown.

Connection State Management

You can receive notification when the connection state changed by providing a handler function:

dotnetify.connectionStateHandler = (state) => { /* handle state changed event */};

The state's possible values are: "connecting", "connected", "reconnecting", "disconnected" and "terminated".

If the connection gets disconnected, as part of its resiliency feature, dotNetify will automatically attempt to reconnect indefinitely, with the delay between attempts of 2 seconds, 5 seconds, and then every 10 seconds afterwards. These can be configured as below:

dotnetify.hub.init();
dotnetify.hub.reconnectDelay = [5, 30];
dotnetify.hub.reconnectRetry = 10;

The above configuration indicates that the reconnect attempt is limited to 10 times after every disconnected event, with initial delay of 5 seconds and then every 30 seconds afterwards. When the retry attempt is exhausted, the "terminated" state is triggered.