2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

feat: 终端支持ping

This commit is contained in:
2026-01-26 20:09:33 +08:00
parent 56c1dcbd44
commit 36f2bdaf81
3 changed files with 87 additions and 2 deletions

View File

@@ -17,6 +17,10 @@ type MessageResize struct {
Rows int `json:"rows"`
}
type MessagePing struct {
Ping bool `json:"ping"`
}
type Turn struct {
ctx context.Context
stdin io.WriteCloser
@@ -72,6 +76,7 @@ func (t *Turn) Close() {
func (t *Turn) Handle(ctx context.Context) error {
var resize MessageResize
var ping MessagePing
for {
select {
@@ -84,6 +89,12 @@ func (t *Turn) Handle(ctx context.Context) error {
return fmt.Errorf("reading ws message err: %v", err)
}
// 判断是否是 ping 消息
if err = json.Unmarshal(data, &ping); err == nil && ping.Ping {
_ = t.ws.Write(ctx, websocket.MessageText, []byte(`{"pong":true}`))
continue
}
// 判断是否是 resize 消息
if err = json.Unmarshal(data, &resize); err == nil {
if resize.Resize && resize.Columns > 0 && resize.Rows > 0 {