WebSignals
Dynamically declare and use Client <-> Server communication functionality.
Features:
- Supports both WebSocket and HTTP.
- Can be used in parallel with express.
- Built in keep-alive system.
- Dynamically declarable and callable API logic.
- Can be used with Promises, callbacks or returns.
- Built-in authentication mechanism (debatable in practice).
- Enables parallel messaging.
In-development:
- Automatic reconnection.
- Server-side in NET Standard (incomplete).
Usage (NodeJS)
let http = ;let express = ; let app = ;let server = http; // or aquire server somehow let ws = ; // Attach websignals to a server.let wsi = ws; // Declare an endpoint.wsiDef { // handle query: ; // or return messsage: "BOOP"; // or return { ; };}; // Call an endpoint on client.wsi;
Usage (web)
const wsi = ; wsi; var Def = wsiDef;var Qry = wsiQry; // to forcefully terminate the connection callwsi;
Making API calls
// This is a dynamic query builder.// A query can be constructed from the object that it returns.const Qry = wsiQry; // Server-side:; // Client-side:;
Declaring endpoints
Client-side endpoint handlers accept up to two arguments: _ (args object) and callback. Server-side endpoint handlers accept auth as a second argument and callback as third. The argument auth is used when making server -> client calls.
// Simple client side endpoint.wsiDef { };// Shorthand version when you don't need to specify parameters on the last node.wsiDef { }; // Server sidewsiDef { }; // Endpoint with predefined arguments.wsiDef { var a = _time; var b = _whenIf;} // Echo messages (server) to specific client endpoint.wsiDef { wsi;} // Define a passthrough function.wsiDef { // modify arguments (will be passes on to the handler) _explanationOK = true; // returning anything will be counted as query response // and the call tree will stop here return error: "This explanation won't suffice." ;} // Using the arguments after passthrough.// No need to define the argument "explanation" again, this will have no effect.wsiDef { var isOk = _explanationOK; var info = _info; ;}; // Defining endpoints from Object.wsiDef = node1: '@': '.a' { // handle passthrough } node2: '@': "a" "b" $: { var a = _node1a b = _a c = _b; }