【m】连接结束后主动断开页面跳转

This commit is contained in:
zhangzheng
2026-03-05 11:32:51 +08:00
parent 425c85dd9c
commit 89cc627fe1

View File

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