26 August 2014

A new Redstone.dart plugin is available on pub: redstone_web_socket.

This plugin is a wrapper to the shelf_web_socket package. It provides a @WebSocketHandler annotation, which can be used to define web socket handlers:

onConnection(websocket) {
  websocket.listen((message) {
    websocket.add("echo $message");

The @WebSocketHandler annotation can also be used with classes:

class ServerEndPoint {

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

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

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

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


The plugin also provides a simple mock client, which can be used to test web socket handlers:

import 'package:redstone/redstone.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"));


    openMockConnection("/ws", socket);


    return completer.future;



For more details, please take a look at the documentation.

comments powered by Disqus