Skip to content

Commit

Permalink
perf: 监控会话结束,弹框提示断开信息
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jul 18, 2023
1 parent e15b298 commit 52646c8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
12 changes: 9 additions & 3 deletions pkg/tunnel/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type MonitorCon struct {
Id string
guacdTunnel Tunneler

ws *websocket.Conn
Expand Down Expand Up @@ -53,7 +54,8 @@ func (m *MonitorCon) Run(ctx context.Context) (err error) {
for {
instruction, err := t.readTunnelInstruction()
if err != nil {
logger.Error(err)
_ = t.writeWsMessage([]byte(ErrDisconnect.String()))
logger.Infof("Monitor[%s] guacd tunnel read err: %+v", t.Id, err)
exit <- err
break
}
Expand All @@ -70,6 +72,8 @@ func (m *MonitorCon) Run(ctx context.Context) (err error) {
for {
_, message, err := t.ws.ReadMessage()
if err != nil {
logger.Infof("Monitor[%s] ws read err: %+v", t.Id, err)

exit <- err
break
}
Expand All @@ -82,11 +86,11 @@ func (m *MonitorCon) Run(ctx context.Context) (err error) {
continue
}
} else {
logger.Errorf("Parse instruction err %s", err)
logger.Errorf("Monitor[%s] parse instruction err %s", t.Id, err)
}
_, err = t.writeTunnelMessage(message)
if err != nil {
logger.Errorf("Guacamole server write err: %+v", err)
logger.Errorf("Monitor[%s] guacamole tunnel write err: %+v", t.Id, err)
exit <- err
break
}
Expand All @@ -97,8 +101,10 @@ func (m *MonitorCon) Run(ctx context.Context) (err error) {
for {
select {
case err = <-exit:
logger.Infof("Monitor[%s] exit: %+v", m.Id, err)
return err
case <-ctx.Done():
logger.Info("Monitor[%s] done", m.Id)
return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/tunnel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func (g *GuacamoleTunnelServer) Monitor(ctx *gin.Context) {
}
defer tunnelCon.Close()
conn := MonitorCon{
Id: sessionId,
guacdTunnel: tunnelCon,
ws: ws,
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/tunnel/ws_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ var (
ErrGuacamoleServer = NewJMSGuacamoleError(1008, "Connect guacamole server failed")

ErrPermission = NewJMSGuacamoleError(256, "No permission")

ErrDisconnect = NewJMSGuacamoleError(1009, "Disconnect by client")
)
8 changes: 3 additions & 5 deletions ui/src/components/GuacamoleMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { getMonitorConnectParams } from '@/utils/common'
import { getSupportedMimetypes } from '@/utils/image'
import { getSupportedGuacAudios } from '@/utils/audios'
import { getSupportedGuacVideos } from '@/utils/video'
import { getLanguage } from '@/i18n'
import { ErrorStatusCodes } from '@/utils/status'
import { ConvertGuacamoleError, ErrorStatusCodes } from '@/utils/status'
const pixelDensity = window.devicePixelRatio || 1
export default {
Expand Down Expand Up @@ -220,9 +219,7 @@ export default {
this.$log.debug(status, i18n.locale)
const code = status.code
let msg = status.message
if (getLanguage() === 'cn') {
msg = ErrorStatusCodes[code] ? this.$t(ErrorStatusCodes[code]) : status.message
}
msg = ErrorStatusCodes[code] ? this.$t(ErrorStatusCodes[code]) : this.$t(ConvertGuacamoleError(status.message))
this.$alert(msg, this.$t('ErrTitle'), {
confirmButtonText: this.$t('OK'),
callback: action => {
Expand All @@ -239,6 +236,7 @@ export default {
const tunnel = new Guacamole.WebSocketTunnel(wsURL)
const client = new Guacamole.Client(tunnel)
const vm = this
tunnel.receiveTimeout = 60 * 1000
tunnel.onerror = function tunnelError(status) {
vm.$log.debug('tunnelError ', status)
display.innerHTML = ''
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/lang/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const message = {
JMSErrAPIFailed: 'Core API 发生错误',
JMSErrGatewayFailed: '网关连接失败',
JMSErrGuacamoleServer: '无法连接 Guacamole 服务器',
JMSErrDisconnected: '会话连接已断开',
GuaErrUpstreamNotFound: '无法连接到远程桌面服务器(网络不可达 | 安全策略错误)',
GuaErrSessionConflict: '因与另一个连接冲突,远程桌面服务器关闭了本连接。请稍后重试。',
GuaErrClientUnauthorized: '用户名和密码认证错误,登录失败',
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const message = {
JMSErrAPIFailed: 'Core API failed',
JMSErrGatewayFailed: 'Gateway not available',
JMSErrGuacamoleServer: 'Connect guacamole server failed',
JMSErrDisconnected: 'Session Disconnected',
GuaErrUpstreamNotFound: 'The remote desktop server does not appear to exist, or cannot be reached over the network.',
GuaErrSessionConflict: 'The session has ended because it conflicts with another session.',
GuaErrClientUnauthorized: 'User failed to logged in. (username and password are incorrect)',
Expand Down
3 changes: 2 additions & 1 deletion ui/src/utils/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const ErrorStatusCodes = {
1005: 'JMSErrTerminatedByAdmin',
1006: 'JMSErrAPIFailed',
1007: 'JMSErrGatewayFailed',
1008: 'JMSErrGuacamoleServer'
1008: 'JMSErrGuacamoleServer',
1009: 'JMSErrDisconnected'
}

export function ConvertAPIError(errMsg) {
Expand Down

0 comments on commit 52646c8

Please sign in to comment.