Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

websocket-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-polyfill

WebSocket class from Browser to NodeJS

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

WebSocket-Polyfill

Deprecated

This package had been developed very long time ago.

It had utilized the websocket library, but the polyfill could be just done by only one line with ws library. In such reason, websocket-polyfill no more keeps long line of codes, but just have only one line like below.

I think instead of importing this websocket-polyfill library, it would better to write the one line code by yourself.

import import2 from "import2"; // JUST TO AVOID TRANSPILING
import { is_node } from "tstl"; // YOU CAN REPLACE IT LIKE BELOW

// let is_node_: boolean | null = null;
// const is_node = (): boolean =>
//   (is_node_ ??=
//     typeof global === "object" &&
//     typeof global.process === "object" &&
//     typeof global.process.versions === "object" &&
//     typeof global.process.versions.node !== "undefined");

if (is_node()) (global as any).WebSocket ??= import2("ws");

Outline

WebSocket class for NodeJS.

Installation

NPM Module

npm install --save websocket-polyfill

Usage

import "websocket-polyfill";

const main = (): void => {
  const ws: WebSocket = new WebSocket("ws://127.0.0.1:38000/main");
  ws.onmessage = (msg: MessageEvent) => {
    console.log("Data from ws-server", msg.data);
  };
}
main();

Keywords

FAQs

Package last updated on 24 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc