Search packages, repositories and app categories

Package detailsv1.5.0

sockjs_client_wrapper

A Dart wrapper for the `sockjs-client` JS library.

Web
30-day downloads
28.6K
Likes
0
Pub points
120

Install package

flutter pub add sockjs_client_wrapper

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Dart wrapper for the `sockjs-client` JavaScript library, enabling WebSocket-like communication in Flutter web applications. It provides a simple interface to establish and manage connections with SockJS servers, supporting real-time data exchange over various transport methods including WebSockets, long polling, and more. The package is designed specifically for web platforms and integrates seamlessly into Flutter web projects. It abstracts low-level details, making it easier to handle events like connection open, message receipt, and errors.

Use cases

  • Real-time chat applications
  • Live dashboard updates
  • Web-based collaborative tools
  • Event-driven web interfaces
  • Server-sent notifications

Key features

  • Cross-transport compatibility
  • Simple event-driven API
  • Seamless integration with Flutter web
  • Automatic fallback to alternative transports
  • Support for connection state management

Suitable for

  • Flutter web developers needing real-time features
  • Projects using SockJS servers
  • Applications requiring reliable client-server communication
  • Developers seeking lightweight WebSocket alternatives
  • Use cases where browser compatibility is critical

Considerations

  • Only supports web platform
  • Relies on JavaScript interop
  • May require additional error handling for network issues
  • Limited to SockJS server endpoints
  • Not suitable for mobile or desktop apps

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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

Install dependencies
$ npm install
$ dart pub get
Run the example
$ dart run dart_dev serve
Run tests
$ dart run dart_dev test

Categories

Dependencies

Dependency list 2 items

  • js^0.6.1
  • w_common>=2.0.0 <5.0.0

Source repository

Projects using this package