[+] 设备录像状态

This commit is contained in:
acgist
2023-06-11 09:06:33 +08:00
parent 0908996fb0
commit b19579a666
11 changed files with 71 additions and 18 deletions

View File

@@ -689,7 +689,7 @@ public final class Taoyao implements ITaoyao {
"signal", this.signal(),
"battery", this.battery(),
"charging", this.charging(),
"recording", this.mediaManager.isRecording()
"clientRecording", this.mediaManager.isRecording()
));
}
@@ -718,12 +718,12 @@ public final class Taoyao implements ITaoyao {
"clientType", this.clientType,
"username", this.username,
"password", this.password,
"latitude", location == null ? -1 : location.getLatitude(),
"longitude", location == null ? -1 : location.getLongitude(),
"signal", this.signal(),
"battery", this.battery(),
"charging", this.charging(),
"recording", this.mediaManager.isRecording()
"latitude", location == null ? -1 : location.getLatitude(),
"longitude", location == null ? -1 : location.getLongitude(),
"signal", this.signal(),
"battery", this.battery(),
"charging", this.charging(),
"clientRecording", this.mediaManager.isRecording()
));
}

View File

@@ -5,3 +5,7 @@
* [mediasoup-client源码](https://github.com/versatica/mediasoup-client)
* [mediasoup-client文档](https://mediasoup.org/documentation/v3/mediasoup-client)
* [mediasoup-client接口](https://mediasoup.org/documentation/v3/mediasoup-client/api)
## 状态维护
`Web`终端并未对整个终端列表以及状态进行维护,所以需要开发者自己实现。

View File

@@ -149,8 +149,8 @@ export default {
window.taoyao = me.taoyao;
},
async loadList() {
this.rooms = await this.taoyao.roomList();
this.medias = await this.taoyao.mediaList();
this.rooms = await this.taoyao.roomList();
this.medias = await this.taoyao.mediaList();
this.clients = await this.taoyao.clientList();
},
async roomLeave() {

View File

@@ -76,6 +76,9 @@ export default {
this.audio = this.$refs.audio;
this.video = this.$refs.video;
this.client.proxy = this;
const status = this.taoyao.clientStatus(this.client.clientId);
this.clientRecord = status.clientRecording;
this.serverRecord = status.serverRecording;
},
props: {
"client": {

View File

@@ -74,6 +74,9 @@ export default {
this.audio = this.$refs.audio;
this.video = this.$refs.video;
this.client.proxy = this;
const status = this.taoyao.clientStatus(this.client.clientId);
this.clientRecord = status.clientRecording;
this.serverRecord = status.serverRecording;
},
props: {
"client": {

View File

@@ -403,12 +403,16 @@ class RemoteClient {
audioTrack;
// 视频Track
videoTrack;
// 终端录制状态
clientRecording;
// 服务端录制状态
serverRecording;
constructor({
name,
clientId,
}) {
this.name = name;
this.name = name;
this.clientId = clientId;
}
@@ -1761,9 +1765,16 @@ class Taoyao extends RemoteClient {
);
return response.body;
}
async clientList() {
async clientStatus(clientId) {
const response = await this.request(
protocol.buildMessage("client::list", { roomId: self.roomId })
protocol.buildMessage("client::list", { clientId })
);
return response.body;
}
async roomClientList() {
const me = this;
const response = await this.request(
protocol.buildMessage("room::client::list", { roomId: me.roomId })
);
return response.body;
}

View File

@@ -58,9 +58,13 @@ public interface Constant {
*/
String CHARGING = "charging";
/**
* 是否正在录像
* 终端是否正在录像
*/
String RECORDING = "recording";
String CLIENT_RECORDING = "clientRecording";
/**
* 服务端是否正在录像
*/
String SERVER_RECORDING = "serverRecording";
/**
* 地址
*/

View File

@@ -45,8 +45,10 @@ public class ClientStatus {
private Boolean alarming;
@Schema(title = "是否正在充电", description = "是否正在充电")
private Boolean charging;
@Schema(title = "是否正在录像", description = "是否正在录像")
private Boolean recording;
@Schema(title = "终端是否正在录像", description = "终端是否正在录像")
private Boolean clientRecording;
@Schema(title = "服务端是否正在录像", description = "服务端是否正在录像")
private Boolean serverRecording;
@Schema(title = "最后心跳时间", description = "最后心跳时间")
private LocalDateTime lastHeartbeat;
@Schema(title = "终端状态", description = "其他扩展终端状态")
@@ -68,7 +70,7 @@ public class ClientStatus {
this.setBattery(MapUtils.getInteger(body, Constant.BATTERY));
this.setAlarming(MapUtils.getBoolean(body, Constant.ALARMING));
this.setCharging(MapUtils.getBoolean(body, Constant.CHARGING));
this.setRecording(MapUtils.getBoolean(body, Constant.RECORDING));
this.setClientRecording(MapUtils.getBoolean(body, Constant.CLIENT_RECORDING));
this.status(MapUtils.get(body, Constant.STATUS));
this.config(MapUtils.get(body, Constant.CONFIG));
this.setLastHeartbeat(LocalDateTime.now());

View File

@@ -168,6 +168,7 @@ public class Recorder {
this.thread.setDaemon(true);
this.thread.setName("TaoyaoRecord");
this.thread.start();
this.updateRecordStatus(true);
log.info("开始媒体录像:{}", this.folder);
}
@@ -276,6 +277,7 @@ public class Recorder {
this.scriptExecutor.stop("q");
this.preview();
this.duration();
this.updateRecordStatus(false);
}
/**
@@ -284,5 +286,14 @@ public class Recorder {
public void close() {
EventPublisher.publishEvent(new RecorderCloseEvent(this));
}
/**
* 更新录像状态
*
* @param status 状态
*/
private void updateRecordStatus(boolean status) {
this.clientWrapper.getClient().status().setServerRecording(status);
}
}

View File

@@ -6,6 +6,7 @@ import com.acgist.taoyao.boot.annotation.Description;
import com.acgist.taoyao.boot.annotation.Protocol;
import com.acgist.taoyao.boot.config.Constant;
import com.acgist.taoyao.boot.model.Message;
import com.acgist.taoyao.boot.utils.MapUtils;
import com.acgist.taoyao.signal.client.Client;
import com.acgist.taoyao.signal.client.ClientType;
import com.acgist.taoyao.signal.protocol.ProtocolControlAdapter;
@@ -46,6 +47,7 @@ public class ControlClientRecordProtocol extends ProtocolControlAdapter {
@Override
public void execute(String clientId, ClientType clientType, Client client, Client targetClient, Message message, Map<String, Object> body) {
this.updateRecordStatus(targetClient, MapUtils.getBoolean(body, Constant.ENABLED));
client.push(targetClient.request(message));
}
@@ -56,7 +58,18 @@ public class ControlClientRecordProtocol extends ProtocolControlAdapter {
* @return 执行结果
*/
public Message execute(String clientId, Boolean enabled) {
this.updateRecordStatus(this.clientManager.clients(clientId), enabled);
return this.request(clientId, this.build(Map.of(Constant.ENABLED, enabled)));
}
/**
* 设置录像状态
*
* @param client 终端
* @param enabled 录像状态
*/
private void updateRecordStatus(Client client, Boolean enabled) {
client.status().setClientRecording(enabled);
}
}

View File

@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.UUID;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import com.acgist.taoyao.boot.annotation.Description;
import com.acgist.taoyao.boot.annotation.Protocol;
@@ -59,6 +60,7 @@ public class ControlServerRecordProtocol extends ProtocolControlAdapter implemen
this.ffmpegProperties = ffmpegProperties;
}
@Async
@Override
public void onApplicationEvent(RecorderCloseEvent event) {
final Recorder recorder = event.getRecorder();