[*] 日常优化

This commit is contained in:
acgist
2023-10-09 09:33:54 +08:00
parent 03ab29a13f
commit 98c701bc94
3 changed files with 28 additions and 25 deletions

View File

@@ -271,42 +271,43 @@ class Room {
* 音量监控
*/
handleAudioLevelObserver() {
const me = this;
// 静音监控
me.audioLevelObserver.on("silence", () => {
me.taoyao.push(protocol.buildMessage("media::audio::volume", {
roomId: me.roomId,
this.audioLevelObserver.on("silence", () => {
this.taoyao.push(protocol.buildMessage("media::audio::volume", {
roomId: this.roomId,
}));
});
// me.audioLevelObserver.observer.on("silence", () => {});
// this.audioLevelObserver.observer.on("silence", () => {});
// 音量监控
me.audioLevelObserver.on("volumes", (volumes) => {
this.audioLevelObserver.on("volumes", (volumes) => {
const notifyVolumes = [];
for (const value of volumes) {
const { volume, producer } = value;
const {
volume,
producer
} = value;
notifyVolumes.push({
volume : volume,
clientId: producer.clientId
});
}
me.taoyao.push(protocol.buildMessage("media::audio::volume", {
roomId : me.roomId,
this.taoyao.push(protocol.buildMessage("media::audio::volume", {
roomId : this.roomId,
volumes: notifyVolumes
}));
});
// me.audioLevelObserver.observer.on("volumes", (volumes) => {});
// this.audioLevelObserver.observer.on("volumes", (volumes) => {});
}
/**
* 当前讲话终端监控
*/
handleActiveSpeakerObserver() {
const me = this;
// 不用通知直接使用音量监控即可
me.activeSpeakerObserver.on("dominantspeaker", (dominantSpeaker) => {
this.activeSpeakerObserver.on("dominantspeaker", (dominantSpeaker) => {
const producer = dominantSpeaker.producer;
console.debug("当前讲话终端", producer.id, producer.clientId);
});
// me.activeSpeakerObserver.observer.on("dominantspeaker", (dominantSpeaker) => {});
// this.activeSpeakerObserver.observer.on("dominantspeaker", (dominantSpeaker) => {});
}
/**
* 房间使用情况

View File

@@ -137,11 +137,17 @@ const signalChannel = {
*/
async connect(address, reconnection = true) {
const me = this;
// 直接返回旧的连接
if (me.connected()) {
return new Promise((resolve, reject) => {
resolve(me.channel);
});
}
// 关闭旧的无效连接
if(this.channel) {
console.debug("关闭旧的信令连接", this.address);
this.close();
}
me.address = address;
me.reconnection = reconnection;
return new Promise((resolve, reject) => {
@@ -473,8 +479,7 @@ class RemoteClient {
* @param {*} volume 音量
*/
setVolume(volume) {
const me = this;
me.volume = ((volume + 127) / 127 * 100) + "%";
this.volume = ((volume + 127) / 127 * 100) + "%";
}
/**
@@ -1496,7 +1501,6 @@ class Taoyao extends RemoteClient {
* @param {*} body 消息主体
*/
defaultMediaAudioVolume(message, body) {
const me = this;
const {
roomId,
volumes
@@ -1508,19 +1512,17 @@ class Taoyao extends RemoteClient {
volume,
clientId
} = v;
if (me.clientId === clientId) {
me.setVolume(volume);
if (this.clientId === clientId) {
this.setVolume(volume);
} else {
const remoteClient = me.remoteClients.get(clientId);
const remoteClient = this.remoteClients.get(clientId);
remoteClient?.setVolume(volume);
}
});
} else {
// 静音
me.volume = 0;
me.remoteClients.forEach(v => {
v.volume = 0;
});
this.setVolume(-127);
this.remoteClients.forEach(v => v.setVolume(-127));
}
}

View File

@@ -19,8 +19,8 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
@Description(
body = """
{
"roomId" : "房间ID",
"volumes" : [
"roomId" : "房间ID",
"volumes": [
{
"volume" : 音量,
"clientId": "终端ID"