2.0.0-side-effects.1628154559925 • Published 5 years ago

@effection/websocket-server v2.0.0-side-effects.1628154559925

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@effection/websocket-server

A basic websocket server which binds to a local port and enables communication over websockets. The server is opinionated in that it assumes that the messages are serialized as JSON.

Usage

import { createWebSocketServer, WebSocketServer } from '@effection/websocket-server';
import { main } from '@effection/main';

type Message = { value: string };

main(function*() {
  let server: WebSocketServer<Message> = yield createWebSocketServer(47000);

  yield spawn(server.forEach(function*(connection) {
    yield connection.forEach(({ value }) => {
      connection.send({ value: value.toUpperCase() });
    });
  }));
});