Signals is an event-emitter-like library meant to be used across different node projects without setting up a websocket or a server, with the use of Firebase and soon can also be used with MongoDB
Documentation
Hello this is the documentation
Installation
Simply just run:
$npmisignalz
Importing
// Using Node.js `require()`constSignalz=require("signalz");// Using ES6 importsimportSignalzfrom"signalz";
Firebase
Heres how to setup Signalz with the firebase method
Getting Started
First import firebase-admin and initialize firebase, this is explained further here
Then initialize Signals itself:
Client ID is explained here
Sending a Signal
Signal ID and Target Client ID are exmplaned here
Receiving a Signal
Replying to Signal
After doing the code when receiving a signal, its a good practice to reply to that signal with a status of "accept" or "error" to make the other project know the status of the signal, optionally, you can add a message to the reply
Awaiting a Reply
Ending a Signal
Its important that you end a signal after you are done with it, it is optional but very recommended as it frees up space from your database.
OR
Explaining Some Terms
Term
Meaning
CLIENT_ID
This is used so signals can be targetted to only the project(s) with that client id
TARGET_CLIENT_ID
You set this in the signal so the signal only goes to the projects with that client id
SIGNAL_ID
This is a custom id that is passed when sending the the signal so the receiving end knows which type of signal its receiving
const client = new Signalz.Client("CLIENT_ID", firebase.database());
await client.sendSignal("SIGNAL_ID", "TARGET_CLIENT_ID", data);
// Data can be a number, string, boolean, or object.
client.on("signal", (signal) => {
// do stuff
});
client.on("signal", (signal) => {
// do stuff
signal.reply("accept", "good!");
// OR
signal.reply("error", "invalid yada yada");
// Message can be number, string, boolean, or object.
});