sockjs_client_wrapper 1.0.11

SockJS Client Wrapper #

A Dart wrapper around the SockJS Client. Uses the js Dart package to interop with the JS lib.

Usage #

Include the SockJS library in your app's index.html prior to the main Dart/JS script:

<!DOCTYPE html>
<html>
  <head> ... </head>
  <body>
    <!-- For local dev/debugging, use the unminified version: -->
    <script src="/packages/sockjs_client_wrapper/sockjs.js"></script>

    <!-- In production, use the minified version:  -->
    <script src="/packages/sockjs_client_wrapper/sockjs_prod.js"></script>
  </body>
</html>

Import package:sockjs_client_wrapper/sockjs_client_wrapper.dart and create a SockJSClient instance that will connect to a SockJS server:

import 'package:sockjs_client_wrapper/sockjs_client_wrapper.dart';

Future<Null> main() async {
  final client = new SockJSClient(Uri.parse('ws://localhost:9000/echo'));
  await client.onOpen.first;
  client.send('Hello!');
  ...
}

Development #

To install dependencies:

$ npm install
$ pub get

To run the example:

$ node example/server.js
$ pub serve example

To run tests:

$ pub run ddev test

1.0.5 #

  • Dart 2 compatible.

1.0.4 #

  • Updated the SockJS library to v1.1.5 to pull in a fix for an issue where xhr_streaming loops infinitely after the connection closes.

1.0.3 #

  • Compatible with latest Dart 2.x dev channel and Dart Dev Compiler.

1.0.2 #

  • Logging was disabled as it was originally too verbose.

1.0.1 #

  • Add a version check to CI.

1.0.0 #

  • Initial release.

example/main.dart

// Copyright 2017 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:async';

import 'package:sockjs_client_wrapper/sockjs_client_wrapper.dart';

Future<Null> main() async {
  print('Starting example');
  final echoUri = Uri.parse('http://localhost:9999/echo');
  final options = new SockJSOptions(
      transports: ['websocket', 'xhr-streaming', 'xhr-polling']);
  final socket = new SockJSClient(echoUri, options: options);

  socket.onOpen.listen((event) {
    print('OPEN: ${event.transport} ${event.url}');
  });

  socket.onMessage.listen((event) {
    print('MSG: ${event.data}');
  });

  socket.onClose.listen((event) {
    print('CLOSE: ${event.code} ${event.reason} (wasClean ${event.wasClean})');
  });

  await new Future<Null>.delayed(const Duration(milliseconds: 500));
  socket.send('test');

  await new Future<Null>.delayed(const Duration(milliseconds: 500));
  socket.send('test 2');

  await new Future<Null>.delayed(const Duration(seconds: 5));

  socket.close(4002);
}

Use this package as a library

1. Depend on it

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


dependencies:
  sockjs_client_wrapper: ^1.0.11

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:sockjs_client_wrapper/sockjs_client_wrapper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
73
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

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

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: web

Primary library: package:sockjs_client_wrapper/sockjs_client_wrapper.dart with components: html, js.

Health suggestions

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

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

line 146 col 24: This function has a return type of 'Future', but doesn't end with a return statement.

Maintenance suggestions

The package description is too short. (-10 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.2 <3.0.0
js ^0.6.1 0.6.1+1
w_common ^1.9.0 1.20.1
Transitive dependencies
args 1.5.2
async 2.3.0
charcode 1.1.2
cli_repl 0.2.0+1
collection 1.14.12
colorize 2.0.0
dart2_constant 1.0.2+dart2
glob 1.1.7
http 0.12.0+2
http_parser 3.1.3
intl 0.15.8 0.16.0
logging 0.11.3+2
matcher 0.12.5
meta 1.1.7
package_config 1.1.0
package_resolver 1.0.10
path 1.6.4
pedantic 1.8.0+1
quiver 2.0.5
sass 1.22.12 1.23.0-module.beta.1
source_maps 0.10.8
source_span 1.5.5
stack_trace 1.9.3
stream_transform 0.0.19
string_scanner 1.0.5
term_glyph 1.1.0
tuple 1.0.2
typed_data 1.1.6
watcher 0.9.7+12
Dev dependencies
build_runner >=0.6.0 <2.0.0
build_test >=0.9.0 <1.0.0
build_web_compilers >=0.2.0 <3.0.0
coverage >=0.10.0 <0.13.0
dart_dev ^2.0.0
dart_style ^1.0.8
dependency_validator ^1.2.1
test >=0.12.30 <2.0.0