Skip to main content

sl_adonis_websok 1.0.2 copy "sl_adonis_websok: ^1.0.2" to clipboard
sl_adonis_websok: ^1.0.2 copied to clipboard

Adonis (adonisjs) high level web sockets. Implements the websocket protocol specified by adonisjs.

example/example.dart

/// For HTML:
/// import 'package:sl_adonis_websok/html.dart';
///
/// For IO (Flutter, Dart, etc.)
// ignore_for_file: unused_local_variable

import 'package:sl_adonis_websok/io.dart';

import '../test/sl_adonis_websok_test.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(onError: (error) {}, onDone: () {});
  // 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();
}

extension on Object? {
  void on(String s, void Function(data) param1) {}

  void emit(String s) {}

  Future<dynamic> close() async {}
}
0
likes
60
points
8
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Adonis (adonisjs) high level web sockets. Implements the websocket protocol specified by adonisjs.

Homepage

License

MIT (license)

Dependencies

meta, sl_websok

More

Packages that depend on sl_adonis_websok