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
b61f34a1
Commit
b61f34a1
authored
Aug 04, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
4554bc34
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
16 deletions
+56
-16
yd-communication-api/src/main/java/com/yd/communication/api/websocket/CoWebSocketServer.java
+56
-16
No files found.
yd-communication-api/src/main/java/com/yd/communication/api/websocket/CoWebSocketServer.java
View file @
b61f34a1
...
@@ -746,26 +746,38 @@ public class CoWebSocketServer {
...
@@ -746,26 +746,38 @@ public class CoWebSocketServer {
"presenter_response"
.
equals
(
action
)
||
"presenter_revoke"
.
equals
(
action
))
{
"presenter_response"
.
equals
(
action
)
||
"presenter_revoke"
.
equals
(
action
))
{
if
(
"presenter_invite"
.
equals
(
action
))
{
if
(
"presenter_invite"
.
equals
(
action
))
{
// 定向发送给目标用户类型
// 强制发送给客户(owner),因为投屏邀请的目标一定是客户
String
targetUserType
=
json
.
has
(
"target"
)
?
json
.
get
(
"target"
).
asText
()
:
null
;
String
targetUserType
=
"owner"
;
if
(
targetUserType
!=
null
)
{
log
.
info
(
"投屏邀请定向发送给: {}"
,
targetUserType
);
sendToUserType
(
roomId
,
targetUserType
,
message
);
sendToUserType
(
roomId
,
targetUserType
,
message
);
}
else
{
broadcast
(
roomId
,
message
,
session
);
}
}
else
if
(
"presenter_response"
.
equals
(
action
))
{
}
else
if
(
"presenter_response"
.
equals
(
action
))
{
boolean
accept
=
json
.
has
(
"accept"
)
&&
json
.
get
(
"accept"
).
asBoolean
();
boolean
accept
=
json
.
has
(
"accept"
)
&&
json
.
get
(
"accept"
).
asBoolean
();
if
(
accept
)
{
if
(
accept
)
{
String
target
=
json
.
has
(
"target"
)
?
json
.
get
(
"target"
).
asText
()
:
null
;
String
target
=
json
.
has
(
"target"
)
?
json
.
get
(
"target"
).
asText
()
:
null
;
if
(
target
!=
null
)
{
if
(
target
!=
null
)
{
PRESENTER_MAP
.
put
(
roomId
,
target
);
String
mappedTarget
=
"customer"
.
equals
(
target
)
?
"owner"
:
log
.
info
(
"房间 {} 投屏者更新为: {}"
,
roomId
,
target
);
"consultant"
.
equals
(
target
)
?
"participant"
:
target
;
PRESENTER_MAP
.
put
(
roomId
,
mappedTarget
);
log
.
info
(
"房间 {} 投屏者更新为: {} (来自 presenter_response 接受)"
,
roomId
,
mappedTarget
);
}
}
}
}
// 广播结果给所有人
broadcast
(
roomId
,
message
,
session
);
broadcast
(
roomId
,
message
,
session
);
}
else
{
}
else
if
(
"presenter_change"
.
equals
(
action
))
{
// presenter_change 或 presenter_revoke 直接广播
String
from
=
json
.
has
(
"from"
)
?
json
.
get
(
"from"
).
asText
()
:
null
;
String
target
=
json
.
has
(
"target"
)
?
json
.
get
(
"target"
).
asText
()
:
null
;
if
(
target
!=
null
)
{
String
mappedTarget
=
"customer"
.
equals
(
target
)
?
"owner"
:
"consultant"
.
equals
(
target
)
?
"participant"
:
target
;
// 如果 from 为空,或 from == target(自己发起),或当前无人投屏,则更新
if
(
from
==
null
||
from
.
equals
(
target
)
||
PRESENTER_MAP
.
get
(
roomId
)
==
null
)
{
PRESENTER_MAP
.
put
(
roomId
,
mappedTarget
);
log
.
info
(
"房间 {} 投屏者更新为: {} (来自 presenter_change)"
,
roomId
,
mappedTarget
);
}
}
broadcast
(
roomId
,
message
,
session
);
}
else
if
(
"presenter_revoke"
.
equals
(
action
))
{
PRESENTER_MAP
.
remove
(
roomId
);
log
.
info
(
"房间 {} 投屏者已清除"
,
roomId
);
broadcast
(
roomId
,
message
,
session
);
broadcast
(
roomId
,
message
,
session
);
}
}
return
;
return
;
...
@@ -776,12 +788,24 @@ public class CoWebSocketServer {
...
@@ -776,12 +788,24 @@ public class CoWebSocketServer {
"remote_control_stop"
.
equals
(
action
))
{
"remote_control_stop"
.
equals
(
action
))
{
if
(
"request_remote_control"
.
equals
(
action
))
{
if
(
"request_remote_control"
.
equals
(
action
))
{
// 向当前投屏者发送请求
String
presenterType
=
PRESENTER_MAP
.
get
(
roomId
);
String
presenterType
=
PRESENTER_MAP
.
get
(
roomId
);
if
(
presenterType
==
null
)
{
// 后备:从数据库加载控制者
CoSession
sessionFromDb
=
sessionService
.
getByRoomId
(
roomId
);
if
(
sessionFromDb
!=
null
)
{
String
holderType
=
sessionFromDb
.
getControlHolderType
();
if
(
holderType
!=
null
)
{
presenterType
=
holderType
;
PRESENTER_MAP
.
put
(
roomId
,
presenterType
);
log
.
info
(
"从数据库加载投屏者: roomId={}, holderType={}"
,
roomId
,
presenterType
);
}
}
}
if
(
presenterType
!=
null
)
{
if
(
presenterType
!=
null
)
{
sendToUserType
(
roomId
,
presenterType
,
message
);
sendToUserType
(
roomId
,
presenterType
,
message
);
}
else
{
}
else
{
log
.
warn
(
"房间 {} 无人投屏,忽略远程控制请求"
,
roomId
);
log
.
warn
(
"房间 {} 无人投屏,忽略远程控制请求"
,
roomId
);
sendError
(
session
,
"当前无人投屏,无法请求远程控制"
);
}
}
}
else
{
}
else
{
// response 或 stop 广播给所有人
// response 或 stop 广播给所有人
...
@@ -1021,17 +1045,32 @@ public class CoWebSocketServer {
...
@@ -1021,17 +1045,32 @@ public class CoWebSocketServer {
* 向房间内指定用户类型的所有用户发送消息(定向发送)
* 向房间内指定用户类型的所有用户发送消息(定向发送)
*/
*/
private
void
sendToUserType
(
String
roomId
,
String
targetUserType
,
String
message
)
{
private
void
sendToUserType
(
String
roomId
,
String
targetUserType
,
String
message
)
{
// 将前端传入的 customer/consultant 映射为 owner/participant
String
mappedType
=
targetUserType
;
if
(
"customer"
.
equals
(
targetUserType
))
{
mappedType
=
"owner"
;
}
else
if
(
"consultant"
.
equals
(
targetUserType
))
{
mappedType
=
"participant"
;
}
log
.
info
(
"定向发送: roomId={}, 目标类型={} (映射为 {}), 消息={}"
,
roomId
,
targetUserType
,
mappedType
,
message
);
Set
<
Session
>
sessions
=
ROOMS
.
get
(
roomId
);
Set
<
Session
>
sessions
=
ROOMS
.
get
(
roomId
);
if
(
sessions
==
null
||
sessions
.
isEmpty
())
return
;
if
(
sessions
==
null
||
sessions
.
isEmpty
())
{
log
.
warn
(
"房间 {} 无会话,无法定向发送"
,
roomId
);
return
;
}
int
count
=
0
;
for
(
Session
s
:
sessions
)
{
for
(
Session
s
:
sessions
)
{
String
userType
=
SESSION_USER_TYPE
.
get
(
s
);
String
userType
=
SESSION_USER_TYPE
.
get
(
s
);
if
(
targetUser
Type
.
equals
(
userType
)
&&
s
.
isOpen
())
{
if
(
mapped
Type
.
equals
(
userType
)
&&
s
.
isOpen
())
{
try
{
try
{
s
.
getBasicRemote
().
sendText
(
message
);
s
.
getBasicRemote
().
sendText
(
message
);
count
++;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
warn
(
"
发送消息给用户类型 {} 失败: {}"
,
targetUserType
,
e
.
getMessage
());
log
.
warn
(
"
向用户 {} 发送消息失败: {}"
,
s
.
getId
()
,
e
.
getMessage
());
}
}
}
}
}
}
log
.
info
(
"定向发送给 {} (映射为 {}),共 {} 个会话"
,
targetUserType
,
mappedType
,
count
);
}
}
}
}
\ No newline at end of file
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