|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
@@ -9,17 +10,17 @@ import (
|
|
|
)
|
|
|
|
|
|
type WebServer struct {
|
|
|
- tv_ip string
|
|
|
- Port string
|
|
|
- Host string
|
|
|
- At string
|
|
|
+ Tv_ip string
|
|
|
+ Port string
|
|
|
+ Host string
|
|
|
+ At string
|
|
|
+ Device_list []string
|
|
|
}
|
|
|
|
|
|
func (w *WebServer) Init(tv, host, port string) {
|
|
|
- w.tv_ip = tv
|
|
|
+ w.Tv_ip = tv
|
|
|
w.Host = host
|
|
|
w.Port = port
|
|
|
- w.At = DebugInfo(w.tv_ip)
|
|
|
}
|
|
|
|
|
|
func (w *WebServer) homepage(c echo.Context) error {
|
|
@@ -35,59 +36,84 @@ func (w *WebServer) homepage(c echo.Context) error {
|
|
|
return c.Render(http.StatusOK, "index.html", data)
|
|
|
}
|
|
|
|
|
|
+func (w *WebServer) connectpage(c echo.Context) error {
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["connected"] = "Connected: " + w.Tv_ip
|
|
|
+ //var dev_list []string
|
|
|
+ var list []string
|
|
|
+ list = append(list, w.Device_list...)
|
|
|
+ data["resp"] = list
|
|
|
+ return c.Render(http.StatusOK, "connect.html", data)
|
|
|
+}
|
|
|
+
|
|
|
+func (w *WebServer) connector(c echo.Context) error {
|
|
|
+ cmd := c.Param("cmd")
|
|
|
+ w.Tv_ip = cmd
|
|
|
+ log.Printf("Switched to %s", cmd)
|
|
|
+
|
|
|
+ return c.Redirect(http.StatusOK, "/connect")
|
|
|
+}
|
|
|
+
|
|
|
+func (w *WebServer) con_refresh(c echo.Context) error {
|
|
|
+ log.Printf("Recieved Connection Refresh")
|
|
|
+ w.Device_list = GetDevices()
|
|
|
+ log.Printf("Found %d devices", len(w.Device_list))
|
|
|
+ return c.Redirect(http.StatusOK, "/connect")
|
|
|
+}
|
|
|
+
|
|
|
func (w *WebServer) tvcmd(c echo.Context) error {
|
|
|
- //w.At = DebugInfo(w.tv_ip)
|
|
|
+ //w.At = DebugInfo(w.Tv_ip)
|
|
|
cmd := c.Param("cmd")
|
|
|
switch cmd {
|
|
|
case "power":
|
|
|
- PerformKey(w.tv_ip, "power")
|
|
|
+ PerformKey(w.Tv_ip, "power")
|
|
|
case "back":
|
|
|
- PerformKey(w.tv_ip, "back")
|
|
|
+ PerformKey(w.Tv_ip, "back")
|
|
|
case "home":
|
|
|
- PerformKey(w.tv_ip, "home")
|
|
|
+ PerformKey(w.Tv_ip, "home")
|
|
|
case "up":
|
|
|
- PerformKey(w.tv_ip, "up")
|
|
|
+ PerformKey(w.Tv_ip, "up")
|
|
|
case "left":
|
|
|
- PerformKey(w.tv_ip, "left")
|
|
|
+ PerformKey(w.Tv_ip, "left")
|
|
|
case "ok":
|
|
|
- PerformKey(w.tv_ip, "select")
|
|
|
+ PerformKey(w.Tv_ip, "select")
|
|
|
case "right":
|
|
|
- PerformKey(w.tv_ip, "right")
|
|
|
+ PerformKey(w.Tv_ip, "right")
|
|
|
case "down":
|
|
|
- PerformKey(w.tv_ip, "down")
|
|
|
+ PerformKey(w.Tv_ip, "down")
|
|
|
case "rewind":
|
|
|
- PerformKey(w.tv_ip, "rev")
|
|
|
+ PerformKey(w.Tv_ip, "rev")
|
|
|
case "play-pause":
|
|
|
- PerformKey(w.tv_ip, "play")
|
|
|
+ PerformKey(w.Tv_ip, "play")
|
|
|
case "fast-forward":
|
|
|
- PerformKey(w.tv_ip, "fwd")
|
|
|
+ PerformKey(w.Tv_ip, "fwd")
|
|
|
case "star":
|
|
|
- PerformKey(w.tv_ip, "info")
|
|
|
+ PerformKey(w.Tv_ip, "info")
|
|
|
case "reload":
|
|
|
- PerformKey(w.tv_ip, "instantreplay")
|
|
|
+ PerformKey(w.Tv_ip, "instantreplay")
|
|
|
case "vol+":
|
|
|
- PerformKey(w.tv_ip, "volumeup")
|
|
|
+ PerformKey(w.Tv_ip, "volumeup")
|
|
|
case "vol-":
|
|
|
- PerformKey(w.tv_ip, "volumedown")
|
|
|
+ PerformKey(w.Tv_ip, "volumedown")
|
|
|
case "mute":
|
|
|
- PerformKey(w.tv_ip, "volumemute")
|
|
|
+ PerformKey(w.Tv_ip, "volumemute")
|
|
|
case "display":
|
|
|
- w.At = DebugInfo(w.tv_ip)
|
|
|
+ w.At = DebugInfo(w.Tv_ip)
|
|
|
data := make(map[string]interface{})
|
|
|
data["at"] = w.At
|
|
|
return c.String(http.StatusOK, w.At)
|
|
|
case "pluto":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d", w.tv_ip, 74519))
|
|
|
+ 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&mediaType=live", w.tv_ip, 74519))
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=367&mediaType=live", w.Tv_ip, 74519))
|
|
|
case "pluto-thefirst":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=244&mediaType=live", w.tv_ip, 74519))
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=244&mediaType=live", w.Tv_ip, 74519))
|
|
|
case "pluto-mst3k":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=488&mediaType=live", w.tv_ip, 74519))
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=488&mediaType=live", w.Tv_ip, 74519))
|
|
|
case "pluto-rifftrax":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=489&mediaType=live", w.tv_ip, 74519))
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=489&mediaType=live", w.Tv_ip, 74519))
|
|
|
case "pluto-startrek":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=150&mediaType=live", w.tv_ip, 74519))
|
|
|
+ Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=150&mediaType=live", w.Tv_ip, 74519))
|
|
|
default:
|
|
|
c.Echo().Logger.Printf("Got '%v'\r\n", cmd)
|
|
|
}
|
|
@@ -102,7 +128,12 @@ func main() {
|
|
|
e.Use(middleware.Logger())
|
|
|
e.Use(middleware.Static("static"))
|
|
|
e.Renderer = NewRenderer("./templates/*.html", true)
|
|
|
+
|
|
|
e.GET("/", web.homepage)
|
|
|
e.GET("/tv/:cmd", web.tvcmd)
|
|
|
+ e.GET("/connect", web.connectpage)
|
|
|
+ e.GET("/con/:cmd", web.connector)
|
|
|
+ e.GET("/conn_refresh", web.con_refresh)
|
|
|
+
|
|
|
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", web.Host, web.Port)))
|
|
|
}
|