workersocket
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

workersocket

A WebSocket that runs in a Web Worker.

Published as an ES module only.

Node.js

Web Workers are not available in Node.js. As a fallback, this module will return a ws object. This is intended to support both dual browser/node libraries and browser libraries that run unit tests in Node.

Deps

  • ws to support use with Node. Adds nothing to a browser bundle.

Example

This library strives to be as similar to the WebSocket API as possible.

import { WorkerSocket } from "workersocket";

const socket = new WorkerSocket("ws://echo.websocket.events");

socket.onmessage = (event) => {
  console.log(event.data);
  socket.close();
};

socket.send("Hello, world!");

/workersocket/

    Package Sidebar

    Install

    npm i workersocket

    Weekly Downloads

    113

    Version

    0.2.3

    License

    MIT

    Unpacked Size

    8.32 kB

    Total Files

    6

    Last publish

    Collaborators

    • breq