adonis_websok 1.0.3

adonis_websok #

A high level adonisjs websockets implementation for dart, flutter and web.

Getting Started #

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

void main() async {
  // Create a websocket connection and attach a JWT to it.
  // For HTML: IOAdonisWebsok -> HTMLAdonisWebsok
  final socket = IOAdonisWebsok(host: '192.168.0.100', port: 3333)
    ..withJwtToken('XXXXXXX');
  // Connect to the socket and await for response from the adonis server.
  await socket.connect();
  // Subscribe to the 'disponible' topic.
  final disponible = await socket.subscribe('disponible');
  // Set a callback to execute when a new event comes by.
  disponible.on('canvi', (data) => print('canvi: ${data.toString()}'));
  // To stop the listener, just perform disponible.off('canvi')
  // Emit send a new message to the server, with additional data if needed.
  disponible.emit('canvi'); // Accepts a data argument as the 2nd parameter.
  // Close the subscription (unsubscribe from the given topic).
  final closed = await disponible.close(); // Unsubscribe.
  // CLoses the socket connection.
  socket.close();
}

[1.0.3] - Lowered depedencies for compatibility

  • Lowered meta dependency for compatibility

[1.0.2] - Fixed small issues

  • More fixes to small issues pointed by pub.dev

[1.0.1] - Fixed small issues

  • Fixes to small issues pointed by pub.dev

[1.0.0] - Initial release

  • Initial release

example/example.dart

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

void main() async {
  // Create a websocket connection and attach a JWT to it.
  // For HTML: IOAdonisWebsok -> HTMLAdonisWebsok
  final socket = IOAdonisWebsok(host: '192.168.0.100', port: 3333)
    ..withJwtToken('XXXXXXX');
  // Connect to the socket and await for response from the adonis server.
  await socket.connect();
  // Subscribe to the 'disponible' topic.
  final disponible = await socket.subscribe('disponible');
  // Set a callback to execute when a new event comes by.
  disponible.on('canvi', (data) => print('canvi: ${data.toString()}'));
  // To stop the listener, just perform disponible.off('canvi')
  // Emit send a new message to the server, with additional data if needed.
  disponible.emit('canvi'); // Accepts a data argument as the 2nd parameter.
  // Close the subscription (unsubscribe from the given topic).
  final closed = await disponible.close(); // Unsubscribe.
  // CLoses the socket connection.
  socket.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  adonis_websok: ^1.0.3

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:adonis_websok/adonis_websok.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
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]
83
Learn more about scoring.

We analyzed this package on Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Format lib/adonis_websok.dart.

Run dartfmt to format lib/adonis_websok.dart.

Dependencies

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