keiser_metrics_connection 0.7.3 copy "keiser_metrics_connection: ^0.7.3" to clipboard
keiser_metrics_connection: ^0.7.3 copied to clipboard

Dart package for Keiser Metrics to handle both websockets and rest calls.

example/main.dart

import 'package:keiser_metrics_connection/keiser_metrics_connection.dart';

bool _isAuthenticated = false;
bool _isConnected = false;
bool _isServerOnline = false;

void main() {
  final connection = MetricsConnection(
    restEndpoint: 'http://192.168.208.191:8080/api',
    socketEndpoint: 'ws://192.168.208.191:8080/ws',
    requestRetryLimit: 1,
    socketTimeout: Duration(seconds: 5),
  );

  connection.onServerStatusChange.listen((event) {
    _isServerOnline = event == ServerState.online;
    _printStatus();
  });
  connection.onConnectionStatusChange.listen((event) {
    _isConnected = event == ConnectionState.connected;
    _printStatus();
  });
  connection.onAuthenticationStatusChange.listen((event) {
    _isAuthenticated = event == AuthenticationState.authenticated;
    _printStatus();
  });

  connection.open();
}

void _printStatus() {
  print(_StatusEvent(
    isAuthenticated: _isAuthenticated,
    isConnected: _isConnected,
    isOnline: _isServerOnline,
  ));
}

class _StatusEvent {
  _StatusEvent({
    required this.isAuthenticated,
    required this.isConnected,
    required this.isOnline,
  });

  final bool isAuthenticated;
  final bool isConnected;
  final bool isOnline;

  @override
  String toString() =>
      '_StatusEvent(isAuthenticated: $isAuthenticated, isConnected: $isConnected, isOnline: $isOnline)';
}
1
likes
130
points
314
downloads

Publisher

verified publisherdev.keiser.com

Weekly Downloads

Dart package for Keiser Metrics to handle both websockets and rest calls.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dio, enum_to_string, jwt_decoder, retry, web_socket_channel

More

Packages that depend on keiser_metrics_connection