@xlue/socketio v1.0.1
SocketIO
Again an wrapper made by XJoeyV for the popular package Socket.IO
Getting Started
These instructions will get you started installing and understanding this simple wrapper package.
Prerequisites
- Node Package Manager
Installing
Start with installing the package into your project.
npm install @xlue/socketio --save
And import :)
const { io } = require('@xlue/socketio')(port);
Example
const { io } = require('../index')(8080);
console.log(`[START]`)
io
.onConnect((socket) => console.log(`Socket has been connected ${socket.id}`))
.onDisconnect((socket) => console.log(`Socket has been disconnected ${socket.id}`))
.on('foo', (socket) => {
console.log(`Received Foo`);
});
Documentation
The SocketIO wrapper will export a couple things. These things is the XlueSocket, SocketIO and HTTP. These can be accessed via {io, socketio, http}
Functions
Method onConnect(handle)
Method onDisconnect(handle)
Method onError(handle)
Method on(channel, handle)
Method any(handle)
Packets
By receiving a packet via a middleware we handle it as following: A packet is received as an array and build out of the order of you emit data to the server.
socket.emit(p1, p2, p3);
will be received as an packet created like:
[0] = p1
[1] = p2
[2] = p3
License
This project is licensed under the MIT License - see the LICENSE.md file for details. Some support as in credits or a coffee is appreaciated!
Supporting
Coffee :): https://www.buymeacoffee.com/xjoeyv