signalr_client 0.0.1

  • Installing
  • Versions
  • 82

signalr_client #

A Flutter SignalR Client for ASP.NET Core.
The client supports the following transport protocols:

  • WebSocket
  • Service Side Events
  • Long Polling

The client supports the following hub protocols:

  • Json
  • MessagePack Since I can't find a MessagePack library that support the current flutter version.

Examples #

Getting Started #

Add signalr_client to your pubspec.yaml dependencies:

    sdk: flutter


Usage #

Let's demo some basic usages:

1. Create a hub connection: #

// Import the library.
import 'package:signalr_client/signalr_client.dart';

// The location of the SignalR Server.
final serverUrl = "";
// Prints log messages to the console.
final logger = ConsoleLogger();
// Creates the connection by using the HubConnectionBuilder.
final hubConnection = HubConnectionBuilder().withUrl(serverUrl).configureLogging(logger: logger).build();
// When the connection is closed, print out a message to the logger.
final hubConnection.onclose( (error) => logger.log(LogLevel.Information, "Connection Closed"));

2. Calling a Hub function: #

Assuming there is this hub function:

public string MethodOneSimpleParameterSimpleReturnValue(string p1)
  Console.WriteLine($"'MethodOneSimpleParameterSimpleReturnValue' invoked. Parameter value: '{p1}");
  return p1;

The client can invoke the function by using:

  final result = await hubConnection.invoke("MethodOneSimpleParameterSimpleReturnValue", args: <Object>["ParameterValue"]);
  logger.log(LogLevel.Information, "Result: '$result");

3. Calling a client function: #

Assuming the server calls a function "aClientProvidedFunction":

  await Clients.Caller.SendAsync("aClientProvidedFunction", null);

The Client provides the function like this:

  hubConnection.on("aClientProvidedFunction", _handleAClientProvidedFunction);

  // To unregister the function use:
  // a) to unregister a specific implementation:
  //"aClientProvidedFunction", method: _handleServerInvokeMethodNoParametersNoReturnValue);
  // b) to unregister all implementations:
  void _handleAClientProvidedFunction(List<Object> parameters) {
    logger.log(LogLevel.Information, "Server invoked the method");

A note about the parameter types #

All function parameters and return values are serialized/deserialized into/from JSON by using the dart:convert package (json.endcode/json.decode). Make sure that you:

  • use only simple parameter types


  • use objects that implements toJson() since these method is used by the dart:convert package to serialize an object.

Flutter Json 101:

[0.0.1] - 10.17.2018

  • Intitial Version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  signalr_client: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:signalr_client/signalr_client.dart';
Version Uploaded Documentation Archive
0.1.5 Feb 26, 2019 Go to the documentation of signalr_client 0.1.5 Download signalr_client 0.1.5 archive
0.1.4 Feb 19, 2019 Go to the documentation of signalr_client 0.1.4 Download signalr_client 0.1.4 archive
0.1.3 Oct 29, 2018 Go to the documentation of signalr_client 0.1.3 Download signalr_client 0.1.3 archive
0.1.2 Oct 18, 2018 Go to the documentation of signalr_client 0.1.2 Download signalr_client 0.1.2 archive
0.1.1 Oct 18, 2018 Go to the documentation of signalr_client 0.1.1 Download signalr_client 0.1.1 archive
0.1.0 Oct 18, 2018 Go to the documentation of signalr_client 0.1.0 Download signalr_client 0.1.0 archive
0.0.1 Oct 17, 2018 Go to the documentation of signalr_client 0.0.1 Download signalr_client 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 8, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/http_connection.dart. (-1.49 points)

Analysis of lib/http_connection.dart reported 3 hints:

line 245 col 68: Avoid using braces in interpolation when not needed.

line 277 col 84: Avoid using braces in interpolation when not needed.

line 312 col 82: Avoid using braces in interpolation when not needed.

Fix lib/hub_connection.dart. (-0.50 points)

Analysis of lib/hub_connection.dart reported 1 hint:

line 373 col 59: Avoid using braces in interpolation when not needed.

Fix lib/utils.dart. (-0.50 points)

Analysis of lib/utils.dart reported 1 hint:

line 25 col 1: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix additional 13 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/web_socket_transport.dart (1 hint)
  • lib/dartio_http_client.dart (Run flutter format to format lib/dartio_http_client.dart.)
  • lib/errors.dart (Run flutter format to format lib/errors.dart.)
  • lib/handshake_protocol.dart (Run flutter format to format lib/handshake_protocol.dart.)
  • lib/http_connection_options.dart (Run flutter format to format lib/http_connection_options.dart.)
  • lib/hub_connection_builder.dart (Run flutter format to format lib/hub_connection_builder.dart.)
  • lib/ihub_protocol.dart (Run flutter format to format lib/ihub_protocol.dart.)
  • lib/itransport.dart (Run flutter format to format lib/itransport.dart.)
  • lib/json_hub_protocol.dart (Run flutter format to format lib/json_hub_protocol.dart.)
  • lib/long_polling_transport.dart (Run flutter format to format lib/long_polling_transport.dart.)
  • lib/server_sent_events_transport.dart (Run flutter format to format lib/server_sent_events_transport.dart.)
  • lib/signalr_http_client.dart (Run flutter format to format lib/signalr_http_client.dart.)
  • lib/text_message_format.dart (Run flutter format to format lib/text_message_format.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and signalr_client.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
w3c_event_source ^1.0.0 1.3.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies