Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dogmatic69/socket-api-server
API server over web sockets that will push data to the client
https://github.com/dogmatic69/socket-api-server
api-server home-automation nodejs socket-io wrapper-api
Last synced: 12 days ago
JSON representation
API server over web sockets that will push data to the client
- Host: GitHub
- URL: https://github.com/dogmatic69/socket-api-server
- Owner: dogmatic69
- Created: 2017-04-26T22:34:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T11:58:37.000Z (11 months ago)
- Last Synced: 2024-10-11T07:45:53.641Z (about 1 month ago)
- Topics: api-server, home-automation, nodejs, socket-io, wrapper-api
- Language: JavaScript
- Homepage: http://dogmatic69.com
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Socket API Server [WIP]
I built this because I needed an easy way to unify lots of different API's into a single API for my home automation project.
Home automation generally contains multiple diffenret data streams that can be fed to multiple different locations. The other hard requirement is that it needs to be instant. For this reason sockets are used so that data can be pushed to clients.
To make it DRY and maintainable I built this pluggable API server that I can pass modules to with a set signature that would deal with generating the data. The server deals with triggering the services at appropriate times based on config similar to a cronjob and uses sockets to push the data to a client where required.
```
DATA INPUT ABSTRACTION DATA OUTPUT
|---- Website
Open Weather ------| |
| |---- Push notifications
Website Scraper ---| |
|-- <=> Socket API Server <=> cache <=> --|---- TV on screen notification
Amazon Alexa ------| |
| |---- Magic mirror
Any other service -| |
|---- any other output```
Example Usage:```
'use strict';const SocketApi = require('socket-api-server');
SocketApi.server.addConnector(
'hello-world', // unique name for the connector
taskConfig, // config the task
(createTask, emitter) => createTask('hello.world', (task) => {
// this callback is run by the API tasker per the configuration provided.
return new Promise((resolve, reject) => {
if (task.initial) {
console.log("Seding initial data: ", data);
}
return emitter(task.name, data);
});
})
);
````addConnector` basically registers the provided callback and runs it periodically based on the specified `taskConfig`. Within the callback you would include any other libs and do API requests to get the data that is needed. It's up to the callback to run the emit any data that should be sent.
The `task` passed in is the object describing the current task
The `emitter` passed to the connector callback is a pre-configured wrapper to `socket-io.volatile.emit()`