diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java index dd769d5..8ab48c8 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java @@ -70,54 +70,51 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand } protected Mono sendMessage(Action action, BaseSession baseSession, BaseMessageResp resp){ - return baseWebSocketService.sendMessage(action, baseSession, resp).map(b -> { - //客户端推送的 - if(baseSession instanceof UserSession) { - log.info("推送Box播放音乐"); - BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn()); - if(boxSession != null){ - baseWebSocketService.sendMsg(boxSession, resp); - //记录音乐状态 - if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ - //去掉内存中音乐同步对象 - boxSession.setMusic(null); - baseSession.setMusic(null); - }else{ - boxSession.setMusic(resp.getMusic()); - baseSession.setMusic(resp.getMusic()); - } + if(baseSession instanceof UserSession) { + log.info("推送Box播放音乐"); + BoxSession boxSession = baseWebSocketService.getBoxSessionWithSn(baseSession.getSn()); + if(boxSession != null){ + baseWebSocketService.sendMsg(boxSession, resp); + //记录音乐状态 + if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ + //去掉内存中音乐同步对象 + boxSession.setMusic(null); + baseSession.setMusic(null); }else{ - log.info("设备sn:{}不在线,无法播放", baseSession.getSn()); - resp.setText("设备不在线,无法播放"); - if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ - //去掉内存中音乐同步对象 - baseSession.setMusic(null); - }else{ - baseSession.setMusic(resp.getMusic()); - } + boxSession.setMusic(resp.getMusic()); + baseSession.setMusic(resp.getMusic()); } - }else{//果box的 - //记录音乐状态 - BaseSession userSession = baseWebSocketService.getUserSessionWithUserId(baseSession.getUserId()); - //记录音乐状态 - //去掉内存中音乐同步对象 - if(userSession != null){ - if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ - baseSession.setMusic(null); - userSession.setMusic(null); - }else{ - baseSession.setMusic(resp.getMusic()); - } - //如果在线推送用户端 + }else{ + log.info("设备sn:{}不在线,无法播放", baseSession.getSn()); + resp.setText("设备不在线,无法播放"); + baseSession.setMusic(null); + resp.setMusic(null); + resp.setType(AskTypeEnum.TTS.getCode()); + + } + }else{//果box的 + //记录音乐状态 + BaseSession userSession = baseWebSocketService.getUserSessionWithUserId(baseSession.getUserId()); + //记录音乐状态 + //去掉内存中音乐同步对象 + if(userSession != null){ + if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ + baseSession.setMusic(null); + userSession.setMusic(null); }else{ - if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){ - baseSession.setMusic(null); - }else{ - baseSession.setMusic(resp.getMusic()); - } + baseSession.setMusic(resp.getMusic()); + userSession.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); } } diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/BaseSession.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/BaseSession.java index e109463..6c78d77 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/BaseSession.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/BaseSession.java @@ -16,7 +16,7 @@ public class BaseSession { /*** * 设备序列号 */ - protected String sn; + protected String sn = ""; protected WebSocketSession session; protected FluxSink sink; @@ -32,7 +32,7 @@ public class BaseSession { /*** * 用户id */ - protected Long userId; + protected Long userId = 0L; /*** * 当前使用的BoxId,如果未绑定,那么就是0 */