[*] 日常优化
This commit is contained in:
@@ -271,42 +271,43 @@ class Room {
|
|||||||
* 音量监控
|
* 音量监控
|
||||||
*/
|
*/
|
||||||
handleAudioLevelObserver() {
|
handleAudioLevelObserver() {
|
||||||
const me = this;
|
|
||||||
// 静音监控
|
// 静音监控
|
||||||
me.audioLevelObserver.on("silence", () => {
|
this.audioLevelObserver.on("silence", () => {
|
||||||
me.taoyao.push(protocol.buildMessage("media::audio::volume", {
|
this.taoyao.push(protocol.buildMessage("media::audio::volume", {
|
||||||
roomId: me.roomId,
|
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 = [];
|
const notifyVolumes = [];
|
||||||
for (const value of volumes) {
|
for (const value of volumes) {
|
||||||
const { volume, producer } = value;
|
const {
|
||||||
|
volume,
|
||||||
|
producer
|
||||||
|
} = value;
|
||||||
notifyVolumes.push({
|
notifyVolumes.push({
|
||||||
volume : volume,
|
volume : volume,
|
||||||
clientId: producer.clientId
|
clientId: producer.clientId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
me.taoyao.push(protocol.buildMessage("media::audio::volume", {
|
this.taoyao.push(protocol.buildMessage("media::audio::volume", {
|
||||||
roomId : me.roomId,
|
roomId : this.roomId,
|
||||||
volumes: notifyVolumes
|
volumes: notifyVolumes
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
// me.audioLevelObserver.observer.on("volumes", (volumes) => {});
|
// this.audioLevelObserver.observer.on("volumes", (volumes) => {});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 当前讲话终端监控
|
* 当前讲话终端监控
|
||||||
*/
|
*/
|
||||||
handleActiveSpeakerObserver() {
|
handleActiveSpeakerObserver() {
|
||||||
const me = this;
|
|
||||||
// 不用通知直接使用音量监控即可
|
// 不用通知直接使用音量监控即可
|
||||||
me.activeSpeakerObserver.on("dominantspeaker", (dominantSpeaker) => {
|
this.activeSpeakerObserver.on("dominantspeaker", (dominantSpeaker) => {
|
||||||
const producer = dominantSpeaker.producer;
|
const producer = dominantSpeaker.producer;
|
||||||
console.debug("当前讲话终端", producer.id, producer.clientId);
|
console.debug("当前讲话终端", producer.id, producer.clientId);
|
||||||
});
|
});
|
||||||
// me.activeSpeakerObserver.observer.on("dominantspeaker", (dominantSpeaker) => {});
|
// this.activeSpeakerObserver.observer.on("dominantspeaker", (dominantSpeaker) => {});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 房间使用情况
|
* 房间使用情况
|
||||||
|
|||||||
@@ -137,11 +137,17 @@ const signalChannel = {
|
|||||||
*/
|
*/
|
||||||
async connect(address, reconnection = true) {
|
async connect(address, reconnection = true) {
|
||||||
const me = this;
|
const me = this;
|
||||||
|
// 直接返回旧的连接
|
||||||
if (me.connected()) {
|
if (me.connected()) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve(me.channel);
|
resolve(me.channel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 关闭旧的无效连接
|
||||||
|
if(this.channel) {
|
||||||
|
console.debug("关闭旧的信令连接", this.address);
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
me.address = address;
|
me.address = address;
|
||||||
me.reconnection = reconnection;
|
me.reconnection = reconnection;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -473,8 +479,7 @@ class RemoteClient {
|
|||||||
* @param {*} volume 音量
|
* @param {*} volume 音量
|
||||||
*/
|
*/
|
||||||
setVolume(volume) {
|
setVolume(volume) {
|
||||||
const me = this;
|
this.volume = ((volume + 127) / 127 * 100) + "%";
|
||||||
me.volume = ((volume + 127) / 127 * 100) + "%";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1496,7 +1501,6 @@ class Taoyao extends RemoteClient {
|
|||||||
* @param {*} body 消息主体
|
* @param {*} body 消息主体
|
||||||
*/
|
*/
|
||||||
defaultMediaAudioVolume(message, body) {
|
defaultMediaAudioVolume(message, body) {
|
||||||
const me = this;
|
|
||||||
const {
|
const {
|
||||||
roomId,
|
roomId,
|
||||||
volumes
|
volumes
|
||||||
@@ -1508,19 +1512,17 @@ class Taoyao extends RemoteClient {
|
|||||||
volume,
|
volume,
|
||||||
clientId
|
clientId
|
||||||
} = v;
|
} = v;
|
||||||
if (me.clientId === clientId) {
|
if (this.clientId === clientId) {
|
||||||
me.setVolume(volume);
|
this.setVolume(volume);
|
||||||
} else {
|
} else {
|
||||||
const remoteClient = me.remoteClients.get(clientId);
|
const remoteClient = this.remoteClients.get(clientId);
|
||||||
remoteClient?.setVolume(volume);
|
remoteClient?.setVolume(volume);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 静音
|
// 静音
|
||||||
me.volume = 0;
|
this.setVolume(-127);
|
||||||
me.remoteClients.forEach(v => {
|
this.remoteClients.forEach(v => v.setVolume(-127));
|
||||||
v.volume = 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
body = """
|
body = """
|
||||||
{
|
{
|
||||||
"roomId" : "房间ID",
|
"roomId" : "房间ID",
|
||||||
"volumes" : [
|
"volumes": [
|
||||||
{
|
{
|
||||||
"volume" : 音量,
|
"volume" : 音量,
|
||||||
"clientId": "终端ID"
|
"clientId": "终端ID"
|
||||||
|
|||||||
Reference in New Issue
Block a user