Registry / messaging / wshe
library2.2.2jsnpmunverified

A simple yet modern WebSocket client for JavaScript/TypeScript. Current stable version is 2.2.2. It provides a clean API with event-based message handling, automatic reconnection, heartbeat support, and TypeScript generics for strongly-typed messages. Ships with server-side utilities for heartbeat protocol. Released under MIT license. Lightweight alternative to heavier WebSocket libraries.

npm install wshe
INSTALL
IMPORT
SIG · WSHE
W
wshe
messagingjavascriptv2.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createWSHE
import { createWSHE } from 'wshe'
import createWSHE from 'wshe'
This is a named export, not default. Also supports TypeScript generics for message types.
getHeartbeatResponse
import { getHeartbeatResponse } from 'wshe/server'
import { getHeartbeatResponse } from 'wshe'
Server utilities are exported from 'wshe/server', not the main module.
isHeartbeatRequest
import { isHeartbeatRequest } from 'wshe/server'
import { isHeartbeatRequest } from 'wshe'
Same as getHeartbeatResponse, server-only import path.

Creates a WebSocket connection with TypeScript generics, sends typed messages, and subscribes to events with payload typing.

import { createWSHE } from 'wshe' const wshe = createWSHE<{ greeting: { message: string } count: { value: number } }>('wss://echo.example.com/ws', { immediate: true, autoReconnect: true, heartbeat: { interval: 5000, pingMessage: 'ping', pongMessage: 'pong', timeout: 10000 }, onConnected(ws, event) { console.log('connected'); }, }) wshe.subscribe('greeting', (payload) => { console.log(payload.message) }) wshe.subscribe('count', (payload) => { console.log(payload.value) }) wshe.send('greeting', { message: 'hello' }) wshe.sendRaw('raw data') wshe.subscribeRaw(data => { console.log('raw:', data) })
Debug
Known issues
gotchaThe package name 'wshe' may be confused with 'ws' (the popular WebSocket library) during import
fix
Ensure you install 'wshe' specifically, not 'ws'. Check package.json dependencies.
affects: all
gotchaServer utilities (getHeartbeatResponse, isHeartbeatRequest) must be imported from 'wshe/server' not the main module
fix
Use import { ... } from 'wshe/server' for server-side heartbeat helpers.
affects: all
gotchaIf immediate option is false, you must call connect() manually; otherwise no connection is established
fix
Set immediate: true or call wshe.connect() explicitly.
affects: all
Errors
Common errors & fixes
Cannot find module 'wshe/server'
Using a bundler or runtime that does not resolve the subpath export properly
fix
Ensure your environment supports package.json 'exports' field. For older Node.js versions (<12), add 'wshe/server' to the 'paths' in tsconfig or use a polyfill.
TypeError: wshe.subscribe is not a function
Trying to subscribe before the WebSocket is created or using wrong import (e.g., default import instead of named)
fix
Use named import: import { createWSHE } from 'wshe' and call createWSHE to get the instance.
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
31
OpenAI (training)
1
Resources
packagewshe
wshe — npm install wshe · libregistry