Registry / messaging / pomelo-client-websocket

pomelo-client-websocket

JSON →
library1.0.13jsnpmunverified

An improved Pomelo JavaScript client supporting both browser and Node.js environments, with multi-client instance support, reconnection, wss protocol, and custom events for unified handling of server push and response messages. Version 1.0.13 is the latest stable release. Key differentiators from the official client include the ability to create multiple independent Pomelo client instances, support for the 'wss' scheme, reconnection features (since 1.0.5), and special events '__CLIENT_ROUTE' and '__CLIENT_RESPONSE' allowing centralized handling of all server messages. It also handles characters above U+FFFF. The package is published on npm but rarely updated, with no recent releases.

npm install pomelo-client-websocket
INSTALL
IMPORT
SIG · POMELO-CLIENT-WEBS
P
pomelo-client-websocket
messagingjavascriptv1.0.13
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.

Pomelo
const Pomelo = require('pomelo-client-websocket'); const client = new Pomelo();
import Pomelo from 'pomelo-client-websocket';
This package is CommonJS only; ESM import may fail unless using bundler interop.
Pomelo (browser)
const Pomelo = require('pomelo-client-websocket/core'); const client = new Pomelo();
For browser environments, use the core entry point ('pomelo-client-websocket/core') to avoid Node-specific dependencies.
events (connect, __CLIENT_ROUTE, __CLIENT_RESPONSE)
client.on('connect', callback); client.on('__CLIENT_ROUTE', callback); client.on('__CLIENT_RESPONSE', callback);
The 'connect' event is non-standard (added by this library). '__CLIENT_ROUTE' and '__CLIENT_RESPONSE' are custom events for global handling.

Demonstrates creating two Pomelo client instances, connecting to a gate server and then a connector server with wss and reconnection, and using custom events.

const Pomelo = require('pomelo-client-websocket'); const gatePomelo = new Pomelo(); const connectorPomelo = new Pomelo(); gatePomelo.init({ host: '192.168.1.20', port: 3010, scheme: 'ws', log: true }, () => { gatePomelo.request('gate.gateHandler.queryEntry', { uid: 123 }, (data) => { console.log('Gate response:', data); gatePomelo.disconnect(); if (data.code === 500) { console.error('Gate connection failed'); return; } connectorPomelo.init({ host: data.host, port: data.port, scheme: 'wss', reconnect: true, maxReconnectAttempts: 5, reconnectionDelay: 2000 }, () => { console.log('Connector connected'); connectorPomelo.request('connector.entryHandler.login', { username: 'test' }, (res) => { console.log('Login response:', res); }); }); }); }); connectorPomelo.on('__CLIENT_ROUTE', (route, data) => { console.log('Route:', route, 'Data:', data); }); connectorPomelo.on('connect', () => { console.log('Connected to server'); });
Debug
Known issues
gotchaDo not reuse a single client instance for multiple connections; create separate instances for each connection.
fix
Use 'new Pomelo()' for each connection to avoid state conflicts.
affects: >=0.0.0
gotchaThe 'connect' event is a custom addition; the original Pomelo client does not emit such an event.
fix
Listen on 'connect' only if using this library; otherwise use the callback in init().
affects: >=0.0.0
breakingIn browser, you must require 'pomelo-client-websocket/core' instead of the main entry to avoid Node dependencies.
fix
Use 'const Pomelo = require('pomelo-client-websocket/core');' for browser builds.
affects: >=0.0.0
deprecatedThe library uses CommonJS; ES module import may not work without a bundler.
fix
Use 'require()' or ensure bundler handles CJS.
affects: >=0.0.0
gotchaCharacters above U+FFFF are supported but may require proper encoding on the server side.
fix
Ensure server also handles UTF-16 surrogate pairs correctly.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pomelo-client-websocket/core'
Using incorrect path in browser environment when not using a bundler that resolves 'require'.
fix
If using a bundler (webpack), ensure alias or use the main entry; for direct browser use, include the core script via <script> tag (not via require).
TypeError: Pomelo is not a constructor
Using ES module import (import) instead of CommonJS require.
fix
Use 'const Pomelo = require('pomelo-client-websocket');'
Error: WebSocket is not defined
Running in Node.js without the 'ws' dependency installed, or running browser code without bundler handling.
fix
For Node: install 'ws' (though it should be included). For browser: use the core entry or ensure WebSocket global exists.
Uncaught ReferenceError: global is not defined
Using main entry in browser without a bundler (main entry expects Node global).
fix
Use 'pomelo-client-websocket/core' instead.
Upgrade
Version history
1.0.13latest on npm
Audit
Dependencies
wsoptionalUsed for WebSocket client implementation in Node.js environment.
Agent activity
42 hits · last 30 days
node
40
Resources
pomelo-client-websocket — npm install pomelo-client-websocket · libregistry