Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-communication
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-communication
Commits
3bec6694
Commit
3bec6694
authored
Jul 30, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
2442dfc8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
+43
-9
yd-communication-api/src/main/java/com/yd/communication/api/service/impl/ApiCoSessionServiceImpl.java
+0
-0
yd-communication-api/src/main/java/com/yd/communication/api/websocket/CoWebSocketServer.java
+43
-9
No files found.
yd-communication-api/src/main/java/com/yd/communication/api/service/impl/ApiCoSessionServiceImpl.java
View file @
3bec6694
This diff is collapsed.
Click to expand it.
yd-communication-api/src/main/java/com/yd/communication/api/websocket/CoWebSocketServer.java
View file @
3bec6694
...
...
@@ -515,21 +515,23 @@ public class CoWebSocketServer {
public
void
onMessage
(
Session
session
,
String
message
)
{
// 根据会话查询对应的房间号
String
roomId
=
SESSION_ROOM
.
get
(
session
);
// 如果会话未关联房间,忽略消息
if
(
roomId
==
null
)
{
log
.
warn
(
"【WebSocket】会话未关联房间,忽略消息"
);
return
;
}
// 打印收到的原始消息
log
.
info
(
"【WebSocket】收到消息,房间号: {}, 消息内容: {}"
,
roomId
,
message
);
try
{
// 1. 解析 JSON 消息
JsonNode
json
=
objectMapper
.
readTree
(
message
);
// 获取操作类型
String
action
=
json
.
get
(
"action"
).
asText
();
// 获取当前操作用户ID
String
userId
=
SESSION_USER_ID
.
get
(
session
);
// 获取当前操作用户类型
String
userType
=
SESSION_USER_TYPE
.
get
(
session
);
log
.
info
(
"【WebSocket】解析结果: action={}, userId={}, userType={}"
,
action
,
userId
,
userType
);
// 2. 获取会话业务ID(用于操作日志记录)
CoSession
coSession
=
sessionService
.
getByRoomId
(
roomId
);
String
bizId
=
coSession
!=
null
?
coSession
.
getCoSessionBizId
()
:
null
;
...
...
@@ -538,26 +540,41 @@ public class CoWebSocketServer {
// --- 操作1:控制权切换(仅顾问可操作) ---
if
(
"control_transfer"
.
equals
(
action
))
{
log
.
info
(
"【控制权切换】开始处理,当前用户类型: {}"
,
userType
);
// 校验权限:只有参与者(顾问)才能切换控制权
if
(!
"participant"
.
equals
(
userType
))
{
log
.
warn
(
"【控制权切换】权限不足,非顾问用户尝试切换,userType={}"
,
userType
);
sendError
(
session
,
"只有顾问可以切换控制权"
);
return
;
}
// 解析顾问切换后的控制权信息
String
newHolderType
=
json
.
get
(
"holderType"
).
asText
();
String
newHolderId
=
json
.
get
(
"holderId"
).
asText
();
log
.
info
(
"【控制权切换】目标控制者: holderType={}, holderId={}"
,
newHolderType
,
newHolderId
);
// 构造控制权切换请求
TransferControlRequest
req
=
new
TransferControlRequest
();
req
.
setRoomId
(
roomId
);
// 判断切换后的持有者类型:如果是 owner(客户)则 opType=1(开启客户操作),否则 opType=2(关闭客户操作)
req
.
setOprType
(
ControlHolderTypeEnum
.
OWNER
.
getItemValue
().
equals
(
newHolderType
)
?
1
:
2
);
Integer
oprType
=
ControlHolderTypeEnum
.
OWNER
.
getItemValue
().
equals
(
newHolderType
)
?
1
:
2
;
req
.
setOprType
(
oprType
);
log
.
info
(
"【控制权切换】操作类型: {}"
,
oprType
);
// 调用服务层切换控制权(更新数据库 + Redis)
try
{
sessionService
.
transferControl
(
req
);
log
.
info
(
"【控制权切换】服务层调用成功,数据库和Redis已更新"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"【控制权切换】服务层调用失败"
,
e
);
sendError
(
session
,
"切换控制权失败:"
+
e
.
getMessage
());
return
;
}
// 广播控制权变更消息给房间内所有用户(包括自己)
broadcast
(
roomId
,
message
,
session
);
log
.
info
(
"【控制权切换】广播消息已发送"
);
// 记录操作日志(用于合规审计)
if
(
bizId
!=
null
)
{
...
...
@@ -570,8 +587,11 @@ public class CoWebSocketServer {
// --- 操作2:结束共享(仅客户可操作) ---
if
(
"end_sharing"
.
equals
(
action
))
{
log
.
info
(
"【结束共享】开始处理,当前用户类型: {}"
,
userType
);
// 校验权限:只有所有者(客户)才能结束共享
if
(!
"owner"
.
equals
(
userType
))
{
log
.
warn
(
"【结束共享】权限不足,非客户用户尝试结束共享,userType={}"
,
userType
);
sendError
(
session
,
"只有客户可以结束共享"
);
return
;
}
...
...
@@ -579,26 +599,29 @@ public class CoWebSocketServer {
// 构造结束会话请求
EndSessionRequest
req
=
new
EndSessionRequest
();
req
.
setRoomId
(
roomId
);
// 调用服务层结束会话(更新状态 + 停止录制 + 清理Redis)
log
.
info
(
"【结束共享】调用服务层结束会话"
);
sessionService
.
end
(
req
);
// 广播结束消息给所有用户
broadcast
(
roomId
,
"{\"action\":\"end_sharing\"}"
,
null
);
log
.
info
(
"【结束共享】结束消息已广播"
);
// 清理 Redis 中的页面状态
redisTemplate
.
delete
(
String
.
format
(
ROOM_STATE_PAGE_KEY
,
roomId
));
log
.
info
(
"【结束共享】Redis页面状态已清理"
);
// 关闭房间所有连接并清理资源
closeRoom
(
roomId
);
log
.
info
(
"共享已结束: roomId={}"
,
roomId
);
return
;
}
// --- 操作3:脱敏开关(客户操作,全房间生效) ---
if
(
"desensitization_switch"
.
equals
(
action
))
{
log
.
info
(
"【脱敏开关】收到请求,enabled={}"
,
json
.
get
(
"enabled"
).
asBoolean
());
// 广播脱敏状态给所有人(同步显示脱敏效果)
broadcast
(
roomId
,
message
,
session
);
log
.
info
(
"【脱敏开关】广播消息已发送"
);
// 记录操作日志
if
(
bizId
!=
null
)
{
...
...
@@ -609,13 +632,20 @@ public class CoWebSocketServer {
// --- 操作4:同步操作(翻页/滚动/缩放)——仅控制权持有者可操作 ---
if
(
"turn_the_page"
.
equals
(
action
)
||
"scroll"
.
equals
(
action
)
||
"scaling"
.
equals
(
action
))
{
log
.
info
(
"【同步操作】开始处理,action={}, 当前用户类型={}"
,
action
,
userType
);
// 4.1 获取当前控制权持有者信息
RoomRedisInfoDTO
dto
=
sessionService
.
getCurrentController
(
roomId
);
String
holderType
=
dto
.
getControlHolderType
();
String
holderId
=
dto
.
getControlHolderId
();
log
.
info
(
"【同步操作】当前控制权: holderType={}, holderId={}"
,
holderType
,
holderId
);
// 4.2 校验:当前用户是否持有控制权
if
(!(
holderType
.
equals
(
userType
)
&&
holderId
.
equals
(
userId
)))
{
boolean
isController
=
holderType
.
equals
(
userType
)
&&
holderId
.
equals
(
userId
);
log
.
info
(
"【同步操作】是否持有控制权: {}"
,
isController
);
if
(!
isController
)
{
log
.
warn
(
"【同步操作】用户无控制权,拒绝操作,userType={}, userId={}"
,
userType
,
userId
);
sendError
(
session
,
"您没有控制权,无法操作"
);
return
;
}
...
...
@@ -624,17 +654,21 @@ public class CoWebSocketServer {
if
(
"turn_the_page"
.
equals
(
action
)
||
"scroll"
.
equals
(
action
))
{
// 获取当前页面 JSON(从消息中提取)
String
currentPage
=
json
.
has
(
"currentPage"
)
?
json
.
get
(
"currentPage"
).
toString
()
:
"{}"
;
log
.
info
(
"【同步操作】更新页面状态: {}"
,
currentPage
);
// 更新数据库中的当前页面和页面历史轨迹
sessionService
.
updateCurrentPage
(
roomId
,
currentPage
,
userId
);
log
.
info
(
"【同步操作】数据库已更新"
);
// 更新 Redis 状态(供新节点连接时同步)
String
stateKey
=
String
.
format
(
ROOM_STATE_PAGE_KEY
,
roomId
);
redisTemplate
.
opsForValue
().
set
(
stateKey
,
currentPage
,
60
,
TimeUnit
.
MINUTES
);
log
.
info
(
"【同步操作】Redis状态已更新"
);
}
// 4.4 广播操作指令给房间内其他用户(排除自己,避免回环)
broadcast
(
roomId
,
message
,
session
);
log
.
info
(
"【同步操作】广播消息已发送"
);
// 4.5 记录操作日志(合规审计)
if
(
bizId
!=
null
)
{
...
...
@@ -648,7 +682,7 @@ public class CoWebSocketServer {
}
catch
(
Exception
e
)
{
// 处理消息异常,向客户端返回错误信息
log
.
error
(
"处理
消息异常"
,
e
);
log
.
error
(
"处理
WebSocket消息异常,消息内容: {}"
,
message
,
e
);
sendError
(
session
,
"服务器处理异常"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment