[*] 日常优化
This commit is contained in:
@@ -241,6 +241,7 @@ const signalChannel = {
|
|||||||
* 视频会话
|
* 视频会话
|
||||||
*/
|
*/
|
||||||
class Session {
|
class Session {
|
||||||
|
|
||||||
// 会话ID
|
// 会话ID
|
||||||
id;
|
id;
|
||||||
// 是否关闭
|
// 是否关闭
|
||||||
@@ -379,23 +380,23 @@ class Session {
|
|||||||
this.remoteAudioEnabled = false;
|
this.remoteAudioEnabled = false;
|
||||||
this.remoteVideoEnabled = false;
|
this.remoteVideoEnabled = false;
|
||||||
if(this.localAudioTrack) {
|
if(this.localAudioTrack) {
|
||||||
this.localAudioTrack.stop();
|
await this.localAudioTrack.stop();
|
||||||
this.localAudioTrack = null;
|
this.localAudioTrack = null;
|
||||||
}
|
}
|
||||||
if(this.localVideoTrack) {
|
if(this.localVideoTrack) {
|
||||||
this.localVideoTrack.stop();
|
await this.localVideoTrack.stop();
|
||||||
this.localVideoTrack = null;
|
this.localVideoTrack = null;
|
||||||
}
|
}
|
||||||
if(this.remoteAudioTrack) {
|
if(this.remoteAudioTrack) {
|
||||||
this.remoteAudioTrack.stop();
|
await this.remoteAudioTrack.stop();
|
||||||
this.remoteAudioTrack = null;
|
this.remoteAudioTrack = null;
|
||||||
}
|
}
|
||||||
if(this.remoteVideoTrack) {
|
if(this.remoteVideoTrack) {
|
||||||
this.remoteVideoTrack.stop();
|
await this.remoteVideoTrack.stop();
|
||||||
this.remoteVideoTrack = null;
|
this.remoteVideoTrack = null;
|
||||||
}
|
}
|
||||||
if(this.peerConnection) {
|
if(this.peerConnection) {
|
||||||
this.peerConnection.close();
|
await this.peerConnection.close();
|
||||||
this.peerConnection = null;
|
this.peerConnection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,7 +416,7 @@ class Session {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(
|
if(
|
||||||
!candidate ||
|
!candidate ||
|
||||||
candidate.sdpMid === undefined ||
|
candidate.sdpMid === undefined ||
|
||||||
candidate.candidate === undefined ||
|
candidate.candidate === undefined ||
|
||||||
candidate.sdpMLineIndex === undefined
|
candidate.sdpMLineIndex === undefined
|
||||||
@@ -430,12 +431,14 @@ class Session {
|
|||||||
setTimeout(() => this.addIceCandidate(candidate, ++index), 100);
|
setTimeout(() => this.addIceCandidate(candidate, ++index), 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程终端
|
* 远程终端
|
||||||
*/
|
*/
|
||||||
class RemoteClient {
|
class RemoteClient {
|
||||||
|
|
||||||
// 终端ID
|
// 终端ID
|
||||||
id;
|
id;
|
||||||
// 是否关闭
|
// 是否关闭
|
||||||
@@ -477,6 +480,8 @@ class RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 设置音量
|
* 设置音量
|
||||||
*
|
*
|
||||||
|
* 可以直接通过本地AudioWorklet对象获取音量
|
||||||
|
*
|
||||||
* @param {*} volume 音量
|
* @param {*} volume 音量
|
||||||
*/
|
*/
|
||||||
setVolume(volume) {
|
setVolume(volume) {
|
||||||
@@ -484,42 +489,43 @@ class RemoteClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭媒体
|
* 关闭终端
|
||||||
*/
|
*/
|
||||||
async close() {
|
async close() {
|
||||||
const me = this;
|
if(this.closed) {
|
||||||
if(me.closed) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.debug("关闭终端", me.clientId);
|
console.debug("关闭终端", this.clientId);
|
||||||
me.closed = true;
|
this.closed = true;
|
||||||
if(me.audioTrack) {
|
if(this.audioTrack) {
|
||||||
await me.audioTrack.stop();
|
await this.audioTrack.stop();
|
||||||
me.audioTrack = null;
|
this.audioTrack = null;
|
||||||
}
|
}
|
||||||
if(me.videoTrack) {
|
if(this.videoTrack) {
|
||||||
await me.videoTrack.stop();
|
await this.videoTrack.stop();
|
||||||
me.videoTrack = null;
|
this.videoTrack = null;
|
||||||
}
|
}
|
||||||
if(me.dataConsumer) {
|
if(this.dataConsumer) {
|
||||||
await me.dataConsumer.close();
|
await this.dataConsumer.close();
|
||||||
me.dataConsumer = null;
|
this.dataConsumer = null;
|
||||||
}
|
}
|
||||||
if(me.audioConsumer) {
|
if(this.audioConsumer) {
|
||||||
await me.audioConsumer.close();
|
await this.audioConsumer.close();
|
||||||
me.audioConsumer = null;
|
this.audioConsumer = null;
|
||||||
}
|
}
|
||||||
if(me.videoConsumer) {
|
if(this.videoConsumer) {
|
||||||
await me.videoConsumer.close();
|
await this.videoConsumer.close();
|
||||||
me.videoConsumer = null;
|
this.videoConsumer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桃夭终端
|
* 桃夭终端
|
||||||
*/
|
*/
|
||||||
class Taoyao extends RemoteClient {
|
class Taoyao extends RemoteClient {
|
||||||
|
|
||||||
// 信令连接
|
// 信令连接
|
||||||
connect;
|
connect;
|
||||||
// 信令地址
|
// 信令地址
|
||||||
|
|||||||
Reference in New Issue
Block a user