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

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,8 +70,6 @@ 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) { if(baseSession instanceof UserSession) {
log.info("推送Box播放音乐"); log.info("推送Box播放音乐");
BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn()); BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn());
@ -89,12 +87,10 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand
}else{ }else{
log.info("设备sn{}不在线,无法播放", baseSession.getSn()); log.info("设备sn{}不在线,无法播放", baseSession.getSn());
resp.setText("设备不在线,无法播放"); resp.setText("设备不在线,无法播放");
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
//去掉内存中音乐同步对象
baseSession.setMusic(null); baseSession.setMusic(null);
}else{ resp.setMusic(null);
baseSession.setMusic(resp.getMusic()); resp.setType(AskTypeEnum.TTS.getCode());
}
} }
}else{//果box的 }else{//果box的
//记录音乐状态 //记录音乐状态
@ -107,6 +103,7 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand
userSession.setMusic(null); userSession.setMusic(null);
}else{ }else{
baseSession.setMusic(resp.getMusic()); baseSession.setMusic(resp.getMusic());
userSession.setMusic(resp.getMusic());
} }
//如果在线推送用户端 //如果在线推送用户端
}else{ }else{
@ -116,8 +113,8 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand
baseSession.setMusic(resp.getMusic()); 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
*/ */