A Dart Package Designed to Facilitate Real-time Communication

A dart package designed to facilitate real-time communication between server and client applications using the Server-Sent Events (SSE) protocol. It provides two main components, the BoraPushServer and BoraPushClient, allowing developers to easily implement real-time updates in their Dart-based web applications.

Features:

Server-Sent Events (SSE) Support: The package enables the implementation of server-sent events, allowing servers to push real-time updates to connected clients over a single HTTP connection.

BoraPushServer: The BoraPushServer class provides a server-side implementation for managing connections, maintaining a list of connected clients, and broadcasting updates to all connected clients.

BoraPushClient: The BoraPushClient class is designed for use on the client side, allowing easy connection to a server supporting SSE and handling incoming real-time updates.

Simple API: Developers can create and configure instances of BoraPushServer and BoraPushClient with minimal code, making it straightforward to integrate real-time communication into their applications.

Example Usage:

  • Server-Side (BoraPushServer):

void main() {
  final pushServer = BoraPushServer();
  pushServer.start();
}
  • Client-Side (BoraPushClient):

void main() {
  final pushClient = BoraPushClient.connect(uri: Uri.parse('https://example.com'));
  pushClient.stream.listen((data) {
    // Handle incoming updates
  });
}

Note:

The package assumes a server supporting SSE (e.g., Dart HTTP server with WebSocket support) for optimal functionality.
Developers can customize and extend the provided classes based on their specific real-time communication requirements.

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add ilebora_push

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  ilebora_push: ^0.0.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:ilebora_push/ilebora_push.dart';

example/main.dart

import 'dart:convert';

import 'package:ilebora_push/ilebora_push.dart';

void main() async {
	Uri uri = Uri.parse('https//:...'); //Your events server url
	Map<String, dynamic> params = {}; //...parameters

	BoraPushClient 
		boraPushClient = BoraPushClient.connect(
			uri:  uri.replace(queryParameters: params),
			withCredentials:true,
			closeOnError:true,
		);

	Stream 
		myStream = boraPushClient.stream;
		myStream.listen((value) {
			try{
				//Conert to JSON
				var jsonResp = jsonDecode(value); 
				//Do something with the response

				print(jsonResp);
				
			}catch(e){
				//Do something on erro
			}
		});
}

Download details:

Author: 

Source: https://pub.dev/packages/ilebora_push

#flutter #dart 

A Dart Package Designed to Facilitate Real-time Communication
1.60 GEEK