[*] 日常优化
This commit is contained in:
@@ -101,12 +101,10 @@ const signalChannel = {
|
|||||||
me.heartbeatTimer = setTimeout(async () => {
|
me.heartbeatTimer = setTimeout(async () => {
|
||||||
if (me.connected()) {
|
if (me.connected()) {
|
||||||
const battery = await navigator.getBattery();
|
const battery = await navigator.getBattery();
|
||||||
me.push(
|
me.push(protocol.buildMessage("client::heartbeat", {
|
||||||
protocol.buildMessage("client::heartbeat", {
|
|
||||||
battery : battery.level * 100,
|
battery : battery.level * 100,
|
||||||
charging: battery.charging,
|
charging: battery.charging,
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
me.heartbeat();
|
me.heartbeat();
|
||||||
} else {
|
} else {
|
||||||
console.warn("心跳失败", me.address);
|
console.warn("心跳失败", me.address);
|
||||||
@@ -143,8 +141,7 @@ const signalChannel = {
|
|||||||
me.channel.onopen = async () => {
|
me.channel.onopen = async () => {
|
||||||
console.info("打开信令通道", me.address);
|
console.info("打开信令通道", me.address);
|
||||||
const battery = await navigator.getBattery();
|
const battery = await navigator.getBattery();
|
||||||
me.push(
|
me.push(protocol.buildMessage("client::register", {
|
||||||
protocol.buildMessage("client::register", {
|
|
||||||
name : me.taoyao.name,
|
name : me.taoyao.name,
|
||||||
clientId : me.taoyao.clientId,
|
clientId : me.taoyao.clientId,
|
||||||
clientType: config.signal.clientType,
|
clientType: config.signal.clientType,
|
||||||
@@ -152,8 +149,7 @@ const signalChannel = {
|
|||||||
password : me.taoyao.password,
|
password : me.taoyao.password,
|
||||||
battery : battery.level * 100,
|
battery : battery.level * 100,
|
||||||
charging : battery.charging,
|
charging : battery.charging,
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
me.reconnectionTimeout = me.minReconnectionDelay;
|
me.reconnectionTimeout = me.minReconnectionDelay;
|
||||||
me.taoyao.connect = true;
|
me.taoyao.connect = true;
|
||||||
me.heartbeat();
|
me.heartbeat();
|
||||||
@@ -491,6 +487,7 @@ class RemoteClient {
|
|||||||
if(me.closed) {
|
if(me.closed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.debug("关闭终端", me.clientId);
|
||||||
me.closed = true;
|
me.closed = true;
|
||||||
if(me.audioTrack) {
|
if(me.audioTrack) {
|
||||||
me.audioTrack.stop();
|
me.audioTrack.stop();
|
||||||
@@ -914,7 +911,7 @@ class Taoyao extends RemoteClient {
|
|||||||
video: me.videoConfig,
|
video: me.videoConfig,
|
||||||
});
|
});
|
||||||
} else if (me.videoSource === "screen") {
|
} else if (me.videoSource === "screen") {
|
||||||
// 可能没有音频
|
// 音频配置:视频可能没有音频
|
||||||
const audioConfig = {
|
const audioConfig = {
|
||||||
...me.audioConfig
|
...me.audioConfig
|
||||||
};
|
};
|
||||||
@@ -923,6 +920,7 @@ class Taoyao extends RemoteClient {
|
|||||||
delete audioConfig.sampleSize.max;
|
delete audioConfig.sampleSize.max;
|
||||||
delete audioConfig.sampleRate.min;
|
delete audioConfig.sampleRate.min;
|
||||||
delete audioConfig.sampleRate.max;
|
delete audioConfig.sampleRate.max;
|
||||||
|
// 视频配置
|
||||||
const videoConfig = {
|
const videoConfig = {
|
||||||
...this.videoConfig,
|
...this.videoConfig,
|
||||||
...defaultShareScreenConfig
|
...defaultShareScreenConfig
|
||||||
@@ -942,72 +940,87 @@ class Taoyao extends RemoteClient {
|
|||||||
} else {
|
} else {
|
||||||
console.warn("不支持的视频来源", me.videoSource);
|
console.warn("不支持的视频来源", me.videoSource);
|
||||||
}
|
}
|
||||||
|
stream.getAudioTracks().forEach(track => {
|
||||||
|
console.debug(
|
||||||
|
"音频轨道信息",
|
||||||
|
track.getSettings(),
|
||||||
|
track.getCapabilities()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
stream.getVideoTracks().forEach(track => {
|
||||||
|
console.debug(
|
||||||
|
"视频轨道信息",
|
||||||
|
track.getSettings(),
|
||||||
|
track.getCapabilities()
|
||||||
|
);
|
||||||
|
});
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:continue
|
/**
|
||||||
|
* @returns 音频轨道
|
||||||
|
*/
|
||||||
async getAudioTrack() {
|
async getAudioTrack() {
|
||||||
const self = this;
|
const me = this;
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({
|
const stream = await navigator.mediaDevices.getUserMedia({
|
||||||
audio: self.audioConfig,
|
audio: me.audioConfig,
|
||||||
|
video: false,
|
||||||
});
|
});
|
||||||
// TODO:首个?
|
|
||||||
const track = stream.getAudioTracks()[0];
|
const track = stream.getAudioTracks()[0];
|
||||||
// TODO:验证修改API audioTrack.applyCapabilities
|
|
||||||
console.debug(
|
console.debug(
|
||||||
"音频信息:",
|
"音频轨道信息",
|
||||||
track.getSettings(),
|
track.getSettings(),
|
||||||
track.getCapabilities()
|
track.getCapabilities()
|
||||||
);
|
);
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns 视频轨道
|
||||||
|
*/
|
||||||
async getVideoTrack() {
|
async getVideoTrack() {
|
||||||
let track;
|
let stream;
|
||||||
const self = this;
|
const me = this;
|
||||||
if (self.videoSource === "file") {
|
if (me.videoSource === "file") {
|
||||||
// TODO:实现文件分享
|
stream = me.fileVideo.captureStream();
|
||||||
// const stream = await this._getExternalVideoStream();
|
} else if (me.videoSource === "camera") {
|
||||||
// track = stream.getVideoTracks()[0].clone();
|
stream = await navigator.mediaDevices.getUserMedia({
|
||||||
} else if (self.videoSource === "camera") {
|
audio: false,
|
||||||
// TODO:参数
|
video: me.videoConfig,
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: self.videoConfig,
|
|
||||||
});
|
});
|
||||||
// TODO:首个?
|
} else if (me.videoSource === "screen") {
|
||||||
track = stream.getVideoTracks()[0];
|
// 视频配置
|
||||||
// TODO:验证修改API videoTrack.applyCapabilities
|
const videoConfig = {
|
||||||
|
...this.videoConfig,
|
||||||
|
...defaultShareScreenConfig
|
||||||
|
};
|
||||||
|
// 删除min/max
|
||||||
|
delete videoConfig.width.min;
|
||||||
|
delete videoConfig.width.max;
|
||||||
|
delete videoConfig.height.min;
|
||||||
|
delete videoConfig.height.max;
|
||||||
|
delete videoConfig.frameRate.min;
|
||||||
|
delete videoConfig.frameRate.max;
|
||||||
|
stream = await navigator.mediaDevices.getDisplayMedia({
|
||||||
|
audio: false,
|
||||||
|
video: videoConfig,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn("不支持的视频来源", me.videoSource);
|
||||||
|
}
|
||||||
|
const track = stream.getVideoTracks()[0];
|
||||||
console.debug(
|
console.debug(
|
||||||
"视频信息:",
|
"视频轨道信息",
|
||||||
track.getSettings(),
|
track.getSettings(),
|
||||||
track.getCapabilities()
|
track.getCapabilities()
|
||||||
);
|
);
|
||||||
} else if (self.videoSource === "screen") {
|
|
||||||
// TODO:默认配置
|
|
||||||
const stream = await navigator.mediaDevices.getDisplayMedia({
|
|
||||||
// 如果需要共享声音
|
|
||||||
audio: false,
|
|
||||||
video: {
|
|
||||||
cursor: true,
|
|
||||||
width: { max: 1920 },
|
|
||||||
height: { max: 1080 },
|
|
||||||
frameRate: { max: 30 },
|
|
||||||
logicalSurface: true,
|
|
||||||
displaySurface: "monitor",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
track = stream.getVideoTracks()[0];
|
|
||||||
} else {
|
|
||||||
// TODO:异常
|
|
||||||
}
|
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
/************************ 信令 ************************/
|
|
||||||
/**
|
/**
|
||||||
* 终端配置信令
|
* 终端配置信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
defaultClientConfig(message) {
|
defaultClientConfig(message) {
|
||||||
const me = this;
|
const me = this;
|
||||||
@@ -1018,8 +1031,6 @@ class Taoyao extends RemoteClient {
|
|||||||
ideal: audio.sampleSize,
|
ideal: audio.sampleSize,
|
||||||
max : media.maxSampleSize,
|
max : media.maxSampleSize,
|
||||||
};
|
};
|
||||||
// 强制修改
|
|
||||||
// me.audioConfig.sampleRate = 8000;
|
|
||||||
me.audioConfig.sampleRate = {
|
me.audioConfig.sampleRate = {
|
||||||
min : media.minSampleRate,
|
min : media.minSampleRate,
|
||||||
ideal: audio.sampleRate,
|
ideal: audio.sampleRate,
|
||||||
@@ -1044,31 +1055,36 @@ class Taoyao extends RemoteClient {
|
|||||||
me.mediaConfig = media;
|
me.mediaConfig = media;
|
||||||
me.webrtcConfig = webrtc;
|
me.webrtcConfig = webrtc;
|
||||||
console.debug(
|
console.debug(
|
||||||
"终端配置:",
|
"终端媒体配置",
|
||||||
|
me.options,
|
||||||
me.audioConfig,
|
me.audioConfig,
|
||||||
me.videoConfig,
|
me.videoConfig,
|
||||||
me.mediaConfig,
|
me.mediaConfig,
|
||||||
me.webrtcConfig
|
me.webrtcConfig
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重启终端信令
|
* 重启终端信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
defaultClientReboot(message) {
|
defaultClientReboot(message) {
|
||||||
console.info("重启终端");
|
console.info("重启终端");
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 终端注册信令
|
* 终端注册信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
defaultClientRegister(message) {
|
defaultClientRegister(message) {
|
||||||
protocol.clientIndex = message.body.index;
|
const { body } = message;
|
||||||
console.debug("终端序号", protocol.clientIndex);
|
protocol.clientIndex = body.index;
|
||||||
|
console.info("终端注册成功", protocol.clientIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭终端信令
|
* 关闭终端信令
|
||||||
*
|
*
|
||||||
@@ -1078,77 +1094,80 @@ class Taoyao extends RemoteClient {
|
|||||||
console.info("关闭终端");
|
console.info("关闭终端");
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拍照
|
* 拍照
|
||||||
*
|
*
|
||||||
* @param {*} clientId
|
* @param {*} clientId 终端ID
|
||||||
*/
|
*/
|
||||||
controlPhotograph(clientId) {
|
controlPhotograph(clientId) {
|
||||||
const me = this;
|
const me = this;
|
||||||
me.push(
|
me.push(protocol.buildMessage("control::photograph", {
|
||||||
protocol.buildMessage("control::photograph", {
|
|
||||||
to: clientId
|
to: clientId
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 终端录像信令
|
* 终端录像信令
|
||||||
*
|
*
|
||||||
* @param {*} clientId
|
* @param {*} clientId 终端ID
|
||||||
* @param {*} enabled
|
* @param {*} enabled 录制状态
|
||||||
*/
|
*/
|
||||||
controlClientRecord(clientId, enabled) {
|
controlClientRecord(clientId, enabled) {
|
||||||
const me = this;
|
const me = this;
|
||||||
me.push(
|
me.push(protocol.buildMessage("control::client::record", {
|
||||||
protocol.buildMessage("control::client::record", {
|
|
||||||
to : clientId,
|
to : clientId,
|
||||||
enabled: enabled
|
enabled: enabled
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务端录像信令
|
* 服务端录像信令
|
||||||
*
|
*
|
||||||
* @param {*} clientId
|
* @param {*} clientId 终端ID
|
||||||
* @param {*} enabled
|
* @param {*} enabled 录制状态
|
||||||
*/
|
*/
|
||||||
controlServerRecord(clientId, enabled) {
|
controlServerRecord(clientId, enabled) {
|
||||||
const me = this;
|
const me = this;
|
||||||
me.push(
|
if(!me.roomId) {
|
||||||
protocol.buildMessage("control::server::record", {
|
me.callbackError("没有进入房间");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
me.push(protocol.buildMessage("control::server::record", {
|
||||||
to : clientId,
|
to : clientId,
|
||||||
roomId : me.roomId,
|
roomId : me.roomId,
|
||||||
enabled: enabled
|
enabled: enabled
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 终端音量信令
|
* 终端音量信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
defaultMediaAudioVolume(message) {
|
defaultMediaAudioVolume(message) {
|
||||||
const me = this;
|
const me = this;
|
||||||
const { roomId, volumes } = message.body;
|
const { roomId, volumes } = message.body;
|
||||||
// 静音
|
// 静音
|
||||||
if (!volumes || !volumes.length) {
|
if (!volumes || volumes.length <= 0) {
|
||||||
me.volume = 0;
|
me.volume = 0;
|
||||||
me.remoteClients.forEach((v) => (v.volume = 0));
|
me.remoteClients.forEach(v => {
|
||||||
|
v.volume = 0;
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 声音
|
// 声音
|
||||||
volumes.forEach((v) => {
|
volumes.forEach(v => {
|
||||||
const { volume, clientId } = v;
|
const { volume, clientId } = v;
|
||||||
if (me.clientId === clientId) {
|
if (me.clientId === clientId) {
|
||||||
me.setVolume(volume);
|
me.setVolume(volume);
|
||||||
} else {
|
} else {
|
||||||
const remoteClient = me.remoteClients.get(clientId);
|
const remoteClient = me.remoteClients.get(clientId);
|
||||||
if (remoteClient) {
|
remoteClient?.setVolume(volume);
|
||||||
remoteClient.setVolume(volume);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭消费者信令
|
* 关闭消费者信令
|
||||||
*
|
*
|
||||||
@@ -1156,51 +1175,60 @@ class Taoyao extends RemoteClient {
|
|||||||
*/
|
*/
|
||||||
mediaConsumerClose(consumerId) {
|
mediaConsumerClose(consumerId) {
|
||||||
const me = this;
|
const me = this;
|
||||||
me.push(
|
if(!me.roomId) {
|
||||||
protocol.buildMessage("media::consumer::close", {
|
me.callbackError("没有进入房间");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
me.push(protocol.buildMessage("media::consumer::close", {
|
||||||
roomId : me.roomId,
|
roomId : me.roomId,
|
||||||
consumerId: consumerId,
|
consumerId: consumerId,
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭消费者信令
|
* 关闭消费者信令
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
defaultMediaConsumerClose(message) {
|
defaultMediaConsumerClose(message) {
|
||||||
const me = this;
|
const me = this;
|
||||||
const { roomId, consumerId } = message.body;
|
const { roomId, consumerId } = message.body;
|
||||||
const consumer = me.consumers.get(consumerId);
|
const consumer = me.consumers.get(consumerId);
|
||||||
if (consumer) {
|
if (consumer) {
|
||||||
console.debug("关闭消费者:", consumerId);
|
console.debug("关闭消费者", consumerId);
|
||||||
consumer.close();
|
consumer.close();
|
||||||
me.consumers.delete(consumerId);
|
me.consumers.delete(consumerId);
|
||||||
} else {
|
} else {
|
||||||
console.debug("关闭消费者无效:", consumerId);
|
console.debug("关闭消费者无效", consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停消费者
|
* 暂停消费者信令
|
||||||
*
|
*
|
||||||
* @param {*} consumerId 消费者ID
|
* @param {*} consumerId 消费者ID
|
||||||
*/
|
*/
|
||||||
mediaConsumerPause(consumerId) {
|
mediaConsumerPause(consumerId) {
|
||||||
const me = this;
|
const me = this;
|
||||||
|
if(!me.roomId) {
|
||||||
|
me.callbackError("没有进入房间");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const consumer = me.consumers.get(consumerId);
|
const consumer = me.consumers.get(consumerId);
|
||||||
if(consumer) {
|
if(consumer) {
|
||||||
if(consumer.paused) {
|
if(consumer.paused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.debug("mediaConsumerPause:", consumerId);
|
console.debug("暂停消费者", consumerId);
|
||||||
me.push(protocol.buildMessage("media::consumer::pause", {
|
me.push(protocol.buildMessage("media::consumer::pause", {
|
||||||
roomId : me.roomId,
|
roomId : me.roomId,
|
||||||
consumerId: consumerId,
|
consumerId: consumerId,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
console.debug("mediaConsumerPause non:", consumerId);
|
console.debug("暂停消费者无效", consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停消费者信令
|
* 暂停消费者信令
|
||||||
*
|
*
|
||||||
@@ -1211,12 +1239,15 @@ class Taoyao extends RemoteClient {
|
|||||||
const { roomId, consumerId } = message.body;
|
const { roomId, consumerId } = message.body;
|
||||||
const consumer = me.consumers.get(consumerId);
|
const consumer = me.consumers.get(consumerId);
|
||||||
if (consumer) {
|
if (consumer) {
|
||||||
console.debug("暂停消费者:", consumerId);
|
console.debug("暂停消费者", consumerId);
|
||||||
consumer.pause();
|
consumer.pause();
|
||||||
} else {
|
} else {
|
||||||
console.debug("暂停消费者无效:", consumerId);
|
console.debug("暂停消费者无效", consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO:continue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求关键帧
|
* 请求关键帧
|
||||||
*
|
*
|
||||||
@@ -1863,7 +1894,7 @@ class Taoyao extends RemoteClient {
|
|||||||
const me = this;
|
const me = this;
|
||||||
const { clientId } = message.body;
|
const { clientId } = message.body;
|
||||||
me.remoteClients.delete(clientId);
|
me.remoteClients.delete(clientId);
|
||||||
// TODO:close
|
// TODO:remoteclient.close
|
||||||
console.info("终端离开:", clientId);
|
console.info("终端离开:", clientId);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -2801,6 +2832,7 @@ class Taoyao extends RemoteClient {
|
|||||||
* autoGainControl: true,
|
* autoGainControl: true,
|
||||||
* noiseSuppression: true
|
* noiseSuppression: true
|
||||||
* }
|
* }
|
||||||
|
* applyCapabilities
|
||||||
await track.applyConstraints(Object.assign(track.getSettings(), setting));
|
await track.applyConstraints(Object.assign(track.getSettings(), setting));
|
||||||
* TODO:播放音量(audio标签配置)、采集音量
|
* TODO:播放音量(audio标签配置)、采集音量
|
||||||
* 支持属性:navigator.mediaDevices.getSupportedConstraints()
|
* 支持属性:navigator.mediaDevices.getSupportedConstraints()
|
||||||
|
|||||||
Reference in New Issue
Block a user