1.1.1 ā€¢ Published 3 years ago

socketit v1.1.1

Weekly downloads
31
License
MIT
Repository
github
Last release
3 years ago

A stream-based WebSocket library.

šŸ  Homepage

Install

yarn add socketit

Usage

Simple server:

const socketit = require("socketit");
const server = new socketit.Server({ port: 8000 });
server.on("connection", (sock) => {
  const socket = new socketit.Socket(sock);
  socket.stream("pos").on("data", (data) => {
    console.log(`x: ${data.x} y: ${data.y}`);
  });
  setTimeout(() => {
    socket.request("position").then((pos) => {
      console.log(`requested position x: ${pos.x} y: ${pos.y}`);
    });
  }, 3000);
});

Simple client:

const socketit = require("socketit");

const ws = new socketit.WebSocket("ws://localhost:8000");
const pos = { x: 0, y: 10 };
ws.on("open", () => {
  const socket = new socketit.Socket(ws);
  socket.handle("position", () => {
    console.log("request for pos");
    return pos;
  });
  setInterval(() => {
    socket.stream("pos").write(pos);
    pos.x += 10;
    pos.y -= 10;
  }, 100);
});

More examples in examples/.

Run tests

yarn test

Browser

You can use socketit in browsers! (With a bundler). Just use the BrowserSocket instead of the Socket.

Documentation

Documentation is available at https://elimerl.github.io/socketit/

Author

šŸ‘¤ elimerl

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

šŸ“ License

Copyright Ā© 2020 elimerl. This project is MIT licensed.

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago