sockjs_client_wrapper 1.0.3

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

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.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);
}

1. Depend on it

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


dependencies:
  sockjs_client_wrapper: "^1.0.3"

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

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: web, other

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

Suggestions

  • 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 <2.0.0
js ^0.6.1 0.6.1
w_common ^1.9.0 1.11.2
Transitive dependencies
logging 0.11.3+1
meta 1.1.2
Dev dependencies
browser ^0.10.0+2
coverage ^0.10.0
dart_dev ^1.8.1
dart_style ^1.0.8
dependency_validator ^1.0.0
test ^0.12.27+1