[*] 日常优化
This commit is contained in:
@@ -37,5 +37,6 @@
|
||||
* 存在TURN服务优先使用
|
||||
* 安卓关闭视频没有删除预览
|
||||
* 浏览器WebRTC监控页面关闭:`chrome://webrtc-internals/`
|
||||
* me -> this
|
||||
|
||||
## 完成任务
|
||||
|
||||
@@ -885,6 +885,12 @@ class Taoyao extends RemoteClient {
|
||||
case "platform::error":
|
||||
me.callbackError(message);
|
||||
break;
|
||||
case "platform::reboot":
|
||||
me.defaultPlatformReboot(message);
|
||||
break;
|
||||
case "platform::shutdown":
|
||||
me.defaultPlatformShutdown(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1954,6 +1960,55 @@ class Taoyao extends RemoteClient {
|
||||
console.debug("视频方向变化信令", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台信令
|
||||
*
|
||||
* @returns 响应
|
||||
*/
|
||||
async platformReboot() {
|
||||
return await this.request(protocol.buildMessage("platform::reboot", {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台信令
|
||||
*
|
||||
* @param {*} message 信令消息
|
||||
*/
|
||||
defaultPlatformReboot(message) {
|
||||
console.debug("平台重启", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令信令
|
||||
*
|
||||
* @param {*} script 命令
|
||||
*
|
||||
* @returns 响应
|
||||
*/
|
||||
async platformScript(script) {
|
||||
return await this.request(protocol.buildMessage("platform::script", {
|
||||
script
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台信令
|
||||
*
|
||||
* @returns 响应
|
||||
*/
|
||||
async platformShutdown() {
|
||||
return await this.request(protocol.buildMessage("platform::shutdown", {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台信令
|
||||
*
|
||||
* @param {*} message 信令消息
|
||||
*/
|
||||
defaultPlatformShutdown(message) {
|
||||
console.debug("平台关闭", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费媒体信令
|
||||
*
|
||||
|
||||
@@ -20,53 +20,53 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
||||
)
|
||||
public class PlatformErrorProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "platform::error";
|
||||
|
||||
/**
|
||||
* 绑定线程请求ID
|
||||
*/
|
||||
private ThreadLocal<Long> idLocal = new InheritableThreadLocal<>();
|
||||
|
||||
public PlatformErrorProtocol() {
|
||||
super("平台异常信令", SIGNAL);
|
||||
}
|
||||
public static final String SIGNAL = "platform::error";
|
||||
|
||||
/**
|
||||
* 绑定线程请求ID
|
||||
*/
|
||||
private ThreadLocal<Long> idLocal = new InheritableThreadLocal<>();
|
||||
|
||||
public PlatformErrorProtocol() {
|
||||
super("平台异常信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message build(Long id, MessageCode messageCode, String message, Object body) {
|
||||
final Long oldId = this.idLocal.get();
|
||||
if(oldId == null) {
|
||||
id = this.idService.buildId();
|
||||
} else {
|
||||
id = oldId;
|
||||
this.idLocal.remove();
|
||||
}
|
||||
// 默认设置失败状态
|
||||
return super.build(id, messageCode == null ? MessageCode.CODE_9999 : messageCode, message, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 请求ID
|
||||
*/
|
||||
public void set(Long id) {
|
||||
this.idLocal.set(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e 异常
|
||||
*
|
||||
* @return 异常消息
|
||||
*/
|
||||
public Message build(Exception e) {
|
||||
final Message message = super.build();
|
||||
final String exceptionMessage = e.getMessage();
|
||||
if(e instanceof MessageCodeException messageCodeException) {
|
||||
// 自定义的异常
|
||||
message.setCode(messageCodeException.getMessageCode(), messageCodeException.getMessage());
|
||||
} else if(StringUtils.isNotEmpty(exceptionMessage) && exceptionMessage.length() <= Byte.MAX_VALUE) {
|
||||
// 少量信息返回异常信息
|
||||
message.setMessage(exceptionMessage);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message build(Long id, MessageCode messageCode, String message, Object body) {
|
||||
final Long oldId = this.idLocal.get();
|
||||
if(oldId == null) {
|
||||
id = this.idService.buildId();
|
||||
} else {
|
||||
id = oldId;
|
||||
this.idLocal.remove();
|
||||
}
|
||||
// 默认设置失败状态
|
||||
return super.build(id, messageCode == null ? MessageCode.CODE_9999 : messageCode, message, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 请求ID
|
||||
*/
|
||||
public void set(Long id) {
|
||||
this.idLocal.set(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e 异常
|
||||
*
|
||||
* @return 异常消息
|
||||
*/
|
||||
public Message build(Exception e) {
|
||||
final Message message = super.build();
|
||||
final String exceptionMessage = e.getMessage();
|
||||
if(e instanceof MessageCodeException messageCodeException) {
|
||||
// 自定义的异常
|
||||
message.setCode(messageCodeException.getMessageCode(), messageCodeException.getMessage());
|
||||
} else if(StringUtils.isNotEmpty(exceptionMessage) && exceptionMessage.length() <= Byte.MAX_VALUE) {
|
||||
// 少量信息返回异常信息
|
||||
message.setMessage(exceptionMessage);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,37 +26,37 @@ import lombok.extern.slf4j.Slf4j;
|
||||
)
|
||||
public class PlatformRebootProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "platform::reboot";
|
||||
|
||||
private final ScriptProperties scriptProperties;
|
||||
|
||||
public PlatformRebootProtocol(ScriptProperties scriptProperties) {
|
||||
super("重启平台信令", SIGNAL);
|
||||
this.scriptProperties = scriptProperties;
|
||||
}
|
||||
public static final String SIGNAL = "platform::reboot";
|
||||
|
||||
private final ScriptProperties scriptProperties;
|
||||
|
||||
public PlatformRebootProtocol(ScriptProperties scriptProperties) {
|
||||
super("重启平台信令", SIGNAL);
|
||||
this.scriptProperties = scriptProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
log.info("重启平台:{}", clientId);
|
||||
this.reboot(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台
|
||||
*/
|
||||
public void execute() {
|
||||
log.info("重启平台");
|
||||
this.reboot(this.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
private void reboot(Message message) {
|
||||
this.clientManager.broadcast(message);
|
||||
ScriptUtils.execute(this.scriptProperties.getPlatformReboot());
|
||||
}
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
log.info("重启平台:{}", clientId);
|
||||
this.reboot(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台
|
||||
*/
|
||||
public void execute() {
|
||||
log.info("重启平台");
|
||||
this.reboot(this.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启平台
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
private void reboot(Message message) {
|
||||
this.clientManager.broadcast(message);
|
||||
ScriptUtils.execute(this.scriptProperties.getPlatformReboot());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,28 +33,28 @@ import lombok.extern.slf4j.Slf4j;
|
||||
}
|
||||
"""
|
||||
},
|
||||
flow = "终端->信令服务->终端"
|
||||
flow = "终端=>信令服务"
|
||||
)
|
||||
public class PlatformScriptProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "platform::script";
|
||||
|
||||
public PlatformScriptProtocol() {
|
||||
super("执行命令信令", SIGNAL);
|
||||
}
|
||||
public static final String SIGNAL = "platform::script";
|
||||
|
||||
public PlatformScriptProtocol() {
|
||||
super("执行命令信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
final String script = MapUtils.get(body, Constant.SCRIPT);
|
||||
final ScriptExecutor executor = ScriptUtils.execute(script);
|
||||
final String result = executor.getResult();
|
||||
log.info("""
|
||||
执行终端:{}
|
||||
执行命令:{}
|
||||
执行结果:{}
|
||||
""", clientId, script, result);
|
||||
message.setBody(Map.of(Constant.RESULT, result));
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
final String script = MapUtils.get(body, Constant.SCRIPT);
|
||||
final ScriptExecutor executor = ScriptUtils.execute(script);
|
||||
final String result = executor.getResult();
|
||||
log.info("""
|
||||
执行终端:{}
|
||||
执行命令:{}
|
||||
执行结果:{}
|
||||
""", clientId, script, result);
|
||||
message.setBody(Map.of(Constant.RESULT, result));
|
||||
client.push(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,36 +28,36 @@ import lombok.extern.slf4j.Slf4j;
|
||||
)
|
||||
public class PlatformShutdownProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "platform::shutdown";
|
||||
|
||||
private final ScriptProperties scriptProperties;
|
||||
|
||||
public PlatformShutdownProtocol(ScriptProperties scriptProperties) {
|
||||
super("关闭平台信令", SIGNAL);
|
||||
this.scriptProperties = scriptProperties;
|
||||
}
|
||||
public static final String SIGNAL = "platform::shutdown";
|
||||
|
||||
private final ScriptProperties scriptProperties;
|
||||
|
||||
public PlatformShutdownProtocol(ScriptProperties scriptProperties) {
|
||||
super("关闭平台信令", SIGNAL);
|
||||
this.scriptProperties = scriptProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
log.info("关闭平台:{}", clientId);
|
||||
this.shutdown(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台
|
||||
*/
|
||||
public void execute() {
|
||||
log.info("关闭平台");
|
||||
this.shutdown(this.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
private void shutdown(Message message) {
|
||||
this.clientManager.broadcast(message);
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
log.info("关闭平台:{}", clientId);
|
||||
this.shutdown(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台
|
||||
*/
|
||||
public void execute() {
|
||||
log.info("关闭平台");
|
||||
this.shutdown(this.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭平台
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
private void shutdown(Message message) {
|
||||
this.clientManager.broadcast(message);
|
||||
if(this.applicationContext instanceof ConfigurableApplicationContext context) {
|
||||
// API关闭
|
||||
if(context.isActive()) {
|
||||
@@ -70,6 +70,6 @@ public class PlatformShutdownProtocol extends ProtocolClientAdapter {
|
||||
// 命令关闭
|
||||
ScriptUtils.execute(this.scriptProperties.getPlatformShutdown());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user