To get setup, clone this repository and npm install
.
Run a server locally using node server.js
.
Now, you'll need a client connection using socket.io.
For example:
const socket = io("https://mocksock.herokuapp.com") // http://localhost:8080
socket.on("templateList", console.log)
socket.on("deviceConnected", data => {
doSomethingWithThis(data) // make magic happen
})
You can write your own templates and export them in templates/index.js
. I've included one sample template called deviceConnected
. It can be used like so:
const options = {
template: "deviceConnected",
frequency: {
leaseMinutes: 2,
mean: 1,
dev: 0.3
}
}
socket.emit("openStream", options)
The server will broadcast to your connection for the data generated by the deviceConnected
template for two minutes, with a normally distributed frequency with mean 1 (second) and stddev of 0.3 (seconds).
One more example:
const options = {
template: "deviceConnected",
frequency: {
leaseMinutes: 10,
type: "static",
intervalSeconds: 20
}
}
socket.emit("openStream", options)
ie. Broadcast data every 20 seconds for 10 minutes.
I've included chance.js because I like it, faker.js is also an option, or this could be extended to support custom templates via an http server and a POST request or similar socket communication.