1.0.5 • Published 2 years ago

switchboards_client v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Switchboard.js

A framework for building dynamic and performant web applications on top of the Websocket protocol.

Has a backend server library with an accompanying frontend browser library. This abstracts away a lot of repetitive patterns behind an extremely easy to use interface.

Has Typescript support!

Server

npm i switchboards

Client

npm i switchboards_client

Note: this is highly experimental and should be used with caution

Core Components

Requests

Designed to be very similiar to Express js, but completely implemented in websockets.

Server

import { WS_Handler } from "switchboards";

const app = new WS_Handler(5000);

app.get("root", (args) => {
    return(`Hello ${args["name"]}!`)
})

Client

let client = new WS_Interface("ws://localhost:5000");
await client.initialize()
await client.get("root", {name: "Nathan"})
// Hello Nathan!

Why not just use Express?
I've found that trying to make a hybrid webapp with Express and Websockets gets clumsy, and often I just need basic response endpoints. Websockets are more flexible, with bidirectional communication which can do things like unlimited request times

Pub Sub

A basic pub sub implementation that allows the server to push events to clients.

Client

const sub = await ws_client.subscribe("test_sub");
sub.onMessage((message) => {
    console.log("sub", message);
})

Server

handler.setup_channel("test_sub");
handler.push_subscription("test_sub", "TEST_DATA");
// client logs "TEST_DATA"
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago