![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
socketconnect
Advanced tools
Readme
Incredibly simple and extendable WebSocket wrapper with an HTTP repeat request fallback providing a shared API for sending and receiving data. SocketConnect checks if WebSockets are available to the client, if so they perform as normal, if not it falls back to repeat HTTP requests. You can then compare responses and check for new data.
var SocketConnect = require('socketconnect');
import SocketConnect from 'socketconnect';
var connection = new SocketConnect(websocketURL, httpFallbackURL);
If your websocketURL
works as a HTTP fallback by replacing ws://
with http://
there's no need for the second argument as SocketConnect will perform the replacement. However if that's not the case, the second argument is necessary for the HTTP fallback.
connection.send(data);
connection.handleData = function(e) {
console.log('Data:', e);
};
There are two flags for checking whether your SocketConnect has used websockets or the fallback. Use some logic like below to separate your custom event handling:
if (connection.isWebSocket) {
// Custom WebSocket handling here
} else if (connection.isHTTP) {
// Custom HTTP handling here
}
The below API is split is split into WS/HTTP, make sure you override them within the correct block of the above logic.
You'll want to override the native WebSocket event handlers, you can do this on connection.ws.*event*
, e.g.:
connection.ws.onopen = function() {
console.info('Connected!');
};
The same applies for onerror
, onclose
, however you'll handle onmessage
within the shared API handleData
.
IMPORTANT: You must set connection.canSend = true;
within the onopen
event, this ensures you cannot send messages before the connection is established.
SocketConnect falls back to HTTP repeat requests using XMLHttpRequest
.
The request interval is set to 1000(ms) by default, but you can change that using:
connection.setReqInterval(5000); // 5 Seconds
SocketConnect provides access to all status updates from XMLHttpRequest
. You can add any event handler to them using the below:
// Response code 0
connection.reqNotInit = function() {
console.log('Request not initialised.');
};
Response Code | Meaning | SocketConnect Function |
---|---|---|
0 | Request not initialised | reqNotInit |
1 | Server connection established | connectionEstablished |
2 | Request received | reqReceived |
3 | Processing request | processingReq |
Response code 4 is dealt with within the shared API handleData
.
FAQs
WebSocket wrapper with HTTP repeat request fallback, providing a shared API for sending and receiving data.
The npm package socketconnect receives a total of 0 weekly downloads. As such, socketconnect popularity was classified as not popular.
We found that socketconnect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.