Skip to main content

websocket_ping_validator 1.0.5 copy "websocket_ping_validator: ^1.0.5" to clipboard
websocket_ping_validator: ^1.0.5 copied to clipboard

outdated

A dart package to use websockets and check the connection

sql_data_helper #

pub package

A dart package to use websockets and check the connection.

Getting Started #

Installing #

In your Flutter project, add the package to your dependencies

flutter pub add websocket_ping_validator

or

dependencies:
  ...
  websocket_ping_validator: #last_version
  ...

Usage Example #

void main() async {
  ///Type: String
  ///YOUR WEBSOCKET URL
  const url = "ws...";

  ///Type: bool
  ///VARIABLE SPECIFICITIES IF YOU WANT TO RECONNECT WHEN A ERROR HAVE OCCURRED
  const reconnectOnError = true;

  ///Type: dynamic (NOT NULL)
  ///IS THE DATA SENT TO SERVER TO MAKE A PING
  final dataToSendAsPing = Uint8List.fromList([0]);

  ///Type: int
  ///IS THE MAX COUNT OF ATTEMPTS TO MAKE A PING
  const maxAttempts = 5;

  ///Type: Duration
  ///IS DURATION OF TIME TO MAKE A PING
  const periodicDurationToPing = Duration(seconds: 3);

  ///Type: Duration
  ///IS DURATION OF TIME TO RECONNECT THE WEBSOCKET
  const reconnectIn = Duration(seconds: 3);

  ///Type: bool (or a function with bool value)
  ///IS A CUSTOM VALIDATION TO CONNECT THE WEBSOCKET
  bool validateIfCanMakeConnection() {
    return true;
  }

  await WebsocketPingValidator.connectWebSocket(url,
      onMessage: (message) async {
        ///MESSAGE RECEIVED FROM SERVER
      }, onConnected: (dateTimeConnected) async {
        ///WEBSOCKET CONNECTED (YOU RECEIVE THE SPECIFIC DateTime WHEN THE CONNECTION OCCURRED)
      }, onConnectionClosed: (statusCode) async {
        ///WEBSOCKET DISCONNECTED (YOU RECEIVE THE SPECIFIC StatusCode IN int WHEN THE DISCONNECTION OCCURRED)
      }, onConnectionLost: () async {
        ///WEBSOCKET HAVE LOST THEIR CONNECTION
      }, onError: (error) async {
        ///WEBSOCKET HAVE OCCURRED AN ERROR (YOU RECEIVED IT)
      }, onReconnectStarted: (duration) async {
        ///FUNCTION BEFORE START RECONNECTION COUNT DOWN
      },
      maxAttempts: maxAttempts,
      periodicDurationToPing: periodicDurationToPing,
      reconnectIn: reconnectIn,
      reconnectOnError: reconnectOnError,
      dataToSendAsPing: dataToSendAsPing,
      validateIfCanMakeConnection: validateIfCanMakeConnection());
}
1
likes
0
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

A dart package to use websockets and check the connection

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on websocket_ping_validator