@async-util/websocket
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@async-util/websocket

A super lightweight lib to get websocket events in async style.

Read data from websocket.

import { getWsData } from '@async-util/websocket';

(async function () {
  const ws = new WebSocket('wss://gateway.discord.gg/?v=9&encoding=json');
  setTimeout(() => ws.send('{"op":1,"d":6}'), 1000);
  setTimeout(() => ws.close(), 5000);

  for await (const data of getWsData(ws)) {
    console.log(data);
  }

  console.log('socket closed.');
})(console.error);

Readme

Keywords

Package Sidebar

Install

npm i @async-util/websocket

Weekly Downloads

3

Version

0.2.0

License

Apache-2.0

Unpacked Size

13.4 kB

Total Files

5

Last publish

Collaborators

  • talrasha007