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