websok 2.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new75

websok #

A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.

Supports IO and HTML websockets.

Getting Started #

/// For HTML:
/// import 'package:websok/html.dart';
///
/// For IO (Flutter, Dart, etc.)
import 'package:websok/io.dart';

/// Testing library.
import 'package:test/test.dart';

/// The received string.
String received;
/// Callback to execute when the function is over.
void onData(dynamic message) => received = message;

void main() {
  test('Performs a test websocket connection', () async {
    /// For HTML: IOWebsok -> HTMLWebsok
    final sok = IOWebsok(host: 'echo.websocket.org', tls: true)
      ..connect()
      ..listen(onData: onData);
    // Assets the connection.
    expect(sok.isActive, true);
    // Send a message.
    final message = 'Hello, world!';
    sok.send(message);
    // Check the message.
    await Future.delayed(Duration(seconds: 1), () => expect(received, message));
    // Close the connection after 1 sec.
    sok.close();
    // Assets the connection.
    expect(sok.isActive, false);
  });
}

[2.1.1] - Lowered depedencies for compatibility

  • Lowered meta dependency for compatibility

[2.1.1] - Fixes to HTML websocket.

  • Fixed HTML websocket path.

[2.1.0] - Add additional paths to the connection URL.

  • Add additional paths to the connection URL.
  • Isolated and created a .url() function that returns the connection URL.
  • Copyright to main lib.

[2.0.4] - Flutter format

  • Flutter format.

[2.0.3] - Small fixes

  • Naming issues.

[2.0.2] - Small fixes

  • Fixes to README.md and websok_test.dart
  • Added example folder.
  • Tried swaping some lib config to make it available on all platforms.

[2.0.1] - Additional info to pubspec.yaml

  • Added more info to pubspec.yaml

[2.0.0] - Available on Web

  • Websok is now also available on web.
  • Use html.dart for HTML websockets, otherwise use io.dart.

[1.1.0] - Available on Dart

  • Websok is now also available on dart.
  • Fixed TLS issue when no port provided.

[1.0.0] - Initial version

  • Initial release.

example/example.dart

/// For HTML:
/// import 'package:websok/html.dart';
///
/// For IO (Flutter, Dart, etc.)
import 'package:websok/io.dart';

/// The received string.
String received;
/// Callback to execute when the function is over.
void onData(dynamic message) => received = message;

void main() async {
  /// For HTML: IOWebsok -> HTMLWebsok
  final sok = IOWebsok(host: 'echo.websocket.org', tls: true)
    ..connect()
    ..listen(onData: onData);
  // Send a message.
  sok.send('Hello, world!');
  // Prints the message.
  await Future.delayed(Duration(seconds: 1), () => print(received));
  // Close the connection after 1 sec.
  sok.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  websok: ^2.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


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

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

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:websok/websok.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.1.7 1.1.8
web_socket_channel ^1.1.0 1.1.0
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
stream_channel 2.0.0
typed_data 1.1.6
Dev dependencies
test ^1.9.4