redstone_web_socket 0.1.0

  • README.md
  • Installing
  • Versions
  • 19

Redstone WebSocket

Build Status

redstone_web_socket is a web socket plugin for Redstone.dart. It uses the shelf_web_socket package to create web socket handlers.

Using @WebSocketHandler with functions

If a function is annotated with @WebSocketHandler, it'll be invoked with a WebSocketChannel object for every new established connection:

@WebSocketHandler("/ws")
onConnection(WebSocketChannel channel) {
  channel.stream.listen((message) {
    channel.sink.add("echo $message");
  });
}

Using @WebSocketHandler with classes

If a class is annotated with @WebSocketHandler, the plugin will install a event listener for every method annotated with @OnOpen, @OnMessage, @OnError and @OnClose:


@WebSocketHandler("/ws")
class ServerEndPoint {

  @OnOpen()
  void onOpen(WebSocketSession session) {
    print("connection established");
  }

  @OnMessage()
  void onMessage(String message, WebSocketSession session) {
    print("message received: $message");
    session.connection.add("echo $message");
  }

  @OnError()
  void onError(error, WebSocketSession session) {
    print("error: $error");
  }

  @OnClose()
  void onClose(WebSocketSession session) {
    print("connection closed");
  }

}

Like redstone groups, the class will be instantiated only once, and it can request injectable objects with a constructor (see dependency injection).

Installing handlers

To install web socket handlers, you just have to import redstone_web_socket.dart and call getWebSocketPlugin():

import 'package:redstone/server.dart' as app;
import 'package:redstone_web_socket/redstone_web_socket.dart';

void main() {
  app.setupConsoleLog();

  //install web socket handlers
  app.addPlugin(getWebSocketPlugin());

  app.start();
}

Unit Tests

This package also provides a simple mock client, which can be used in unit tests:

import 'package:redstone/server.dart' as app;
import 'package:redstone_web_socket/redstone_web_socket.dart';
import 'package:unittest/unittest.dart';

main() {

  test("Test echo service", () {

    var completer = new Completer();
    var socket = new MockWebSocket();

    socket.listen((message) {

      expect(message, equals("echo message"));

      completer.complete();
    });

    openMockConnection("/ws", socket);

    socket.add("message");

    return completer.future;

  });

}

Use this package as a library

1. Depend on it

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


dependencies:
  redstone_web_socket: "^0.1.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


      import 'package:redstone_web_socket/redstone_web_socket.dart';
  
Version Uploaded Documentation Archive
0.1.0 Dec 28, 2016 Go to the documentation of redstone_web_socket 0.1.0 Download redstone_web_socket 0.1.0 archive
0.0.2 Oct 12, 2014 Go to the documentation of redstone_web_socket 0.0.2 Download redstone_web_socket 0.0.2 archive
0.0.1 Aug 27, 2014 Go to the documentation of redstone_web_socket 0.0.1 Download redstone_web_socket 0.0.1 archive
0.1.0-beta.1 Mar 22, 2015 Go to the documentation of redstone_web_socket 0.1.0-beta.1 Download redstone_web_socket 0.1.0-beta.1 archive

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
40 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
36 / 100
Overall score:
Weighted score of the above. [more]
19
Learn more about scoring.

Platforms

Detected platforms: other

Primary library: package:redstone_web_socket/redstone_web_socket.dart with components: isolate, mirrors.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 errors 1 hint.

    Strong-mode analysis of lib/redstone_web_socket.dart failed with the following error:

    line: 231 col: 7
    Missing concrete implementations of 'StreamChannelMixin.cast', 'StreamChannelMixin.changeSink', 'StreamChannelMixin.changeStream', 'StreamChannelMixin.pipe' and 3 more.

  • Package is getting outdated.

    The package was released 80 weeks ago.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use redstone_web_socket.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.13.0 <2.0.0
di ^3.3.10 3.3.10
redstone ^0.6.7 0.6.8
shelf_web_socket ^0.2.1 0.2.2 0.2.2+2
Transitive dependencies
analyzer 0.27.2 0.32.3
ansicolor 0.0.10 0.1.1
args 0.13.7 1.4.3
async 1.13.3 2.0.7
barback 0.15.2+16
boolean_selector 1.0.4
charcode 1.1.2
cli_util 0.0.1+2 0.1.3
code_transformers 0.3.1 0.5.1+5
collection 1.14.10
convert 2.0.1
crypto 2.0.6
csslib 0.13.7+1 0.14.4
glob 1.1.6
grinder 0.8.0+3 0.8.2
html 0.12.2+2 0.13.3+1
http 0.11.3+17
http_multi_server 2.0.5
http_parser 3.1.2
http_server 0.9.8
io 0.3.3
js 0.6.1
logging 0.11.3+1
matcher 0.12.2+1 0.12.3
meta 1.1.5
mime 0.9.6+1
mockable_filesystem 0.0.3
multi_server_socket 1.0.1
node_preamble 1.4.3
package_config 0.1.5 1.0.3
package_resolver 1.0.3
path 1.6.1
plugin 0.1.0 0.2.0+2
pool 1.3.5
pub_semver 1.4.1
route_hierarchical 0.7.0
shelf 0.6.8 0.7.3+2
shelf_packages_handler 1.0.3
shelf_static 0.2.8
source_map_stack_trace 1.1.4
source_maps 0.10.6
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.7+1
string_scanner 1.0.2
supports_color 0.1.1
term_glyph 1.0.0
typed_data 1.1.5
unscripted 0.6.2
utf 0.9.0+4
watcher 0.9.7+9
web_socket_channel 1.0.8
when 0.2.0
which 0.1.3
yaml 2.1.14
Dev dependencies
test ^0.12.0 0.12.37 1.2.0