|
@@ -1,72 +1,108 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"net/http"
|
|
|
- "os"
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
"github.com/labstack/echo/v4/middleware"
|
|
|
)
|
|
|
|
|
|
-const tv_ip = "192.168.254.75"
|
|
|
+type WebServer struct {
|
|
|
+ tv_ip string
|
|
|
+ Port string
|
|
|
+ Host string
|
|
|
+ At string
|
|
|
+}
|
|
|
+
|
|
|
+func (w *WebServer) Init(tv, host, port string) {
|
|
|
+ w.tv_ip = tv
|
|
|
+ w.Host = host
|
|
|
+ w.Port = port
|
|
|
+ w.At = DebugInfo(w.tv_ip)
|
|
|
+}
|
|
|
|
|
|
-func homepage(c echo.Context) error {
|
|
|
- DebugInfo(tv_ip)
|
|
|
+func (w *WebServer) homepage(c echo.Context) error {
|
|
|
//return c.String(http.StatusOK, "Hello World!")
|
|
|
- file, err := os.ReadFile("templates/index.html")
|
|
|
+ /*file, err := os.ReadFile("templates/index.html")
|
|
|
if err != nil {
|
|
|
return err
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- return c.HTMLBlob(http.StatusOK, file)
|
|
|
+ //return c.HTMLBlob(http.StatusOK, file)
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["at"] = w.At
|
|
|
+ return c.Render(http.StatusOK, "index.html", data)
|
|
|
}
|
|
|
|
|
|
-func tvcmd(c echo.Context) error {
|
|
|
+func (w *WebServer) tvcmd(c echo.Context) error {
|
|
|
+ //w.At = DebugInfo(w.tv_ip)
|
|
|
cmd := c.Param("cmd")
|
|
|
switch cmd {
|
|
|
case "power":
|
|
|
- PerformKey(tv_ip, "power")
|
|
|
+ PerformKey(w.tv_ip, "power")
|
|
|
case "back":
|
|
|
- PerformKey(tv_ip, "back")
|
|
|
+ PerformKey(w.tv_ip, "back")
|
|
|
case "home":
|
|
|
- PerformKey(tv_ip, "home")
|
|
|
+ PerformKey(w.tv_ip, "home")
|
|
|
case "up":
|
|
|
- PerformKey(tv_ip, "up")
|
|
|
+ PerformKey(w.tv_ip, "up")
|
|
|
case "left":
|
|
|
- PerformKey(tv_ip, "left")
|
|
|
+ PerformKey(w.tv_ip, "left")
|
|
|
case "ok":
|
|
|
- PerformKey(tv_ip, "select")
|
|
|
+ PerformKey(w.tv_ip, "select")
|
|
|
case "right":
|
|
|
- PerformKey(tv_ip, "right")
|
|
|
+ PerformKey(w.tv_ip, "right")
|
|
|
case "down":
|
|
|
- PerformKey(tv_ip, "down")
|
|
|
+ PerformKey(w.tv_ip, "down")
|
|
|
case "rewind":
|
|
|
- PerformKey(tv_ip, "rev")
|
|
|
+ PerformKey(w.tv_ip, "rev")
|
|
|
case "play-pause":
|
|
|
- PerformKey(tv_ip, "play")
|
|
|
+ PerformKey(w.tv_ip, "play")
|
|
|
case "fast-forward":
|
|
|
- PerformKey(tv_ip, "fwd")
|
|
|
- /*case "star":
|
|
|
- // Unknown
|
|
|
+ PerformKey(w.tv_ip, "fwd")
|
|
|
+ case "star":
|
|
|
+ PerformKey(w.tv_ip, "info")
|
|
|
case "reload":
|
|
|
- // Unknown*/
|
|
|
+ PerformKey(w.tv_ip, "instantreplay")
|
|
|
case "vol+":
|
|
|
- PerformKey(tv_ip, "volumeup")
|
|
|
+ PerformKey(w.tv_ip, "volumeup")
|
|
|
case "vol-":
|
|
|
- PerformKey(tv_ip, "volumedown")
|
|
|
+ PerformKey(w.tv_ip, "volumedown")
|
|
|
case "mute":
|
|
|
- PerformKey(tv_ip, "volumemute")
|
|
|
+ PerformKey(w.tv_ip, "volumemute")
|
|
|
+ case "display":
|
|
|
+ w.At = DebugInfo(w.tv_ip)
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["at"] = w.At
|
|
|
+ return c.String(http.StatusOK, "TV: "+w.At)
|
|
|
+ case "pluto":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d", w.tv_ip, 74519))
|
|
|
+ case "pluto-cops":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=367", w.tv_ip, 74519))
|
|
|
+ case "pluto-thefirst":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=244", w.tv_ip, 74519))
|
|
|
+ case "pluto-mst3k":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=488", w.tv_ip, 74519))
|
|
|
+ case "pluto-rifftrax":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=489", w.tv_ip, 74519))
|
|
|
+ case "pluto-startrek":
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=150", w.tv_ip, 74519))
|
|
|
default:
|
|
|
c.Echo().Logger.Printf("Got '%v'\r\n", cmd)
|
|
|
}
|
|
|
- return c.Redirect(http.StatusAccepted, "/")
|
|
|
+ return c.Redirect(http.StatusOK, "/")
|
|
|
+ //return c.Render(http.StatusOK, "index.html", data)
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
+ web := WebServer{}
|
|
|
+ web.Init("192.168.254.75", "", "8000")
|
|
|
e := echo.New()
|
|
|
e.Use(middleware.Logger())
|
|
|
e.Use(middleware.Static("static"))
|
|
|
- e.GET("/", homepage)
|
|
|
- e.GET("/tv/:cmd", tvcmd)
|
|
|
- e.Logger.Fatal(e.Start(":8000"))
|
|
|
+ e.Renderer = NewRenderer("./templates/*.html", true)
|
|
|
+ e.GET("/", web.homepage)
|
|
|
+ e.GET("/tv/:cmd", web.tvcmd)
|
|
|
+ e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", web.Host, web.Port)))
|
|
|
}
|