more tweeks
This commit is contained in:
parent
c85abb3b63
commit
5830f92637
14
.docker/build
Executable file
14
.docker/build
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd ../server
|
||||||
|
go get && make build
|
||||||
|
|
||||||
|
cd ../client
|
||||||
|
npm install && npm run build
|
||||||
|
|
||||||
|
cd ../
|
||||||
|
sudo docker build -f Dockerfile -t neko .
|
||||||
|
|
||||||
|
# sudo docker run -p 8080:8080 --shm-size=2gb neko:latest
|
||||||
|
# sudo docker run --network host --shm-size=2gb neko:latest
|
||||||
|
# sudo docker run --network host --shm-size=2gb -it neko:latest /bin/bash
|
@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cd ../server
|
|
||||||
go get && make build
|
|
||||||
|
|
||||||
cd ../client
|
|
||||||
npm install && npm run build
|
|
||||||
|
|
||||||
cd ../
|
|
||||||
sudo docker build -f Dockerfile -t neko .
|
|
||||||
|
|
||||||
# sudo docker run -p 8080:8080 --shm-size=2gb neko:latest
|
|
13
Dockerfile
13
Dockerfile
@ -9,7 +9,7 @@ ENV DEBIAN_FRONTEND=noninteractive
|
|||||||
|
|
||||||
# Install dependencies ttf-freefont
|
# Install dependencies ttf-freefont
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get -y install curl supervisor openbox dbus-x11 xvfb pulseaudio firefox-esr \
|
&& apt-get -y install curl apt-utils supervisor openbox dbus-x11 xvfb pulseaudio firefox-esr \
|
||||||
&& apt-get -y install gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-pulseaudio libxcb-xkb-dev libxkbcommon-x11-dev \
|
&& apt-get -y install gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-pulseaudio libxcb-xkb-dev libxkbcommon-x11-dev \
|
||||||
#
|
#
|
||||||
# Create a non-root user
|
# Create a non-root user
|
||||||
@ -29,10 +29,13 @@ RUN apt-get update \
|
|||||||
&& 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 \
|
&& 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 \
|
||||||
#
|
#
|
||||||
# Setup Pulse Audio
|
# Setup Pulse Audio
|
||||||
mkdir -p /home/$USERNAME/.config/pulse/ \
|
&& mkdir -p /home/$USERNAME/.config/pulse/ \
|
||||||
&& echo "default-server=unix:/tmp/pulseaudio.socket" > /home/$USERNAME/.config/pulse/client.conf \
|
&& echo "default-server=unix:/tmp/pulseaudio.socket" > /home/$USERNAME/.config/pulse/client.conf \
|
||||||
&& chown -R $USERNAME:$USERNAME /home/$USERNAME \
|
&& chown -R $USERNAME:$USERNAME /home/$USERNAME \
|
||||||
#
|
#
|
||||||
|
# Workaround for an X11 problem. See: http://blog.tigerteufel.de/?p=476
|
||||||
|
&& mkdir /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix && chown $USERNAME /tmp/.X11-unix/ \
|
||||||
|
#
|
||||||
# Make directories for neko
|
# Make directories for neko
|
||||||
&& mkdir -p /etc/neko /var/www \
|
&& mkdir -p /etc/neko /var/www \
|
||||||
#
|
#
|
||||||
@ -62,9 +65,7 @@ ENV NEKO_DISPLAY=0
|
|||||||
ENV NEKO_WIDTH=1280
|
ENV NEKO_WIDTH=1280
|
||||||
ENV NEKO_HEIGHT=720
|
ENV NEKO_HEIGHT=720
|
||||||
ENV NEKO_PASSWORD=neko
|
ENV NEKO_PASSWORD=neko
|
||||||
ENV NEKO_BIND=0.0.0.0:8080
|
ENV NEKO_BIND=:8080
|
||||||
ENV NEKO_KEY=
|
|
||||||
ENV NEKO_CERT=
|
|
||||||
|
|
||||||
# Nayn
|
# Nayn
|
||||||
ENV NEKO_URL=https://www.youtube.com/embed/QH2-TGUlwu4
|
ENV NEKO_URL=https://www.youtube.com/embed/QH2-TGUlwu4
|
||||||
@ -74,5 +75,5 @@ ENV NEKO_URL=https://www.youtube.com/embed/QH2-TGUlwu4
|
|||||||
COPY .docker/entrypoint.sh /entrypoint.sh
|
COPY .docker/entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Run entrypoint
|
# Run Service
|
||||||
CMD ["/bin/bash", "/entrypoint.sh"]
|
CMD ["/bin/bash", "/entrypoint.sh"]
|
1
client/.env.development
Normal file
1
client/.env.development
Normal file
@ -0,0 +1 @@
|
|||||||
|
NEKO_DEV=localhost:3000
|
@ -470,12 +470,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
/*
|
|
||||||
this.ws = new WebSocket(
|
this.ws = new WebSocket(
|
||||||
`${/https/gi.test(location.protocol) ? 'wss' : 'ws'}://${location.host}/ws?password=${this.password}`,
|
process.env.NODE_ENV === 'development' ? `ws://${process.env.NEKO_DEV}/ws?password=${this.password}` : `${/https/gi.test(location.protocol) ? 'wss' : 'ws'}://${location.host}/ws?password=${this.password}` ,
|
||||||
)
|
)
|
||||||
*/
|
|
||||||
this.ws = new WebSocket(`ws://localhost:3000/ws?password=${this.password}`)
|
|
||||||
this.ws.onmessage = this.onMessage.bind(this)
|
this.ws.onmessage = this.onMessage.bind(this)
|
||||||
this.ws.onerror = event => console.error((event as ErrorEvent).error)
|
this.ws.onerror = event => console.error((event as ErrorEvent).error)
|
||||||
this.ws.onclose = event => this.onClose.bind(this)
|
this.ws.onclose = event => this.onClose.bind(this)
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"n.eko.moe/neko/internal/http/handler"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(bind, password, static string) *http.Server {
|
|
||||||
return &http.Server{
|
|
||||||
Addr: bind,
|
|
||||||
Handler: handler.New(password, static),
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"n.eko.moe/neko/internal/http/middleware"
|
|
||||||
"n.eko.moe/neko/internal/http/endpoint"
|
|
||||||
"n.eko.moe/neko/internal/webrtc"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Handler struct {
|
|
||||||
router *chi.Mux
|
|
||||||
manager *webrtc.WebRTCManager
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(password, static string) *chi.Mux {
|
|
||||||
router := chi.NewRouter()
|
|
||||||
manager, err := webrtc.NewManager(password)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
handler := &Handler{
|
|
||||||
router: router,
|
|
||||||
manager: manager,
|
|
||||||
}
|
|
||||||
|
|
||||||
router.Use(middleware.Recoverer) // Recover from panics without crashing server
|
|
||||||
// router.Use(middleware.Logger) // Log API request calls
|
|
||||||
|
|
||||||
router.Get("/ping", endpoint.Handle(handler.Ping))
|
|
||||||
router.Get("/ws", endpoint.Handle(handler.WebSocket))
|
|
||||||
|
|
||||||
fs := http.FileServer(http.Dir(static))
|
|
||||||
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if _, err := os.Stat(static + r.RequestURI); os.IsNotExist(err) {
|
|
||||||
http.StripPrefix(r.RequestURI, fs).ServeHTTP(w, r)
|
|
||||||
} else {
|
|
||||||
fs.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.NotFound(endpoint.Handle(func(w http.ResponseWriter, r *http.Request) error {
|
|
||||||
return &endpoint.HandlerError{
|
|
||||||
Status: http.StatusNotFound,
|
|
||||||
Message: fmt.Sprintf("Endpoint '%s' is not avalible", r.RequestURI),
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
return router
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import "net/http"
|
|
||||||
|
|
||||||
func (h *Handler) Ping(w http.ResponseWriter, r *http.Request) error {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write([]byte("."))
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h *Handler) WebSocket(w http.ResponseWriter, r *http.Request) error {
|
|
||||||
return h.manager.Upgrade(w, r)
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Config(name string) {
|
func Config(name string) {
|
||||||
config := viper.GetString("neko.config")
|
config := viper.GetString("config")
|
||||||
|
|
||||||
if config != "" {
|
if config != "" {
|
||||||
viper.SetConfigFile(config) // Use config file from the flag.
|
viper.SetConfigFile(config) // Use config file from the flag.
|
||||||
@ -35,8 +35,8 @@ func Config(name string) {
|
|||||||
|
|
||||||
file := viper.ConfigFileUsed()
|
file := viper.ConfigFileUsed()
|
||||||
logger := log.With().
|
logger := log.With().
|
||||||
Bool("debug", viper.GetBool("neko.debug")).
|
Bool("debug", viper.GetBool("debug")).
|
||||||
Str("logging", viper.GetString("neko.logs")).
|
Str("logging", viper.GetString("logs")).
|
||||||
Str("config", file).
|
Str("config", file).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
|
@ -18,13 +18,13 @@ func Logs(name string) {
|
|||||||
zerolog.TimeFieldFormat = ""
|
zerolog.TimeFieldFormat = ""
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
|
|
||||||
if viper.GetBool("neko.debug") {
|
if viper.GetBool("debug") {
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
console := zerolog.ConsoleWriter{Out: os.Stdout}
|
console := zerolog.ConsoleWriter{Out: os.Stdout}
|
||||||
|
|
||||||
if !viper.GetBool("neko.logs") {
|
if !viper.GetBool("logs") {
|
||||||
log.Logger = log.Output(console)
|
log.Logger = log.Output(console)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -18,10 +18,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (manager *WebRTCManager) Upgrade(w http.ResponseWriter, r *http.Request) error {
|
func (manager *WebRTCManager) Upgrade(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
manager.logger.
|
||||||
|
Info().
|
||||||
|
Msg("Attempting to upgrade ws")
|
||||||
|
|
||||||
socket, err := manager.upgrader.Upgrade(w, r, nil)
|
socket, err := manager.upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Error().Err(err).Msg("Failed to upgrade websocket!")
|
manager.logger.Error().Err(err).Msg("Failed to upgrade websocket!")
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID, ok := manager.authenticate(r)
|
sessionID, ok := manager.authenticate(r)
|
||||||
|
@ -9,9 +9,12 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"n.eko.moe/neko/internal/config"
|
"n.eko.moe/neko/internal/config"
|
||||||
|
"n.eko.moe/neko/internal/http/endpoint"
|
||||||
|
"n.eko.moe/neko/internal/http/middleware"
|
||||||
"n.eko.moe/neko/internal/structs"
|
"n.eko.moe/neko/internal/structs"
|
||||||
api "n.eko.moe/neko/internal/http"
|
"n.eko.moe/neko/internal/webrtc"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -68,7 +71,49 @@ func (neko *Neko) Preflight() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (neko *Neko) Start() {
|
func (neko *Neko) Start() {
|
||||||
server := api.New(neko.Serve.Bind, neko.Serve.Password, neko.Serve.Static)
|
router := chi.NewRouter()
|
||||||
|
|
||||||
|
manager, err := webrtc.NewManager(neko.Serve.Password)
|
||||||
|
if err != nil {
|
||||||
|
neko.Logger.Panic().Err(err).Msg("Can not start webrtc manager")
|
||||||
|
}
|
||||||
|
|
||||||
|
router.Use(middleware.Recoverer) // Recover from panics without crashing server
|
||||||
|
router.Use(middleware.RequestID) // Create a request ID for each request
|
||||||
|
router.Use(middleware.Logger) // Log API request calls
|
||||||
|
|
||||||
|
router.Get("/ping", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("."))
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Get("/ws", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if err := manager.Upgrade(w, r); err != nil {
|
||||||
|
neko.Logger.Error().Err(err).Msg("session.destroy has failed")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
fs := http.FileServer(http.Dir(neko.Serve.Static))
|
||||||
|
router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := os.Stat(neko.Serve.Static + r.RequestURI); os.IsNotExist(err) {
|
||||||
|
http.StripPrefix(r.RequestURI, fs).ServeHTTP(w, r)
|
||||||
|
} else {
|
||||||
|
fs.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.NotFound(endpoint.Handle(func(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
return &endpoint.HandlerError{
|
||||||
|
Status: http.StatusNotFound,
|
||||||
|
Message: fmt.Sprintf("Endpoint '%s' is not avalible", r.RequestURI),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: neko.Serve.Bind,
|
||||||
|
Handler: router,
|
||||||
|
}
|
||||||
|
|
||||||
if neko.Serve.Cert != "" && neko.Serve.Key != "" {
|
if neko.Serve.Cert != "" && neko.Serve.Key != "" {
|
||||||
go func() {
|
go func() {
|
||||||
|
Reference in New Issue
Block a user