2.0.0-package-json-version-import.1629635719447 • Published 5 years ago

@effection/websocket-client v2.0.0-package-json-version-import.1629635719447

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

@effection/websocket-client

A basic websocket client for sending and receiving messages over a websocket connection. Works both in the browser and in node. The client is oppinionated in that it assumes that the messages are serialized as JSON.

Usage

import { createWebSocketClient, WebSocketClient } from '@effection/websocket-client';
import { main } from '@effection/main';

type Request = { value: string };
type Response = { value: number };

main(function* () {
  let client: WebSocketClient<Request, Response> = yield createWebSocketClient('ws://localhost:1234');

  yield client.forEach(({ value }) {
    client.send({ value: parseInt(value) });
  });
});