stream2app v1.0.0
stream2app - server
:checkered_flag: Português (Portuguese)
Framework to build servers for Flutter Apps that allows you to:
:handshake: perform a websocket connection to exchange data that:
:vibration_mode: supports streams on the client side in Flutter
:arrow_right_hook: perform the resending of data in case of instability of the client connection
:pencil2: create your own CRUD operations (Create, Read, Update and Delete)
:no_entry: restrict client access to CRUD operations
:mega: notify in real time clients who are listening for changes in a route, you can choose to notify:
- :no_pedestrians: only specify clients will receive the data
:heavy_check_mark: all clients will receive the data
:lock: accept and deny connection attempts
This is the server side (Node.js), click here to access the client side (Flutter).
Important links
- Server documentation: Regarding to the server in Node.js.
- Getting Started (client): Regarding to the client in Flutter.
- chat (example): Chat between the colors blue and green.
- catalog (example): Users adding and removing products from a catalog.
Getting Started
1 - Install
npm install --save stream2app
2 - Import the package
import {Stream2App} from "stream2app";
3 - Create and init the server
const server = new Stream2App();
server.init({
projectName: 'tracking',
wsOptions : {
port : 3123
}
});
4 - Set the routes
where the client will
listen realtime data.
The example data that the client will listen is trackingStatus
.
let trackingStatus = '';
server.addReadRoute<string>({
route: 'product/tracking',
read: async (context) => {
return new RespondSuccess({
output: trackingStatus
});
},
});
5 - Set the routes
where the client will
create, remove and update data.
Call server.notifyClients(...)
when the data changes.
let customerSaidCounter = 0;
server.addCreateRoute<string>({
route: 'product/customerSaid',
create: (async (context) => {
customerSaidCounter++;
trackingStatus = 'Customer said: "'+context.body + '" '+ (customerSaidCounter) + " times";
server.notifyClients('product/tracking', {
output: trackingStatus
});
return new RespondSuccess();
}),
});
6 - Start the server
server.start();
7 - Simulating changes of trackingStatus
in the server
let kmRemaining = 101;
const kmRemainingTask = setInterval(() => {
if(kmRemaining == 0){
return clearInterval(kmRemainingTask);
}
kmRemaining--;
trackingStatus = 'Product is '+kmRemaining+' km from you';
server.notifyClients('product/tracking', {
output: trackingStatus
});
}, 3 * 1000);
8 - Check what's your IPV4 address in the machine that your server is running. It will be something like:
192.168.X.X
9 - Configure the client side (Flutter).
Issues
Feel free to open a issue about:
:grey_question: questions
:bulb: suggestions
:page_facing_up: documentation improvements
:ant: potential bugs