A Flutter SignalR Client for ASP.NET Core.
The client supports the following transport protocols:
The client supports the following hub protocols:
Add signalr_client
to your pubspec.yaml
dependencies:
...
dependencies:
flutter:
sdk: flutter
signalr_client:
...
Let's demo some basic usages:
// Import the library.
import 'package:signalr_client/signalr_client.dart';
// The location of the SignalR Server.
final serverUrl = "192.168.10.50:51001";
// 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"));
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");
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:
// hubConnection.off("aClientProvidedFunction", method: _handleServerInvokeMethodNoParametersNoReturnValue);
// b) to unregister all implementations:
// hubConnection.off("aClientProvidedFunction");
...
void _handleAClientProvidedFunction(List<Object> parameters) {
logger.log(LogLevel.Information, "Server invoked the method");
}
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:
or
Flutter Json 101:
Add this to your package's pubspec.yaml file:
dependencies:
signalr_client: ^0.0.1
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:signalr_client/signalr_client.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.3 | Oct 29, 2018 |
|
|
0.1.2 | Oct 18, 2018 |
|
|
0.1.1 | Oct 18, 2018 |
|
|
0.1.0 | Oct 18, 2018 |
|
|
0.0.1 | Oct 17, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
75
|
Health:
Code health derived from static analysis.
[more]
|
97
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
60
|
Overall:
Weighted score of the above.
[more]
|
79
|
We analyzed this package on Feb 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
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
.)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/README.md
.
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 | |||
flutter_test |