From 7aa034f3ba89ee2310522393ee4ef884f2cd86d1 Mon Sep 17 00:00:00 2001 From: Craig Date: Sat, 18 Jan 2020 23:30:09 +0000 Subject: [PATCH] large refactor, fixes #2 --- .docker/build | 6 +- .docker/test | 20 +- README.md | 45 +- client/.eslintrc | 1 + client/src/App.vue | 92 +-- neko.code-workspace | 7 +- server/.env.development | 1 + server/.vscode/launch.json | 2 +- server/Makefile | 2 +- server/cmd/neko/main.go | 8 +- server/cmd/root.go | 13 +- server/cmd/serve.go | 10 +- server/go.mod | 3 +- server/go.sum | 43 +- server/internal/config/config.go | 2 +- .../internal/config/{serve.go => server.go} | 22 +- server/internal/config/webrtc.go | 60 ++ server/internal/config/websocket.go | 30 + server/internal/event/events.go | 15 + server/internal/gst/gst.c | 5 +- server/internal/gst/gst.go | 104 ++- server/internal/gst/gst.h | 2 + server/internal/hid/hid.c | 94 +++ server/internal/hid/hid.go | 236 ++++++ server/internal/hid/hid.h | 34 + server/internal/hid/keycode/button.go | 49 ++ server/internal/hid/keycode/keys.go | 701 ++++++++++++++++++ server/internal/http/endpoint/endpoint.go | 144 ++-- server/internal/http/endpoint/error.go | 14 +- server/internal/http/http.go | 87 +++ server/internal/http/middleware/logger.go | 6 +- server/internal/http/middleware/middleware.go | 4 +- server/internal/http/middleware/recover.go | 22 +- server/internal/http/middleware/request.go | 78 +- server/internal/http/response/response.go | 2 +- server/internal/keys/keyboard.go | 203 ----- server/internal/keys/mouse.go | 21 - server/internal/message/messages.go | 15 + server/internal/nanoid/nanoid.go | 71 -- server/internal/preflight/config.go | 4 +- server/internal/preflight/logs.go | 6 +- server/internal/session/manager.go | 172 +++++ .../internal/{webrtc => session}/session.go | 20 +- server/internal/structs/version.go | 21 - server/internal/utils/array.go | 24 + server/internal/utils/header.go | 10 - server/internal/utils/json.go | 10 + server/internal/utils/map.go | 25 - server/internal/webrtc/data.go | 22 - server/internal/webrtc/handle.go | 138 ++++ server/internal/webrtc/logger.go | 32 + server/internal/webrtc/manager.go | 236 ++++-- server/internal/webrtc/messages.go | 15 - server/internal/webrtc/peer.go | 266 ------- server/internal/webrtc/tracks.go | 99 +++ server/internal/webrtc/websocket.go | 228 ------ server/internal/websocket/handler.go | 205 +++++ server/internal/websocket/messages.go | 131 ++++ server/neko.go | 173 ++--- 59 files changed, 2766 insertions(+), 1345 deletions(-) rename server/internal/config/{serve.go => server.go} (66%) create mode 100644 server/internal/config/webrtc.go create mode 100644 server/internal/config/websocket.go create mode 100644 server/internal/event/events.go create mode 100644 server/internal/hid/hid.c create mode 100644 server/internal/hid/hid.go create mode 100644 server/internal/hid/hid.h create mode 100644 server/internal/hid/keycode/button.go create mode 100644 server/internal/hid/keycode/keys.go create mode 100644 server/internal/http/http.go delete mode 100644 server/internal/keys/keyboard.go delete mode 100644 server/internal/keys/mouse.go create mode 100644 server/internal/message/messages.go delete mode 100644 server/internal/nanoid/nanoid.go create mode 100644 server/internal/session/manager.go rename server/internal/{webrtc => session}/session.go (63%) delete mode 100644 server/internal/structs/version.go create mode 100644 server/internal/utils/array.go delete mode 100644 server/internal/utils/header.go create mode 100644 server/internal/utils/json.go delete mode 100644 server/internal/utils/map.go delete mode 100644 server/internal/webrtc/data.go create mode 100644 server/internal/webrtc/handle.go create mode 100644 server/internal/webrtc/logger.go delete mode 100644 server/internal/webrtc/messages.go delete mode 100644 server/internal/webrtc/peer.go create mode 100644 server/internal/webrtc/tracks.go delete mode 100644 server/internal/webrtc/websocket.go create mode 100644 server/internal/websocket/handler.go create mode 100644 server/internal/websocket/messages.go diff --git a/.docker/build b/.docker/build index 737817d5..ebfbe93f 100755 --- a/.docker/build +++ b/.docker/build @@ -9,6 +9,6 @@ npm install && npm run build cd ../ sudo docker build -f Dockerfile -t nurdism/neko . -# sudo docker run -p 8080:8080 --shm-size=2gb nurdism/neko:latest -# sudo docker run --network host --shm-size=2gb nurdism/neko:latest -# sudo docker run --network host --shm-size=2gb -it nurdism/neko:latest /bin/bash \ No newline at end of file +# sudo docker run -p 8080:8080 --shm-size=1gb nurdism/neko:latest +# sudo docker run --network host --shm-size=1gb nurdism/neko:latest +# sudo docker run --network host --shm-size=1gb -it nurdism/neko:latest /bin/bash \ No newline at end of file diff --git a/.docker/test b/.docker/test index 436c50b6..c6e763bf 100755 --- a/.docker/test +++ b/.docker/test @@ -2,6 +2,16 @@ # usefull debugging tools pavucontrol htop x11vnc +# if [ ! -f ../server/bin/neko ]; then +# echo "build server before testing" +# exit 1 +# fi + +# if [ ! -d ../client/dist/ ]; then +# echo "build client before testing" +# exit 1 +# fi + sudo mkdir -p /var/run/dbus /etc/neko sudo /etc/init.d/dbus start @@ -19,16 +29,6 @@ if [ ! -f /usr/lib/firefox-esr/distribution/extensions/uBlock0@raymondhill.net.x sudo curl -o /usr/lib/firefox-esr/distribution/extensions/uBlock0@raymondhill.net.xpi https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/addon-607454-latest.xpi fi -if [ ! -f ../server/bin/neko ]; then - echo "build server before testing" - exit 1 -fi - -if [ ! -d ../client/dist/ ]; then - echo "build client before testing" - exit 1 -fi - sudo cp ../server/bin/neko /usr/bin/neko sudo cp -R ../client/dist /var/www/ diff --git a/README.md b/README.md index 2c841af7..1a1ef562 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ -# n.eko +# **n**.eko This is a proof of concept project I threw together over the last few days, it's ugly, it's not perfect, but it looks nice. This uses web rtc to stream a desktop inside of a docker container, I made this because [rabb.it](https://en.wikipedia.org/wiki/Rabb.it) went under and my internet can't handle streaming and discord keeps crashing. I just want to watch anime with my friends ლ(ಠ益ಠლ) so I started digging throughout the net and found a few *kinda* clones, but non of them had the virtual browser, then I found [Turtus](https://github.com/Khauri/Turtus) and I was able to figure out the rest. This is by no means a fully featured clone of rabbit. The client has no concept of other peers. It has bugs, but for the most part it works. I'm not sure what the future holds for this. If I continue to use it and like it, I'll probably keep pushing updates to it. I'd be happy to accept PRs for any improvements. @@ -15,15 +15,23 @@ This is by no means a fully featured clone of rabbit. The client has no concept I like cats (Neko is the Japanese word for cat), I'm a weeb/nerd, I own the domain [n.eko.moe](https://n.eko.moe/) and I love the logo /shrug ### Super easy mode setup -1. Head on to [Digital Ocean](https://digitalocean.com/) and create an account -2. Go [here](https://marketplace.digitalocean.com/apps/docker) and click on "Create Docker Droplet" -3. Configure the droplet: - * **576p** [$15/mo] Not Recommended - * **720p** [$40/mo] Good Performance - * **720p** [$80/mo] Recommended - * **720p+** [$160/mo] Best Performance -4. [Login to the droplet over ssh](https://www.digitalocean.com/docs/droplets/how-to/connect-with-ssh/) -5. Run these commands: +1. Deploy a server + + *Recomended specs:* + | Resolution | Cores | Ram | Recommendation | + |------------|-------|-----|------------------| + | **576p** | 2 | 2gb | Not Recommended | + | **720p** | 4 | 4gb | Good Performance | + | **720p** | 6 | 6gb | Recommended | + | **720p+** | 8 | 8gb | Best Performance | + +2. [SSH into your VPS](https://www.digitalocean.com/docs/droplets/how-to/connect-with-ssh/) + +3. Install Docker + ``` + curl -sSL https://get.docker.com/ | CHANNEL=stable bash + ``` +4. Run these commands: ``` ufw allow 80/tcp wget https://raw.githubusercontent.com/nurdism/neko/master/docker-compose.yaml @@ -33,14 +41,12 @@ I like cats (Neko is the Japanese word for cat), I'm a weeb/nerd, I own the doma > *Protip*: Run `nano docker-compose.yaml` to edit the settings, then press *ctrl+x* to exit and save the file. -Heres the cool part, this will only cost you a little bit (maybe a few cents), *as long as you remember to delete the droplet after you are done!* Droplets are charged per hour, so when you want to share, just create a new droplet and start sharing. - ### Running the container: ``` -sudo docker run -p 8080:8080 -e NEKO_PASSWORD='secret' --shm-size=2gb nurdism/neko:latest +sudo docker run -p 8080:8080 -e NEKO_PASSWORD='secret' --shm-size=1gb nurdism/neko:latest ``` -*Note:* `--shm-size=2gb` is required, firefox-esr tabs will crash (not sure if 2gb is *really* needed) +*Note:* `--shm-size=1gb` is required, firefox-esr tabs will crash ### Config ``` @@ -57,14 +63,3 @@ NEKO_CERT= // (SSL)Cert ### Development *Highly* recommend you use a [dev container](https://code.visualstudio.com/docs/remote/containers) for [vscode](https://code.visualstudio.com/), I've included the `.devcontainer` I've used to develop this app. To build neko run: `cd .docker && ./build` - -### Goals -* Remove need for gstreamer, handle encoding/capturing with go -* Make firefox work with client (wrtc issues) -* Remove the need for supervisor and handle starting/stopping the applications -* Find ouw witch audio/video codec is the cheapest as far as data and performance goes (with minimal quality loss) -* Slim down the [robotgo](github.com/go-vgo/robotgo) package and *just* handle the key io -* Add user names for the client -* Add (text) chat for the client -* Add that cool emoji thing rabb.it had -* Slim down the docker container (use alpine) diff --git a/client/.eslintrc b/client/.eslintrc index 05bd58d4..a52d45af 100644 --- a/client/.eslintrc +++ b/client/.eslintrc @@ -11,6 +11,7 @@ "no-case-declarations": "off", "no-dupe-class-members": "off", "no-console": "off", + "no-empty": "off" } } diff --git a/client/src/App.vue b/client/src/App.vue index f66ff27c..8e6b25c5 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -379,13 +379,11 @@