Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 768 Bytes

README.md

File metadata and controls

38 lines (26 loc) · 768 Bytes

wsRPC

A JavaScript library that allows servers to communicate via WebSockets

Usage

You can start a wsRPC server with some services:

// Service 1
import { initializeServer } from "https://deno.land/x/[email protected]/mod.ts";

function helloService(clientName: string) {
  console.log(`${clientName} says hello!`);
}

const services = new Map();

services.set("hello", helloService);

initializeServer({
  port: 3000,
  services,
});

And initialize a client on another service and call the hello method:

import { initializeClient } from "https://deno.land/x/[email protected]/mod.ts";

const service1 = await initializeClient({
  host: "ws://localhost:3000",
});

const helloResponse = await service1.hello("service-2");
console.log(helloResponse);