Overview
Connexa is a library which aims to create an abstraction to the WebSockets layer in order to simplify the usage for the Dart developers. The Connexa usage is much similar and protocol compatible with Socket.IO.
How to use
Installing
First, add the library to the list of dependencies in your pubspec.yaml file:
dependencies:
connexa: any
Create a simple server
server.dart
import 'package:connexa/connexa.dart';
main() {
Connexa.listen().then((Server server) {
server.on('connection', (Socket socket) {
socket.emit('news', {'title': 'Hello!'});
socket.on('my_event', (data) {
print(data);
});
});
});
}
client.dart
import 'package:connexa/connexa.dart';
main() {
Connexa connexa = new Connexa('ws://localhost:8080');
socket.on('news', (data) {
print(data);
socket.emit('my_event', {'some': 'data'});
});
}
Sending and receiving events
Connexa allows you to emit and receive custom events. Besides connect
, message
, disconnect
, you can emit custom events:
Server
// note, listen(<options>) will create a http server for you
// if you want serve in IPv6 please use listenV6(<options>) instead
Server server = await Connexa.listen();
server.on('connection', (socket) {
server.emit('this', { 'will': 'be received by everyone' });
socket.on('private_message', (from, msg) {
print('I received a private message by ' + from + ' saying ' + msg);
});
socket.on('disconnect', (_) {
server.emit('user disconnected');
});
});
Contributing
Connexa still at the early stage of development and all contribution are more than welcome. Fork Connexa on GitHub, make it awesome and send a pull request when it is ready.
Please note that one of the Connexa's design goals is to use as many Dart idioms as possible while retaining the Socket.IO compatibility.
Features and bugs
Please file feature requests and bugs at the issue tracker.