diff --git a/Zframework/websocket.lua b/Zframework/websocket.lua index ab36c69e..2cf5af08 100644 --- a/Zframework/websocket.lua +++ b/Zframework/websocket.lua @@ -233,6 +233,15 @@ local wsList=setmetatable({},{ end }) +function WS.switchHost(_1,_2,_3) + for k in next,wsList do + WS.close(k) + end + host=_1 + port=_2 or port + path=_3 or path +end + function WS.connect(name,subPath,body,timeout) local ws={ real=true, diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 73bcf490..5a6ce217 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -236,6 +236,18 @@ do--commands.help(arg) "Usage: test", }, }, + switchhost={ + description="Switch another host", + details={ + "Disconnect all connections and switch to another host", + "", + "Usage:", + "switchhost [host]", + "switchhost [host] [port]", + "switchhost [host] [port] [path]", + "Example: switchhost 127.0.0.1 26000 /sock", + }, + }, applet={ description="Go to an applet scene", details={ @@ -275,6 +287,7 @@ do--commands.help(arg) "setbg", "theme", "test", + "switchhost", "applet", } function commands.help(arg) @@ -583,6 +596,19 @@ end function commands.test() SCN.go('test','none') end +function commands.switchhost(arg) + arg=STRING.split(arg," ") + if arg[1]and #arg<=3 then + WS.switchHost(unpack(arg)) + log{C.Y,"Host switched"} + else + log{C.A,"Usage:"} + log{C.A,"switchhost [host]"} + log{C.A,"switchhost [host] [port]"} + log{C.A,"switchhost [host] [port] [path]"} + log{C.A,"Example: switchhost 127.0.0.1 26000 /sock"} + end +end do--commands.applet(name) local appList={"15p","grid","pong","atoz","uttt","cube","2048","ten","tap","dtw","cannon","dropper","calc","reflect","polyforge"} local appScene={'app_15p','app_schulteG','app_pong','app_AtoZ','app_UTTT','app_cubefield','app_2048','app_ten','app_tap','app_dtw','app_cannon','app_dropper','app_calc','app_reflect','app_polyforge'}