优化客户端音乐播放推送规则

This commit is contained in:
wulin 2023-10-28 23:17:33 +08:00
parent 18647a3951
commit 0e1a4d830a
2 changed files with 43 additions and 46 deletions

View File

@ -70,54 +70,51 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand
} }
protected Mono<Boolean> sendMessage(Action action, BaseSession baseSession, BaseMessageResp resp){ protected Mono<Boolean> sendMessage(Action action, BaseSession baseSession, BaseMessageResp resp){
return baseWebSocketService.sendMessage(action, baseSession, resp).map(b -> { if(baseSession instanceof UserSession) {
//客户端推送的 log.info("推送Box播放音乐");
if(baseSession instanceof UserSession) { BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn());
log.info("推送Box播放音乐"); if(boxSession != null){
BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn()); baseWebSocketService.sendMsg(boxSession, resp);
if(boxSession != null){ //记录音乐状态
baseWebSocketService.sendMsg(boxSession, resp); if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
//记录音乐状态 //去掉内存中音乐同步对象
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ boxSession.setMusic(null);
//去掉内存中音乐同步对象 baseSession.setMusic(null);
boxSession.setMusic(null);
baseSession.setMusic(null);
}else{
boxSession.setMusic(resp.getMusic());
baseSession.setMusic(resp.getMusic());
}
}else{ }else{
log.info("设备sn{}不在线,无法播放", baseSession.getSn()); boxSession.setMusic(resp.getMusic());
resp.setText("设备不在线,无法播放"); baseSession.setMusic(resp.getMusic());
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
//去掉内存中音乐同步对象
baseSession.setMusic(null);
}else{
baseSession.setMusic(resp.getMusic());
}
} }
}else{//果box的 }else{
//记录音乐状态 log.info("设备sn{}不在线,无法播放", baseSession.getSn());
BaseSession userSession = baseWebSocketService.getUserSessionWithUserId(baseSession.getUserId()); resp.setText("设备不在线,无法播放");
//记录音乐状态 baseSession.setMusic(null);
//去掉内存中音乐同步对象 resp.setMusic(null);
if(userSession != null){ resp.setType(AskTypeEnum.TTS.getCode());
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
baseSession.setMusic(null); }
userSession.setMusic(null); }else{//果box的
}else{ //记录音乐状态
baseSession.setMusic(resp.getMusic()); BaseSession userSession = baseWebSocketService.getUserSessionWithUserId(baseSession.getUserId());
} //记录音乐状态
//如果在线推送用户端 //去掉内存中音乐同步对象
if(userSession != null){
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
baseSession.setMusic(null);
userSession.setMusic(null);
}else{ }else{
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ baseSession.setMusic(resp.getMusic());
baseSession.setMusic(null); userSession.setMusic(resp.getMusic());
}else{ }
baseSession.setMusic(resp.getMusic()); //如果在线推送用户端
} }else{
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
baseSession.setMusic(null);
}else{
baseSession.setMusic(resp.getMusic());
} }
} }
return b;
}); }
return baseWebSocketService.sendMessage(action, baseSession, resp);
} }
} }

View File

@ -16,7 +16,7 @@ public class BaseSession {
/*** /***
* 设备序列号 * 设备序列号
*/ */
protected String sn; protected String sn = "";
protected WebSocketSession session; protected WebSocketSession session;
protected FluxSink<WebSocketMessage> sink; protected FluxSink<WebSocketMessage> sink;
@ -32,7 +32,7 @@ public class BaseSession {
/*** /***
* 用户id * 用户id
*/ */
protected Long userId; protected Long userId = 0L;
/*** /***
* 当前使用的BoxId如果未绑定那么就是0 * 当前使用的BoxId如果未绑定那么就是0
*/ */