【m】连接结束后主动断开页面跳转
This commit is contained in:
@@ -253,21 +253,22 @@ class CallStateManager {
|
|||||||
*/
|
*/
|
||||||
async hangUp() {
|
async hangUp() {
|
||||||
this.clearStatsMessage(); // 清除统计信息
|
this.clearStatsMessage(); // 清除统计信息
|
||||||
this.messageDiv.style.display = 'block';
|
console.log(`Disconnect peer on ${this.connectionId}.`);
|
||||||
this.messageDiv.innerText = `Disconnect peer on ${this.connectionId}.`;
|
|
||||||
|
|
||||||
// 删除连接并停止WebRTC
|
// 删除连接并停止WebRTC
|
||||||
await this.renderstreaming.deleteConnection();
|
if (this.renderstreaming) {
|
||||||
await this.renderstreaming.stop();
|
try {
|
||||||
this.renderstreaming = null;
|
await this.renderstreaming.deleteConnection();
|
||||||
this.remoteVideo.srcObject = null; // 清除远程视频源
|
await this.renderstreaming.stop();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during hangUp:', error);
|
||||||
|
}
|
||||||
|
this.renderstreaming = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.connectionId = null;
|
this.connectionId = null;
|
||||||
|
this.state.session.status = 'ended';
|
||||||
// 启用编解码器选择
|
this.notify({ type: 'CALL_ENDED' });
|
||||||
if (this.supportsSetCodecPreferences) {
|
|
||||||
this.codecPreferences.disabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 设置编解码器偏好
|
* 设置编解码器偏好
|
||||||
@@ -276,14 +277,13 @@ class CallStateManager {
|
|||||||
/** @type {RTCRtpCodecCapability[] | null} */
|
/** @type {RTCRtpCodecCapability[] | null} */
|
||||||
let selectedCodecs = null;
|
let selectedCodecs = null;
|
||||||
|
|
||||||
if (this.supportsSetCodecPreferences) {
|
// 获取视频编解码器能力
|
||||||
const preferredCodec = this.codecPreferences.options[this.codecPreferences.selectedIndex];
|
const { codecs } = RTCRtpSender.getCapabilities('video');
|
||||||
if (preferredCodec.value !== '') {
|
if (codecs && codecs.length > 0) {
|
||||||
const [mimeType, sdpFmtpLine] = preferredCodec.value.split(' ');
|
// 优先选择H.264编解码器
|
||||||
const { codecs } = RTCRtpSender.getCapabilities('video');
|
const h264Codec = codecs.find(c => c.mimeType === 'video/H264');
|
||||||
const selectedCodecIndex = codecs.findIndex(c => c.mimeType === mimeType && c.sdpFmtpLine === sdpFmtpLine);
|
if (h264Codec) {
|
||||||
const selectCodec = codecs[selectedCodecIndex];
|
selectedCodecs = [h264Codec];
|
||||||
selectedCodecs = [selectCodec];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,9 +292,11 @@ class CallStateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取视频收发器并设置编解码器偏好
|
// 获取视频收发器并设置编解码器偏好
|
||||||
const transceivers = this.renderstreaming.getTransceivers().filter(t => t.receiver.track.kind == "video");
|
if (this.renderstreaming) {
|
||||||
if (transceivers && transceivers.length > 0) {
|
const transceivers = this.renderstreaming.getTransceivers().filter(t => t.receiver.track.kind == "video");
|
||||||
transceivers.forEach(t => t.setCodecPreferences(selectedCodecs));
|
if (transceivers && transceivers.length > 0) {
|
||||||
|
transceivers.forEach(t => t.setCodecPreferences(selectedCodecs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user