* 优化图标和LOGO * 修改登录页面动画的速度为3 * 增加对websocket的异常处理 * 修复了用户组和用户名唯一判断错误的问题 * 提示版本号 * 修复readme错别字 * 修复单词拼写错误的问题 * 修复代码格式 * 修改Windows资产属性名称 * Docker 打包流程增加 upx 压缩 * 升级依赖文件,修改sqlite驱动为 github.com/glebarez/sqlite * 修复第一次查询「授权令牌」的错误 * 移除无关代码 * 修改docker打包脚本 * 增加打包脚本 * 增加微信群 * 修复单词拼写错误的问题 * 修复代码格式 * 修改Windows资产属性名称 * Docker 打包流程增加 upx 压缩 * 修改docker打包脚本 * - 替换 sqlite 驱动为 github.com/glebarez/sqlite - 修复数据库锁定的问题 - 修复部分代码不完善的问题 - 修复策略显示不完整的问题 - 修复编辑文件换行符的问题 - 优化guacd连接
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package api
|
||
|
||
import (
|
||
"context"
|
||
|
||
"next-terminal/server/guacd"
|
||
"next-terminal/server/log"
|
||
"next-terminal/server/utils"
|
||
|
||
"github.com/gorilla/websocket"
|
||
)
|
||
|
||
type GuacamoleHandler struct {
|
||
ws *websocket.Conn
|
||
tunnel *guacd.Tunnel
|
||
ctx context.Context
|
||
cancel context.CancelFunc
|
||
}
|
||
|
||
func NewGuacamoleHandler(ws *websocket.Conn, tunnel *guacd.Tunnel) *GuacamoleHandler {
|
||
ctx, cancel := context.WithCancel(context.Background())
|
||
return &GuacamoleHandler{
|
||
ws: ws,
|
||
tunnel: tunnel,
|
||
ctx: ctx,
|
||
cancel: cancel,
|
||
}
|
||
}
|
||
|
||
func (r GuacamoleHandler) Start() {
|
||
go func() {
|
||
for {
|
||
select {
|
||
case <-r.ctx.Done():
|
||
return
|
||
default:
|
||
instruction, err := r.tunnel.Read()
|
||
if err != nil {
|
||
utils.Disconnect(r.ws, TunnelClosed, "远程连接已关闭")
|
||
return
|
||
}
|
||
if len(instruction) == 0 {
|
||
continue
|
||
}
|
||
err = r.ws.WriteMessage(websocket.TextMessage, instruction)
|
||
if err != nil {
|
||
log.Debugf("WebSocket写入失败,即将关闭Guacd连接...")
|
||
return
|
||
}
|
||
}
|
||
}
|
||
}()
|
||
}
|
||
|
||
func (r GuacamoleHandler) Stop() {
|
||
r.cancel()
|
||
}
|