fix: souscription manuelle aux tracks audio des participants
Problème : RoomEvent.TrackSubscribed ne se déclenchait jamais avec @livekit/rtc-node Solution : - Itération manuelle sur participant.trackPublications quand participant se connecte - Création AudioStream immédiate si track audio disponible - Factorisation code dans _handleAudioTrack() Cela devrait permettre de recevoir l'audio des clients PWA. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -136,8 +136,19 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Participants
|
// Participants
|
||||||
this.room.on(RoomEvent.ParticipantConnected, (participant) => {
|
this.room.on(RoomEvent.ParticipantConnected, async (participant) => {
|
||||||
console.log(`➕ Participant connecté: ${participant.identity}`);
|
console.log(`➕ Participant connecté: ${participant.identity}`);
|
||||||
|
|
||||||
|
// Parcourir les tracks publiés par ce participant et s'y abonner manuellement
|
||||||
|
for (const [trackSid, publication] of participant.trackPublications) {
|
||||||
|
console.log(` 📝 Track disponible: ${publication.kind} (${trackSid}), muted: ${publication.muted}`);
|
||||||
|
|
||||||
|
if (publication.kind === 'audio' && publication.track) {
|
||||||
|
console.log(` ⚡ Souscription manuelle au track audio ${trackSid}...`);
|
||||||
|
await this._handleAudioTrack(publication.track, publication, participant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.emit('participantConnected', participant);
|
this.emit('participantConnected', participant);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -152,11 +163,30 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
console.log(`📢 Track publié par ${participant.identity}: ${publication.kind} (${publication.sid}), muted: ${publication.muted}`);
|
console.log(`📢 Track publié par ${participant.identity}: ${publication.kind} (${publication.sid}), muted: ${publication.muted}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
|
this.room.on(RoomEvent.TrackSubscribed, async (track, publication, participant) => {
|
||||||
console.log(`🎵 Track souscrit de ${participant.identity}: ${track.kind} (${publication.sid})`);
|
console.log(`🎵 Track souscrit de ${participant.identity}: ${track.kind} (${publication.sid})`);
|
||||||
|
|
||||||
if (track.kind === 'audio') {
|
if (track.kind === 'audio') {
|
||||||
console.log(`🎵 Track AUDIO souscrit de ${participant.identity}, création AudioStream...`);
|
console.log(`🎵 Track AUDIO souscrit de ${participant.identity} (événement TrackSubscribed)`);
|
||||||
|
await this._handleAudioTrack(track, publication, participant);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.room.on(RoomEvent.TrackUnsubscribed, (track, publication, participant) => {
|
||||||
|
if (track.kind === 'audio') {
|
||||||
|
console.log(`🔇 Track audio désouscrit de ${participant.identity}`);
|
||||||
|
this.remoteParticipants.delete(participant.sid);
|
||||||
|
this.emit('audioTrackUnsubscribed', { track, participant });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gère un track audio (création AudioStream et lecture)
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
async _handleAudioTrack(track, publication, participant) {
|
||||||
|
console.log(`🎧 Création AudioStream pour ${participant.identity}...`);
|
||||||
|
|
||||||
// Création d'un AudioStream pour recevoir les données PCM
|
// Création d'un AudioStream pour recevoir les données PCM
|
||||||
const stream = new AudioStream(
|
const stream = new AudioStream(
|
||||||
@@ -177,16 +207,6 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
|
|
||||||
this.emit('audioTrackSubscribed', { track, participant });
|
this.emit('audioTrackSubscribed', { track, participant });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
this.room.on(RoomEvent.TrackUnsubscribed, (track, publication, participant) => {
|
|
||||||
if (track.kind === 'audio') {
|
|
||||||
console.log(`🔇 Track audio désouscrit de ${participant.identity}`);
|
|
||||||
this.remoteParticipants.delete(participant.sid);
|
|
||||||
this.emit('audioTrackUnsubscribed', { track, participant });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Démarre la réception audio d'un participant
|
* Démarre la réception audio d'un participant
|
||||||
|
|||||||
Reference in New Issue
Block a user