|
@@ -78,7 +78,7 @@ func (w *WebServer) connector(c echo.Context) error {
|
|
|
w.Tv_ip = cmd
|
|
|
log.Printf("Switched to %s", cmd)
|
|
|
|
|
|
- return c.Redirect(http.StatusOK, "/connect")
|
|
|
+ return c.Redirect(http.StatusTemporaryRedirect, "/connect")
|
|
|
}
|
|
|
|
|
|
func (w *WebServer) con_refresh(c echo.Context) error {
|
|
@@ -124,39 +124,106 @@ func (w *WebServer) tvcmd(c echo.Context) error {
|
|
|
cmd := c.Param("cmd")
|
|
|
switch cmd {
|
|
|
case "power":
|
|
|
- PerformKey(w.Tv_ip, "power")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "power")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ }
|
|
|
case "back":
|
|
|
- PerformKey(w.Tv_ip, "back")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "back")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "back")
|
|
|
+ }
|
|
|
case "home":
|
|
|
- PerformKey(w.Tv_ip, "home")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "home")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "home")
|
|
|
+ }
|
|
|
case "up":
|
|
|
- PerformKey(w.Tv_ip, "up")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "up")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "up")
|
|
|
+ }
|
|
|
case "left":
|
|
|
- PerformKey(w.Tv_ip, "left")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "left")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "left")
|
|
|
+ }
|
|
|
case "ok":
|
|
|
- PerformKey(w.Tv_ip, "select")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "select")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "select")
|
|
|
+ }
|
|
|
case "right":
|
|
|
- PerformKey(w.Tv_ip, "right")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "right")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "right")
|
|
|
+ }
|
|
|
case "down":
|
|
|
- PerformKey(w.Tv_ip, "down")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "down")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "down")
|
|
|
+ }
|
|
|
case "rewind":
|
|
|
- PerformKey(w.Tv_ip, "rev")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "rev")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "rev")
|
|
|
+ }
|
|
|
case "play-pause":
|
|
|
- PerformKey(w.Tv_ip, "play")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "play")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "play")
|
|
|
+ }
|
|
|
case "fast-forward":
|
|
|
- PerformKey(w.Tv_ip, "fwd")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "fwd")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "fwd")
|
|
|
+ }
|
|
|
case "star":
|
|
|
- PerformKey(w.Tv_ip, "info")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "info")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "info")
|
|
|
+ }
|
|
|
case "reload":
|
|
|
- PerformKey(w.Tv_ip, "instantreplay")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "instantreplay")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "instantreplay")
|
|
|
+ }
|
|
|
case "vol+":
|
|
|
- PerformKey(w.Tv_ip, "volumeup")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "volumeup")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "volumeup")
|
|
|
+ }
|
|
|
case "vol-":
|
|
|
- PerformKey(w.Tv_ip, "volumedown")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "volumedown")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "volumedown")
|
|
|
+ }
|
|
|
case "mute":
|
|
|
- PerformKey(w.Tv_ip, "volumemute")
|
|
|
+ var r bool = PerformKey(w.Tv_ip, "volumemute")
|
|
|
+ if !r {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ PerformKey(w.Tv_ip, "volumemute")
|
|
|
+ }
|
|
|
case "display":
|
|
|
w.At = DebugInfo(w.Tv_ip)
|
|
|
+ if w.At == "" {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ w.At = DebugInfo(w.Tv_ip)
|
|
|
+ }
|
|
|
device := GetDeviceInfo(w.Tv_ip)
|
|
|
if device["power-mode"] == "PowerOn" {
|
|
|
w.Power = true
|
|
@@ -168,25 +235,60 @@ func (w *WebServer) tvcmd(c echo.Context) error {
|
|
|
data["power"] = w.Power
|
|
|
return c.JSON(http.StatusOK, data)
|
|
|
case "pluto":
|
|
|
- Post(fmt.Sprintf("http://%s:8060/launch/%d", w.Tv_ip, 74519))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=367&mediaType=live", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=244&mediaType=live", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=488&mediaType=live", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=489&mediaType=live", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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))
|
|
|
+ r := Post(fmt.Sprintf("http://%s:8060/launch/%d?contentId=150&mediaType=live", w.Tv_ip, 74519))
|
|
|
+ if r == nil {
|
|
|
+ sendEtherWake(w.WakeOnLan[w.Tv_ip])
|
|
|
+ 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)
|
|
|
+ c.Echo().Logger.Printf("Got '%v'\n", cmd)
|
|
|
}
|
|
|
- return c.Redirect(http.StatusOK, "/")
|
|
|
+ return c.Redirect(http.StatusTemporaryRedirect, "/")
|
|
|
//return c.Render(http.StatusOK, "index.html", data)
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
+ // Write log.print ect into a file
|
|
|
+ var logfilename string = "roku.log"
|
|
|
+ var logf *os.File
|
|
|
+ var err error
|
|
|
+ logf, err = os.OpenFile(logfilename, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
|
|
+ if err != nil {
|
|
|
+ log.Panicf("Error creating log file %s: %v", logfilename, err)
|
|
|
+ }
|
|
|
+ log.SetOutput(logf)
|
|
|
+ log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
|
+
|
|
|
web := WebServer{}
|
|
|
web.Init("192.168.254.75", "", "8000")
|
|
|
|