[*] 日常优化
This commit is contained in:
@@ -1048,6 +1048,38 @@ class Taoyao extends RemoteClient {
|
|||||||
me.push(protocol.buildMessage("client::close", {}));
|
me.push(protocol.buildMessage("client::close", {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns 媒体服务列表
|
||||||
|
*/
|
||||||
|
async mediaList() {
|
||||||
|
const response = await this.request(protocol.buildMessage("client::list", {
|
||||||
|
clientType: "MEDIA"
|
||||||
|
}));
|
||||||
|
return response.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns 媒体终端列表
|
||||||
|
*/
|
||||||
|
async mediaClientList() {
|
||||||
|
const response = await this.request(protocol.buildMessage("client::list", {}));
|
||||||
|
return response.body.filter(v => {
|
||||||
|
return v.clientType === "WEB" || v.clientType === "CAMERA" || v.clientType === "MOBILE";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} clientType 终端类型(默认所有)
|
||||||
|
*
|
||||||
|
* @returns 终端列表
|
||||||
|
*/
|
||||||
|
async clientList(clientType) {
|
||||||
|
const response = await this.request(protocol.buildMessage("client::list", {
|
||||||
|
clientType
|
||||||
|
}));
|
||||||
|
return response.body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 终端配置信令
|
* 终端配置信令
|
||||||
*
|
*
|
||||||
@@ -2090,28 +2122,6 @@ class Taoyao extends RemoteClient {
|
|||||||
return response.body;
|
return response.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns 媒体服务列表
|
|
||||||
*/
|
|
||||||
async mediaList() {
|
|
||||||
const response = await this.request(protocol.buildMessage("client::list", {
|
|
||||||
clientType: "MEDIA"
|
|
||||||
}));
|
|
||||||
return response.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {*} clientType 终端类型(默认所有)
|
|
||||||
*
|
|
||||||
* @returns 终端列表
|
|
||||||
*/
|
|
||||||
async clientList(clientType) {
|
|
||||||
const response = await this.request(protocol.buildMessage("client::list", {
|
|
||||||
clientType
|
|
||||||
}));
|
|
||||||
return response.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {*} clientId 终端ID
|
* @param {*} clientId 终端ID
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -68,7 +68,12 @@ public interface Client extends AutoCloseable {
|
|||||||
/**
|
/**
|
||||||
* @return 授权是否超时
|
* @return 授权是否超时
|
||||||
*/
|
*/
|
||||||
boolean timeout();
|
boolean authorizeTimeout();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 心跳是否超时
|
||||||
|
*/
|
||||||
|
boolean heartbeatTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置授权
|
* 设置授权
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.acgist.taoyao.signal.client;
|
package com.acgist.taoyao.signal.client;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@@ -140,10 +142,16 @@ public abstract class ClientAdapter<T extends AutoCloseable> implements Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean timeout() {
|
public boolean authorizeTimeout() {
|
||||||
return System.currentTimeMillis() - this.time > this.timeout;
|
return System.currentTimeMillis() - this.time > this.timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean heartbeatTimeout() {
|
||||||
|
final LocalDateTime last = this.status.getLastHeartbeat();
|
||||||
|
return Duration.between(last, LocalDateTime.now()).getSeconds() >= this.timeout * 60;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void authorize(String clientId) {
|
public void authorize(String clientId) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
|
|||||||
@@ -220,8 +220,13 @@ public class ClientManager {
|
|||||||
private void closeTimeout() {
|
private void closeTimeout() {
|
||||||
final int oldSize = this.clients.size();
|
final int oldSize = this.clients.size();
|
||||||
this.clients.stream()
|
this.clients.stream()
|
||||||
.filter(v -> v.unauthorized())
|
.filter(v -> {
|
||||||
.filter(v -> v.timeout())
|
if(v.unauthorized()) {
|
||||||
|
return v.authorizeTimeout();
|
||||||
|
} else {
|
||||||
|
return v.heartbeatTimeout();
|
||||||
|
}
|
||||||
|
})
|
||||||
.forEach(v -> {
|
.forEach(v -> {
|
||||||
log.debug("关闭超时终端:{}", v);
|
log.debug("关闭超时终端:{}", v);
|
||||||
this.close(v);
|
this.close(v);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class ClientStatus {
|
|||||||
@Schema(title = "终端配置", description = "其他扩展终端配置")
|
@Schema(title = "终端配置", description = "其他扩展终端配置")
|
||||||
private Map<String, Object> config = new HashMap<>();
|
private Map<String, Object> config = new HashMap<>();
|
||||||
@Schema(title = "最后心跳时间", description = "最后心跳时间")
|
@Schema(title = "最后心跳时间", description = "最后心跳时间")
|
||||||
private LocalDateTime lastHeartbeat;
|
private LocalDateTime lastHeartbeat = LocalDateTime.now();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拷贝属性
|
* 拷贝属性
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
"battery" : 电池电量(0~100),
|
"battery" : 电池电量(0~100),
|
||||||
"alarming" : 是否发生告警(true|false),
|
"alarming" : 是否发生告警(true|false),
|
||||||
"charging" : 是否正在充电(true|false),
|
"charging" : 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat" : "最后心跳时间",
|
"lastHeartbeat" : "最后心跳时间",
|
||||||
"status" : {更多状态},
|
"status" : {更多状态},
|
||||||
"config" : {更多配置}
|
"config" : {更多配置}
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
"battery" : 电池电量(0~100),
|
"battery" : 电池电量(0~100),
|
||||||
"alarming" : 是否发生告警(true|false),
|
"alarming" : 是否发生告警(true|false),
|
||||||
"charging" : 是否正在充电(true|false),
|
"charging" : 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat" : "最后心跳时间",
|
"lastHeartbeat" : "最后心跳时间",
|
||||||
"status" : {更多状态},
|
"status" : {更多状态},
|
||||||
"config" : {更多配置}
|
"config" : {更多配置}
|
||||||
@@ -51,7 +52,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
},
|
},
|
||||||
flow = "终端->信令服务->终端"
|
flow = "终端=>信令服务->终端"
|
||||||
)
|
)
|
||||||
public class ClientListProtocol extends ProtocolClientAdapter {
|
public class ClientListProtocol extends ProtocolClientAdapter {
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
"battery": 电池电量(0~100),
|
"battery": 电池电量(0~100),
|
||||||
"alarming": 是否发生告警(true|false),
|
"alarming": 是否发生告警(true|false),
|
||||||
"charging": 是否正在充电(true|false),
|
"charging": 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat": "最后心跳时间",
|
"lastHeartbeat": "最后心跳时间",
|
||||||
"status": {更多状态},
|
"status": {更多状态},
|
||||||
"config": {更多配置}
|
"config": {更多配置}
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
"battery": 电池电量(0~100),
|
"battery": 电池电量(0~100),
|
||||||
"alarming": 是否发生告警(true|false),
|
"alarming": 是否发生告警(true|false),
|
||||||
"charging": 是否正在充电(true|false),
|
"charging": 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat": "最后心跳时间",
|
"lastHeartbeat": "最后心跳时间",
|
||||||
"status": {更多状态},
|
"status": {更多状态},
|
||||||
"config": {更多配置}
|
"config": {更多配置}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
"battery": 电池电量(0~100),
|
"battery": 电池电量(0~100),
|
||||||
"alarming": 是否发生告警(true|false),
|
"alarming": 是否发生告警(true|false),
|
||||||
"charging": 是否正在充电(true|false),
|
"charging": 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat": "最后心跳时间",
|
"lastHeartbeat": "最后心跳时间",
|
||||||
"status": {更多状态},
|
"status": {更多状态},
|
||||||
"config": {更多配置}
|
"config": {更多配置}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
"battery": 电池电量(0~100),
|
"battery": 电池电量(0~100),
|
||||||
"alarming": 是否发生告警(true|false),
|
"alarming": 是否发生告警(true|false),
|
||||||
"charging": 是否正在充电(true|false),
|
"charging": 是否正在充电(true|false),
|
||||||
"recording": 是否正在录像(true|false),
|
"clientRecording": 是否正在录像(true|false),
|
||||||
|
"serverRecording": 是否正在录像(true|false),
|
||||||
"lastHeartbeat": "最后心跳时间",
|
"lastHeartbeat": "最后心跳时间",
|
||||||
"status": {更多状态},
|
"status": {更多状态},
|
||||||
"config": {更多配置}
|
"config": {更多配置}
|
||||||
|
|||||||
Reference in New Issue
Block a user