ispectify_ws 5.0.0-dev43 copy "ispectify_ws: ^5.0.0-dev43" to clipboard
ispectify_ws: ^5.0.0-dev43 copied to clipboard

WebSocket diagnostics for ISpect with connection lifecycle, sent and received frame logging, grouping, and redaction.

example/main.dart

import 'dart:async';
import 'dart:io' as io show exit;
import 'package:ispectify/ispectify.dart';
import 'package:ispectify_ws/ispectify_ws.dart';
import 'package:ws/ws.dart';

void main([List<String>? args]) {
  // Using a non-existent WebSocket URL to trigger a connection error.
  const url = String.fromEnvironment(
    'URL',
    defaultValue: 'wss://echo.plugfox.dev:443/non-existent-path',
  );
  final logger = ISpectLogger();

  final interceptor = ISpectWSInterceptor(logger: logger);

  final client = WebSocketClient(
    WebSocketOptions.common(
      connectionRetryInterval: (
        min: const Duration(milliseconds: 500),
        max: const Duration(seconds: 15),
      ),
      interceptors: [interceptor],
    ),
  );

  interceptor.setClient(client);

  client
    ..connect(url)
    ..add('Hello')
    ..add('world!');

  // Adding a client-side error by trying to send data after closing the connection.
  Timer(const Duration(seconds: 1), () async {
    await client.close();
    try {
      unawaited(client.add('This will fail'));
    } catch (e) {
      // This error will be caught by the interceptor.
    }
    // ignore: avoid_print
    print('Metrics:\n${client.metrics}');
    io.exit(0);
  });
}
0
likes
150
points
2.03k
downloads

Documentation

API reference

Publisher

verified publishershodev.live

Weekly Downloads

WebSocket diagnostics for ISpect with connection lifecycle, sent and received frame logging, grouping, and redaction.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

ispectify, ws

More

Packages that depend on ispectify_ws