Visitar URL original
GitHub - breqdev/workersocket: Run a WebSocket inside of a Web Worker. · GitHub
Skip to content

About

Run a WebSocket inside of a Web Worker.

Topics

Resources

Code of conduct

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

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!");

About

Run a WebSocket inside of a Web Worker.

Topics

Resources

Code of conduct

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages