sockjs_client_wrapper 1.0.7

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 64

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.7

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';
  
Version Uploaded Documentation Archive
1.0.7 Aug 16, 2018 Go to the documentation of sockjs_client_wrapper 1.0.7 Download sockjs_client_wrapper 1.0.7 archive
1.0.5 Aug 1, 2018 Go to the documentation of sockjs_client_wrapper 1.0.5 Download sockjs_client_wrapper 1.0.5 archive
1.0.4 Jul 2, 2018 Go to the documentation of sockjs_client_wrapper 1.0.4 Download sockjs_client_wrapper 1.0.4 archive
1.0.3 Apr 18, 2018 Go to the documentation of sockjs_client_wrapper 1.0.3 Download sockjs_client_wrapper 1.0.3 archive
1.0.2 Feb 2, 2018 Go to the documentation of sockjs_client_wrapper 1.0.2 Download sockjs_client_wrapper 1.0.2 archive
1.0.1 Dec 12, 2017 Go to the documentation of sockjs_client_wrapper 1.0.1 Download sockjs_client_wrapper 1.0.1 archive
0.0.0 Dec 12, 2017 Go to the documentation of sockjs_client_wrapper 0.0.0 Download sockjs_client_wrapper 0.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
72
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Aug 16, 2018, and provided a score, details, and suggestions below. Analysis was completed with status tool failures using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 
 Because sockjs_client_wrapper depends on w_common >=0.2.0 which requires SDK version >=1.12.0 <2.0.0, version solving failed.

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed.

Make sure dartdoc runs without any issues.

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.2 <3.0.0