-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from OpenHausIO/dev
v.1.0.0 release
- Loading branch information
Showing
41 changed files
with
5,801 additions
and
1,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
node_modules | ||
npm-debug.log | ||
Dockerfile* | ||
docker-compose* | ||
.dockerignore | ||
.git | ||
.gitignore | ||
README.md | ||
LICENSE | ||
.vscode | ||
docs | ||
tests | ||
.github | ||
demo-database.gz | ||
.env | ||
*.md | ||
*.MD | ||
.env | ||
.eslintrc.json | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,6 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
build | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# https://dev.to/alex_barashkov/using-docker-for-nodejs-in-development-and-production-3cgp | ||
# https://medium.com/@kahana.hagai/docker-compose-with-node-js-and-mongodb-dbdadab5ce0a | ||
|
||
# The instructions for the first stage | ||
FROM node:16-alpine as builder | ||
|
||
ARG NODE_ENV=production | ||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
# fix #233 | ||
RUN mkdir scripts | ||
RUN echo "exit 0" > scripts/post-install.sh | ||
RUN chmod +x scripts/post-install.sh | ||
|
||
RUN apk --no-cache add python3 make g++ | ||
|
||
COPY ./package*.json ./ | ||
RUN npm install | ||
|
||
|
||
# ------------------------------------ | ||
|
||
|
||
# The instructions for second stage | ||
FROM node:16-alpine | ||
|
||
WORKDIR /opt/OpenHaus/connector | ||
COPY --from=builder node_modules node_modules | ||
RUN apk --no-cache add openssl | ||
|
||
ARG version=unknown | ||
LABEL version=$version | ||
|
||
ARG buildDate=unknown | ||
LABEL buildDate=$buildDate | ||
|
||
COPY build ./ | ||
#COPY ./package.json ./ | ||
|
||
#ENV HTTP_PORT=8080 | ||
ENV NODE_ENV=production | ||
#ENV DB_HOST=10.0.0.1 | ||
#EXPOSE 8080 | ||
|
||
CMD ["node", "index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
const cp = require("child_process"); | ||
const pkg = require("./package.json"); | ||
const path = require("path"); | ||
|
||
const PATH_DIST = path.resolve(process.cwd(), "dist"); | ||
const PATH_BUILD = path.resolve(process.cwd(), "build"); | ||
|
||
process.env = Object.assign({ | ||
NODE_ENV: "production" | ||
}, process.env); | ||
|
||
module.exports = (grunt) => { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg, | ||
uglify: { | ||
options: { | ||
mangle: { | ||
toplevel: true | ||
} | ||
}, | ||
build: { | ||
files: [{ | ||
expand: true, | ||
src: [ | ||
"**/*.js", | ||
"!logs/**", | ||
"**/*.gitkeep", | ||
"!Gruntfile.js", | ||
"!node_modules/**", | ||
"!scripts/**", | ||
"!tests/**" | ||
], | ||
dest: PATH_BUILD, | ||
}] | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks("grunt-contrib-uglify"); | ||
|
||
grunt.registerTask("build", () => { | ||
[ | ||
`rm -rf ${path.join(PATH_BUILD, "/*")}`, | ||
`rm -rf ${path.join(PATH_DIST, "/*")}`, | ||
`mkdir -p ${PATH_BUILD}`, | ||
`mkdir ${path.join(PATH_BUILD, "logs")}`, | ||
`mkdir ${path.join(PATH_BUILD, "scripts")}`, | ||
`echo "exit 0" > ${path.join(PATH_BUILD, "scripts/post-install.sh")}`, | ||
`chmod +x ${path.join(PATH_BUILD, "scripts/post-install.sh")}`, | ||
`cp ./package*.json ${PATH_BUILD}`, | ||
"grunt uglify", | ||
].forEach((cmd) => { | ||
cp.execSync(cmd, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
grunt.registerTask("build:docker", () => { | ||
|
||
let buildArgs = [ | ||
`--build-arg version=${pkg.version}`, | ||
`--build-arg buildDate=${Date.now()}`, | ||
].join(" "); | ||
|
||
cp.execSync(`docker build . -t openhaus/${pkg.name}:${pkg.version} ${buildArgs}`, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
|
||
cp.execSync(`docker build . -t openhaus/${pkg.name}:latest ${buildArgs}`, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
|
||
}); | ||
|
||
grunt.registerTask("compress", () => { | ||
cp.execSync(`cd ${PATH_BUILD} && tar -czvf ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}.tgz`)} *`, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
}); | ||
|
||
grunt.registerTask("release", () => { | ||
[ | ||
`mkdir -p ${PATH_BUILD}`, | ||
`mkdir -p ${PATH_DIST}`, | ||
`rm -rf ${PATH_BUILD}/*`, | ||
`rm -rf ${PATH_DIST}/*`, | ||
"npm run build", | ||
"npm run build:docker", | ||
//`pkg build --out-path=${PATH_DIST}`, // -> Fix errors! | ||
`docker save openhaus/${pkg.name}:latest | gzip > ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}-docker.tgz`)}`, | ||
"grunt compress" | ||
].forEach((cmd) => { | ||
cp.execSync(cmd, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
}); | ||
}); | ||
|
||
grunt.registerTask("publish", () => { | ||
[ | ||
`docker push openhaus/${pkg.name}:${pkg.version}`, | ||
`docker push openhaus/${pkg.name}:latest` | ||
].forEach((cmd) => { | ||
cp.execSync(cmd, { | ||
env: process.env, | ||
stdio: "inherit" | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,68 @@ | ||
# Connector | ||
Forwards traffic between the [backend](https://github.com/OpenHausIO/backend) & local network devices over WebSockets. | ||
To controll your devices on your local network, it is necessary to have a piece of software running on your local network. | ||
To control your devices on your local network, it is necessary to have a piece of software running on your local network. | ||
|
||
> NOTE: This application is in a eraly developmen state! | ||
## Environment variables | ||
| Name | Default value | Description | | ||
| ---------------- | ------------- | --------------------------------------------------------------------------- | | ||
| NODE_ENV | `production` | `production` or `development` | | ||
| BACKEND_URL | `` | Full URL to backend. E.g. `http://172.16.0.15:80` | | ||
| BACKEND_PROTOCOL | `http` | Protocol for HTTP/WS requests: `http` or `https` | | ||
| BACKEND_HOST | `127.0.0.1` | Backend IP/Hostname | | ||
| BACKEND_PORT | `8080` | Backend Webserver port | | ||
| TRANSPORT_FILTER | `` | Comma seperated filter list for transport connections. E.g: `tcp`, `udp,ws` | | ||
| Name | Default value | Description | | ||
| ---------------- | ------------------------- | --------------------------------------------------------------------------- | | ||
| NODE_ENV | `production` | `production` or `development` | | ||
| BACKEND_URL | | Full URL to backend. E.g. `http://172.16.0.15:80` | | ||
| BACKEND_PROTOCOL | `http` | Protocol for HTTP/WS requests: `http` or `https` | | ||
| BACKEND_HOST | `127.0.0.1` | Backend IP/Hostname | | ||
| BACKEND_PORT | `8080` | Backend Webserver port | | ||
| RECONNECT_DELAY | `15` | Delay between disconnect & connecting again in Seconds | | ||
| ENABLE_SSDP | `true` | Enable SSDP forwarding (Autodiscover) | | ||
| ALLOW_HALF_OPEN | `false` | Allow half open bridging | | ||
| STARTUP_DELAY | `0` | Delay the startup & first try to establish a ws conneciton with the backend | | ||
| MQTT_HOST | `127.0.0.1` | MQTT Broker host | | ||
| MQTT_PORT | `1883` | MQTT Broker port | | ||
| ENABLE_MQTT | `false` | Enable MQTT forwarding to backend | | ||
| ENABLE_MDNS | `true` | Enable MDNS forwarding (Autodiscover) | | ||
| LOG_PATH | `<cwd>/logs` | Logger destination | | ||
| LOG_LEVEL | `info` | Logger level | | ||
| LOG_DATEFORMAT | `yyyy.mm.dd - HH:MM.ss.l` | Logger date format | | ||
| LOG_SUPPRESS | `false` | Suppress logging | | ||
| LOG_TARGET | `` | Logs only set target, e.g. `forwarder/mdns` | | ||
|
||
## Installation | ||
Download the latest version from the [release page](https://github.com/OpenHausIO/connector/releases).<br /> | ||
Execute the binary or install node.js and run the script as systemd service. | ||
|
||
## Usage of single bridge | ||
### General | ||
```sh | ||
Usage of bridge.js as cli tool: | ||
|
||
bridge.js --upstream="http://example.com" --host="127.0.0.1" --port="8080" | ||
|
||
--upstream WebSocket upstream to backend | ||
--socket Network socket type: tcp|udp|raw | ||
--host Host to connect to | ||
--port Host port to connect to | ||
[--settings] Settings object from interface as json string | ||
[--options] Duplex stream optinos passed to WebSocket.createWebSocketStream | ||
``` | ||
|
||
```sh | ||
./bridge.js --upstream="ws://127.0.0.1:8080/api/devices/<_id>/interfaces/<_id>" --socket="tcp" --host="<host>" --port="<port>" | ||
``` | ||
|
||
### Example | ||
```sh | ||
./bridge.js --upstream="ws://127.0.0.1:8080/api/devices/625c311123ed9311d25efbeb/interfaces/625c311123ed9311d25efbec" --host="licht.lan" --port="443" | ||
./bridge.js --upstream="ws://127.0.0.1:8080/api/devices/625c311123ed9311d25efbeb/interfaces/625c311123ed9311d25efbec" --host="licht.lan" --port="80" | ||
``` | ||
|
||
```sh | ||
./bridge.js --upstream="ws://127.0.0.1:8080/api/devices/625c330e23ed9311d25efbee/interfaces/625c330e23ed9311d25efbef" --host="av-receiver.lan" --port="60128" | ||
``` | ||
|
||
```sh | ||
./bridge.js --upstream="ws://127.0.0.1:8080/api/devices/62a4c005b9e05a649f6cec57/interfaces/62a4c005b9e05a649f6cec58" --host="samsung-tv.lan" --port="8080" | ||
``` | ||
|
||
## Note | ||
This is bascily the same concept as [Websockify](https://github.com/novnc/websockify).<br /> | ||
Forward data between network socket & Websocket. |
Oops, something went wrong.