增加返回listen,方便客户端控制是否聆听

This commit is contained in:
wulin 2023-11-15 19:37:18 +08:00
parent b42ed0826f
commit 0034eb6767
6 changed files with 22 additions and 2 deletions

View File

@ -64,7 +64,7 @@ public class TimeActionCommand extends ActionCommand implements IActionCommand{
resp.setText(action.getAsk().replaceAll(action.getAction(), getDayOfWeek(action.getTime().getDetailTime().getLocalDateTime().format(df)))); resp.setText(action.getAsk().replaceAll(action.getAction(), getDayOfWeek(action.getTime().getDetailTime().getLocalDateTime().format(df))));
resp.setTime(dateTimeResp); resp.setTime(dateTimeResp);
return baseWebSocketService.sendMessage( return baseWebSocketService.send .Message(
action, action,
baseSession, baseSession,
resp); resp);

View File

@ -14,6 +14,11 @@ public class BaseMessageResp {
*/ */
protected String text; protected String text;
/**
* 播放完成后是否继续聆听 1聆听 0不聆听需要唤醒
*/
protected Integer listen = 1;
/** /**
* 在线播放音乐信息 * 在线播放音乐信息

View File

@ -8,6 +8,10 @@ import reactor.core.publisher.FluxSink;
@Data @Data
public class BaseSession { public class BaseSession {
/**
* 透传给box是否继续聆听 1 0:不聆听需要唤醒
*/
Integer listen = 1;
/** /**
* session类型0 box 1 用户 * session类型0 box 1 用户
*/ */

View File

@ -11,4 +11,8 @@ public class BoxSession extends BaseSession {
* 阿里token * 阿里token
*/ */
String aliToken; String aliToken;
/**
*
*/
} }

View File

@ -172,6 +172,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
return Mono.empty(); return Mono.empty();
}else{ }else{
boxTalkMessage.setMessage(alarm.getAction()); boxTalkMessage.setMessage(alarm.getAction());
boxSession.setListen(YesNo.NO.getCode());
return processMessage(boxSession, boxTalkMessage); return processMessage(boxSession, boxTalkMessage);
} }
}); });

View File

@ -153,10 +153,12 @@ public class BaseWebSocketService {
BaseMessageResp resp = new BaseMessageResp(); BaseMessageResp resp = new BaseMessageResp();
resp.setType(type); resp.setType(type);
resp.setText(message); resp.setText(message);
resp.setListen(baseSession.getListen());
return sendMessage(action, baseSession, resp); return sendMessage(action, baseSession, resp);
} }
public Mono<Boolean> sendMessage(Action action, BaseSession baseSession, BaseMessageResp resp){ public Mono<Boolean> sendMessage(Action action, BaseSession baseSession, BaseMessageResp resp){
resp.setListen(baseSession.getListen());
DeviceUserTalkRecordEntity talkRecord = new DeviceUserTalkRecordEntity(); DeviceUserTalkRecordEntity talkRecord = new DeviceUserTalkRecordEntity();
talkRecord.setAskType(resp.getType()); talkRecord.setAskType(resp.getType());
talkRecord.setAskValue(action.getAsk()); talkRecord.setAskValue(action.getAsk());
@ -194,6 +196,7 @@ public class BaseWebSocketService {
BoxMessageResp resp = new BoxMessageResp(); BoxMessageResp resp = new BoxMessageResp();
resp.setType(type); resp.setType(type);
resp.setText(message); resp.setText(message);
resp.setListen(baseSession.getListen());
sendMsg(baseSession, resp); sendMsg(baseSession, resp);
} }
@ -202,7 +205,7 @@ public class BaseWebSocketService {
resp.setType(type); resp.setType(type);
resp.setText(message); resp.setText(message);
resp.getTts().setStatus(finish); resp.getTts().setStatus(finish);
resp.setListen(baseSession.getListen());
return sendMsgWithMono(baseSession, resp); return sendMsgWithMono(baseSession, resp);
} }
@ -266,6 +269,7 @@ public class BaseWebSocketService {
BoxMessageResp boxMessageResp = new BoxMessageResp(); BoxMessageResp boxMessageResp = new BoxMessageResp();
BeanUtils.copyProperties(baseMessageResp, boxMessageResp); BeanUtils.copyProperties(baseMessageResp, boxMessageResp);
boxMessageResp.setText(text); boxMessageResp.setText(text);
boxMessageResp.setListen(baseSession.getListen());
return sendAudioMessage(baseSession, boxMessageResp).flatMap(s -> { return sendAudioMessage(baseSession, boxMessageResp).flatMap(s -> {
return Mono.just(true); return Mono.just(true);
}); });
@ -299,6 +303,7 @@ public class BaseWebSocketService {
BoxMessageResp boxMessageResp = new BoxMessageResp(); BoxMessageResp boxMessageResp = new BoxMessageResp();
BeanUtils.copyProperties(baseMessageResp, boxMessageResp); BeanUtils.copyProperties(baseMessageResp, boxMessageResp);
boxMessageResp.setText(text); boxMessageResp.setText(text);
boxMessageResp.setListen(baseSession.getListen());
sendAudioMessage(baseSession, boxMessageResp).subscribe(); sendAudioMessage(baseSession, boxMessageResp).subscribe();
} }
return; return;
@ -344,6 +349,7 @@ public class BaseWebSocketService {
BeanUtils.copyProperties(baseMessageResp, boxMessageResp); BeanUtils.copyProperties(baseMessageResp, boxMessageResp);
boxMessageResp.setText(message); boxMessageResp.setText(message);
boxMessageResp.getTts().setStatus(status); boxMessageResp.getTts().setStatus(status);
boxMessageResp.setListen(baseSession.getListen());
return sendAudioMessage(baseSession, boxMessageResp).flatMap(s -> { return sendAudioMessage(baseSession, boxMessageResp).flatMap(s -> {
return sendAudioMessage(baseSession, baseMessageResp, builder, text, m, length, requestId); return sendAudioMessage(baseSession, baseMessageResp, builder, text, m, length, requestId);
}); });