[*] 日常优化

This commit is contained in:
acgist
2023-08-24 07:47:43 +08:00
parent b2c25fff51
commit 0626023d89
3 changed files with 46 additions and 29 deletions

View File

@@ -1144,9 +1144,16 @@ public final class Taoyao implements ITaoyao {
final String name = MapUtils.get(body, "name");
final String clientId = MapUtils.get(body, "clientId");
final String sessionId = MapUtils.get(body, "sessionId");
final Boolean audio = MapUtils.get(body, "audio");
final Boolean video = MapUtils.get(body, "video");
final Resources resources = this.context.getResources();
if(this.sessions.containsKey(sessionId)) {
Log.w(Taoyao.class.getSimpleName(), "会话已经存在:" + sessionId);
return;
}
final SessionClient sessionClient = new SessionClient(
sessionId, name, clientId, this, this.mainHandler,
sessionId, name, clientId,
this, this.mainHandler,
resources.getBoolean(R.bool.preview),
resources.getBoolean(R.bool.playAudio),
resources.getBoolean(R.bool.playVideo),
@@ -1154,8 +1161,8 @@ public final class Taoyao implements ITaoyao {
resources.getBoolean(R.bool.audioConsume),
resources.getBoolean(R.bool.videoConsume),
resources.getBoolean(R.bool.dataProduce),
resources.getBoolean(R.bool.audioProduce),
resources.getBoolean(R.bool.videoProduce),
resources.getBoolean(R.bool.audioProduce) && audio,
resources.getBoolean(R.bool.videoProduce) && video,
this.mediaManager.getMediaProperties(),
this.mediaManager.getWebrtcProperties()
);

View File

@@ -3041,27 +3041,32 @@ class Taoyao extends RemoteClient {
}
/**
* 发起会话
* 发起会话信令
*
* @param {*} clientId 接收者ID
* @param {*} clientId 目标ID
* @param {*} audio 打开音频
* @param {*} video 打开视频
*/
async sessionCall(clientId) {
const me = this;
if (clientId == me.clientId) {
async sessionCall(clientId, audio = true, video = true) {
if (clientId == this.clientId) {
this.callbackError("不能监控自己");
return;
}
await me.checkDevice();
const response = await me.request(protocol.buildMessage("session::call", {
await this.checkDevice();
const response = await this.request(protocol.buildMessage("session::call", {
clientId
}));
const { name, sessionId } = response.body;
const {
name,
sessionId
} = response.body;
console.debug("发起会话", clientId, sessionId);
const session = new Session({
name,
clientId,
sessionId,
audioEnabled: me.audioProduce,
videoEnabled: me.videoProduce
audioEnabled: this.audioProduce && audio,
videoEnabled: this.videoProduce && video
});
this.sessionClients.set(sessionId, session);
}
@@ -3073,13 +3078,20 @@ class Taoyao extends RemoteClient {
*/
async defaultSessionCall(message) {
await this.checkDevice();
const { name, clientId, sessionId } = message.body;
const {
name,
audio = true,
video = true,
clientId,
sessionId
} = message.body;
console.debug("接收会话", clientId, sessionId, audio, video);
const session = new Session({
name,
clientId,
sessionId,
audioEnabled: this.audioProduce,
videoEnabled: this.videoProduce
audioEnabled: this.audioProduce && audio,
videoEnabled: this.videoProduce && video
});
this.sessionClients.set(sessionId, session);
await this.buildPeerConnection(session, sessionId);
@@ -3282,7 +3294,7 @@ class Taoyao extends RemoteClient {
session.remoteVideoTrack = track;
session.remoteVideoEnabled = true;
} else {
// 未知媒体类型
console.warn("未知媒体类型", track);
}
this.callbackTrack(session.clientId, track);
if(session.proxy && session.proxy.media) {
@@ -3301,8 +3313,8 @@ class Taoyao extends RemoteClient {
};
peerConnection.onnegotiationneeded = event => {
console.debug("会话媒体重新协商", event);
if(peerConnection.connectionState === "connected") {
// TODO重连
if(peerConnection.connectionState === "connected") {
peerConnection.restartIce();
}
}

View File

@@ -6,25 +6,24 @@ 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.model.MessageCode;
import com.acgist.taoyao.boot.model.MessageCodeException;
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.party.session.Session;
import com.acgist.taoyao.signal.protocol.ProtocolSessionAdapter;
import lombok.extern.slf4j.Slf4j;
/**
* 发起会话信令
*
* @author acgist
*/
@Slf4j
@Protocol
@Description(
body = """
{
"clientId": "接收者ID",
"clientId": "目标ID",
"audio" : 是否需要声音true|false
"video" : 是否需要视频true|false
}
@@ -49,8 +48,7 @@ public class SessionCallProtocol extends ProtocolSessionAdapter {
final String targetId = MapUtils.get(body, Constant.CLIENT_ID);
final Client target = this.clientManager.getClients(targetId);
if(target == null) {
log.warn("邀请对象无效:{}", clientId);
return;
throw MessageCodeException.of(MessageCode.CODE_3404, "邀请对象无效");
}
final Session session = this.sessionManager.call(client, target);
message.setBody(Map.of(