Pollsockets is a simple, yet powerful, server-client communication library. It is designed to be used in situations where you need to send data from the server to the client. It is a great alternative to websockets, as it is much simpler to implement and use.
Pollsockets uses a simple polling mechanism to send events from the server to the client. Instead of polling an endpoint that returns data, pollsockets polls an endpoint that returns a list of events that have occurred, thus saving bandwidth and response time. The client then processes the events and updates the UI accordingly.
You can install the package via npm:
npm i pollsockets-js
import {useSocket} from "pollsockets-js"
// Channel name can be any string. Can be used to separate events from different sources.
let channelName = 'channel';
// Event name can be any string. Can be used to separate events of the same type.
let event = 'reload';
// Subscribe to an event from anywhere in your code. Perfect for updating the UI when something happens.
useSocket(channelName, {
event: () => doSomething()
}, {
pollInterval: 1000,
})
You can stop polling by calling stopSockets()
.
import {stopSockets} from "pollsockets-js"
stopSockets()
Please see CHANGELOG for more information on what has changed recently.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.