debug: add RTC diagnostic logs (ICE state, ontrack, sendOffer, signal flow)
This commit is contained in:
@@ -44,8 +44,10 @@ class ClassroomRTC {
|
||||
this._localStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
|
||||
this._localStream.getAudioTracks().forEach(t => { t.enabled = !this._muted; });
|
||||
this._startVAD(this._uid, this._localStream);
|
||||
console.log('[RTC] startAudio OK, tracks:', this._localStream.getAudioTracks().map(t => `${t.label} enabled=${t.enabled}`));
|
||||
return true;
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.warn('[RTC] startAudio FAILED', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -182,6 +184,7 @@ class ClassroomRTC {
|
||||
|
||||
async handleSignal(fromUid, payload) {
|
||||
const { kind } = payload;
|
||||
console.log(`[RTC] signal ← ${kind} from uid=${fromUid}`, 'myUid=', this._uid);
|
||||
try {
|
||||
if (kind === 'offer') await this._handleOffer(fromUid, payload);
|
||||
else if (kind === 'answer') await this._handleAnswer(fromUid, payload);
|
||||
@@ -249,6 +252,7 @@ class ClassroomRTC {
|
||||
|
||||
async _sendOffer(targetUid) {
|
||||
const peer = this._getOrCreate(targetUid);
|
||||
console.log(`[RTC] _sendOffer → uid=${targetUid} localStream=${!!this._localStream}`);
|
||||
if (this._localStream) {
|
||||
const existing = peer.pc.getSenders().map(s => s.track);
|
||||
this._localStream.getAudioTracks().forEach(t => {
|
||||
@@ -287,6 +291,13 @@ class ClassroomRTC {
|
||||
if (e.candidate) this._onSignal(uid, { kind: 'candidate', candidate: e.candidate.toJSON() });
|
||||
};
|
||||
|
||||
pc.oniceconnectionstatechange = () => {
|
||||
console.log(`[RTC] ICE uid=${uid} → ${pc.iceConnectionState}`);
|
||||
};
|
||||
pc.onconnectionstatechange = () => {
|
||||
console.log(`[RTC] conn uid=${uid} → ${pc.connectionState}`);
|
||||
};
|
||||
|
||||
/* Renegotiation: fires when tracks are added/removed (e.g. screen share) */
|
||||
pc.onnegotiationneeded = async () => {
|
||||
if (peer.negotiating || !peer.remoteSet || pc.signalingState !== 'stable') return;
|
||||
@@ -302,6 +313,7 @@ class ClassroomRTC {
|
||||
pc.ontrack = e => {
|
||||
const track = e.track;
|
||||
const stream = e.streams[0] || new MediaStream([track]);
|
||||
console.log(`[RTC] ontrack uid=${uid} kind=${track.kind} readyState=${track.readyState} streams=${e.streams.length}`);
|
||||
|
||||
if (track.kind === 'audio') {
|
||||
if (!peer.audioEl) {
|
||||
@@ -311,7 +323,9 @@ class ClassroomRTC {
|
||||
document.body.appendChild(peer.audioEl);
|
||||
}
|
||||
peer.audioEl.srcObject = stream;
|
||||
peer.audioEl.play().catch(() => {});
|
||||
peer.audioEl.play()
|
||||
.then(() => console.log(`[RTC] audio play() OK uid=${uid}`))
|
||||
.catch(err => console.warn(`[RTC] audio play() BLOCKED uid=${uid}`, err));
|
||||
this._startVAD(uid, stream);
|
||||
} else if (track.kind === 'video') {
|
||||
if (this._onScreen) this._onScreen(stream);
|
||||
|
||||
Reference in New Issue
Block a user