socketcluster_client 0.0.3

SocketCluster Dart Client #

Build Status Coverage Status

SocketCluster Client is the client-side component of SocketCluster.

Example Usage #

  var socket = await Socket.connect('ws://localhost:8000/socketcluster/',
      listener: new MyListener());
      
  socket.on('rand', (name, data, ack) {
    print('got message $data from event $name');
    ack(name, 'No error', 'Hi there buddy');
  });

Note #

This is a straight and dirty port from the C# client.

Large changes will be made to clean this up and make it more 'Dartified'

For instance, BasicListener will be removed in favor of Stream

0.0.3 #

  • Allow listener to be optional.
  • Added test framework (Thanks to Michael Marner).

0.0.2 #

  • Added license.

0.0.1 - October 8th, 2018 #

  • Initial release.

example/main.dart

import 'package:socketcluster_client/socketcluster_client.dart';
import 'dart:async';

class MyListener extends BasicListener {
  @override
  void onAuthentication(Socket socket, bool status) {
    print('onAuthentication: socket $socket status $status');
  }

  @override
  void onConnectError(Socket socket, e) {
    print('onConnectError: socket $socket e $e');
  }

  @override
  void onConnected(Socket socket) {
    print('onConnected: socket $socket');
    new Timer.periodic(const Duration(seconds: 2), (_) {
      print('Attempting to send');
      socket.emit('sampleClientEvent',
          {'message': 'This is an object with a message property'});
    });
  }

  @override
  void onDisconnected(Socket socket) {
    print('onDisconnected: socket $socket');
  }

  @override
  void onSetAuthToken(String token, Socket socket) {
    print('onSetAuthToken: socket $socket token $token');
    socket.authToken = token;
  }
}

main() async {
  var socket = await Socket.connect('ws://localhost:8000/socketcluster/',
      listener: new MyListener());
  socket.on('rand', (name, data, ack) {
    print('got message $data from event $name');
    ack(name, 'No error', 'Hi there buddy');
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  socketcluster_client: ^0.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:socketcluster_client/socketcluster_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:socketcluster_client/socketcluster_client.dart with components: io.

Health suggestions

Fix lib/src/reconnect_strategy.dart. (-1.99 points)

Analysis of lib/src/reconnect_strategy.dart reported 4 hints:

line 5 col 3: Prefer using /// for doc comments.

line 11 col 3: Prefer using /// for doc comments.

line 17 col 3: Prefer using /// for doc comments.

line 25 col 88: Don't explicitly initialize variables to null.

Fix lib/src/emitter.dart. (-0.50 points)

Analysis of lib/src/emitter.dart reported 1 hint:

line 34 col 7: DO use curly braces for all flow control structures.

Fix lib/src/parser.dart. (-0.50 points)

Analysis of lib/src/parser.dart reported 1 hint:

line 15 col 7: DO use curly braces for all flow control structures.

Format lib/socketcluster_client.dart.

Run dartfmt to format lib/socketcluster_client.dart.

Format lib/src/channel.dart.

Run dartfmt to format lib/src/channel.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.

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0

Admin