Socket.io client with offline queue
Install using npm:
npm install queued-socket.io
const socket = require('queued-socket.io');
// Before there is a socket connection, add events. These will be queued and run after the connection is established.
socket.on('ping', () => console.log('ping'));
socket.on('disconnect', () => console.log('disconnected'));
socket.once('ping', () => console.log('One time ping'));
socket.emit('authentication', { token: 'loginToken' }, 1);
const options = {
path: '/socket',
transports: ['websocket']
};
const client = socket.connect('http://localhost:5000', options);
console.log(`Socket is ${socket.isConnected() ? 'connected' : 'disconnected'}`);
Socket module
Retrieve the client
Kind: inner method of socket
Returns: socket.io client
Access: public
Check if the socket is connected
Kind: inner method of socket
Returns: Boolean
- socket connection status
Access: public
Send an event to the socket, when the socket is not connected, add an emit event to the queue.
Kind: inner method of socket
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
data | Object |
The data to send to the socket when the event is triggered. | |
priority | Number |
2 |
The priority of the event. |
Wrapper around socket.on that adds priority and caching
Kind: inner method of socket
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
callback | function |
The callback function that the sockets call when the event is triggered. | |
priority | Number |
2 |
The priority of the event. |
Wrapper around socket.off that adds priority and caching
Kind: inner method of socket
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
priority | Number |
2 |
The priority of the event. |
Wrapper around socket.once that adds priority and caching
Kind: inner method of socket
Returns: socket.io client
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
callback | function |
The callback function that the sockets call when the event is triggered. | |
priority | Number |
2 |
The priority of the event. |
Connect to socket.io, if socket is already connected, returns that socket.
Kind: inner method of socket
Returns: socket.io client
Access: public
Param | Type | Description |
---|---|---|
uri | String |
The connection uri of the host. |
options | Object |
Options object used by socket.io. |
Events module
Adds a socket event to the socket, when the socket is not connected, add the add event to the queue.
Kind: inner method of events
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
callback | function |
The callback function that the sockets call when the event is triggered. | |
priority | Number |
2 |
The priority of the event. |
Adds a single run socket event to the socket, when the socket is not connected, add the once event to the queue.
Kind: inner method of events
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
callback | function |
The callback function that the sockets call when the event is triggered. | |
priority | Number |
2 |
The priority of the event. |
Remove all socket events from the socket, when the socket is not connected, add the clear event to the queue.
Kind: inner method of events
Access: public
Param | Type | Default | Description |
---|---|---|---|
priority | Number |
2 |
The priority of the event. |
Retrieve all registered events
Kind: inner method of events
Returns: Array.<Object>
- Registered events
Access: public
Remove a socket event from the socket, when the socket is not connected, add a remove event to the queue.
Kind: inner method of events
Access: public
Param | Type | Default | Description |
---|---|---|---|
event | String |
The event name that needs to be added to the socket. | |
priority | Number |
2 |
The priority of the event. |
queued-socket.io makes use of debug. To see the output in the console run this in the console:
localStorage.debug = 'queued-socket.io*';
Please submit all issues and pull requests to the anchorchat/queued-socket.io repository!
Run tests using npm test
.
Make sure your working directory is clean!
git checkout master && git fetch && git merge origin/master
npm run prepare
npm version <patch|minor|major> -m '<commit message containing changes for this release>'
git push origin master
git push --tags
npm publish
If you have any problem or suggestion please open an issue here.