@josefransaenz/hypergate-socketio-server
v1.0.4
Published
hypergate-socketio-server is built on top of [Socket.io](https://socket.io) and can be used to create a Socket.io server that act as a gateway for the commands and events directed or generated by the an Hypergate instance.
Downloads
3
Readme
hypergate-socketio-server
hypergate-socketio-server is built on top of Socket.io and can be used to create a Socket.io server that act as a gateway for the commands and events directed or generated by the an Hypergate instance.
API Reference
HypergateSocketioServer
Kind: global class
new HypergateSocketioServer(hypergate, httpServer, options)
An instance of the HypergateAWSMqtt class is a | Socket.io Server instance.
| Param | Type | Description | | --- | --- | --- | | hypergate | object | The instance of the Hypergate class to use | | httpServer | string | the server to bind to. | | options | object | Socket.io options |
Example
const Hypergate = require('@josefransaenz/hypergate-core');
const HgSocketIoServer = require('@josefransaenz/hypergate-socketio-server');
const io = require('socket.io-client');
const httpServer = require('http').createServer();
const port = 3000;
httpServer.listen(port);
const options = { serveClient: false };
const socketServer = new HgSocketIoServer(hypergate, httpServer, options);
const socketClient = io(`http://localhost:${port}`);
socketClient.on('routines/testRoutine/start/done', (payload) => {
console.log('Done: ' + payload)
})
socketClient.on('routines/testRoutine/start/failed', (payload) => {
console.log('Failed: '+payload)
})
socketClient.on('connect', (payload) => {
socketClient.emit('routines/testRoutine/start');
});