Registry / communication / jquery-simple-websocket

jquery-simple-websocket

JSON →
library1.1.4jsnpmunverified

jQuery Simple WebSocket (v1.1.4) is a browser-only jQuery plugin that extends $.simpleWebSocket with a fluent, deferred interface for WebSocket communication. It supports reconnection, configurable timeouts and attempts, and JSON/XML/text data types. The plugin is no longer actively maintained; the last release was in 2017. Key differentiators: built on jQuery, uses Promises (done/fail) for send, and supports multiple listeners. Alternatives include native WebSocket or modern libraries like Socket.IO.

npm install jquery-simple-websocket
INSTALL
IMPORT
SIG · JQUERY-SIMPLE-WEBS
J
jquery-simple-websocket
communicationjavascriptv1.1.4
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.

$.simpleWebSocket
var socket = $.simpleWebSocket({url: 'ws://...'});
const socket = simpleWebSocket({url: 'ws://...'});
Must be called on the jQuery global ($). Works only in browser with jQuery loaded.
socket.listen
socket.listen(function(msg) { console.log(msg.text); });
socket.on('message', function(msg) {});
Uses custom listen method, not native WebSocket onmessage.
socket.send
socket.send({foo: 'bar'}).done(function() {}).fail(function() {});
socket.send(JSON.stringify({foo: 'bar'}));
Automatically serializes data based on dataType option; returns a deferred object.
socket.connect
socket.connect();
socket.open();
Explicitly initiates connection; not called automatically.

Basic usage showing how to create a WebSocket connection, listen for messages, and send data with deferred callbacks.

<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.2.0.min.js"></script> <script src="jquery.simple.websocket.js"></script> </head> <body> <script> var wsUrl = 'ws://127.0.0.1:3000/'; var socket = $.simpleWebSocket({ url: wsUrl }); socket.listen(function(message) { console.log('Received:', message.text); }); socket.send({ 'text': 'hello' }).done(function() { console.log('Message sent'); }).fail(function(e) { console.error('Send failed', e); }); </script> </body> </html>
Debug
Known issues
deprecatedjQuery Simple WebSocket is no longer actively maintained and may have compatibility issues with modern jQuery versions or browser APIs.
fix
Consider using native WebSocket API or a maintained library like Socket.IO or ws (Node.js).
affects: all
gotchaThe plugin expects jQuery in the global scope. Using module bundlers (Webpack, Rollup) require explicit exposure via window.jQuery.
fix
Before loading the plugin, ensure jQuery is on window: import $ from 'jquery'; window.jQuery = $;
affects: all
gotchasend() automatically serializes JavaScript objects based on the dataType option (default 'json'). Sending non-serializable values may cause errors.
fix
Ensure data is serializable. If dataType is 'text', send strings only.
affects: all
gotchaThe plugin's deferred interface uses done/fail but does not support modern Promise async/await directly.
fix
Wrap calls in new Promise((resolve, reject) => socket.send(data).done(resolve).fail(reject)) to enable async/await.
affects: all
gotchaurl must be a ws:// or wss:// URI. Relative paths may not work as expected.
fix
Always provide an absolute WebSocket URL.
affects: all
Errors
Common errors & fixes
$.simpleWebSocket is not a function
jQuery not loaded before plugin, or variable $ is not defined.
fix
Ensure jQuery is loaded before the plugin script. Verify no other library overrides $.
Cannot read property 'text' of undefined
The message object may not have a 'text' property if dataType is not 'json' or the server sends different structure.
fix
Check the server's response format. Log the full message object using console.log(message).
Uncaught TypeError: socket.send(...).done is not a function
Using native WebSocket API instead of plugin; send() returns undefined for native WebSocket.
fix
Use $.simpleWebSocket to create the socket object, not new WebSocket().
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
jqueryrequiredThe plugin extends jQuery ($) and requires it to be loaded before usage.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
jquery-simple-websocket — npm install jquery-simple-websocket · libregistry