1.0.5 • Published 12 months ago

modern-isomorphic-ws v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

modern-isomorphic-ws

MIT License Types Version Package size

Isomorphic WebSocket client implementation inspired by the heinisuo/isomorphic-ws package.

It uses ws on Node and native WebSocket in browsers.

Limitations

Before using this module, you should be aware that ws is not fully compatible with the WebSocket API. It may not match the implementation in the browser, or it may introduce its own methods (for example, ping and pong, which are not in the browser version). You should always test your code in both Node and browsers for better compatibility and security.

Difference from original isomorphic-ws

  • There is support for ES modules
  • Uses a shorter WebSocket export syntax in the browser, due to almost 100% support for 2022 (for comparison, export in the isomorphic-ws)

Usage

You need to install both this package and ws:

npm i modern-isomorphic-ws ws

If you are using TypeScript, also set the type declarations:

npm i @types/ws -D

Now just import this package:

import WebSocket from "modern-isomorphic-ws";

// And write your code ;)