Compare commits

..

1 Commits

Author SHA1 Message Date
pabloFuente
dd6320b5b5 Fix openvidu-live-captions null pointer 2025-09-15 18:38:58 +02:00

View File

@ -63,11 +63,20 @@ async function joinRoom() {
const trackId = reader.info.attributes["lk.transcribed_track_id"]; const trackId = reader.info.attributes["lk.transcribed_track_id"];
if (isFinal) { if (isFinal) {
const speaker = participantInfo.identity == room.localParticipant.identity // Due to a bug in LiveKit Server the participantInfo object may be empty.
? "You" : participantInfo.identity; // You can still get the participant owning the audio track like below:
const timestamp = new Date().toLocaleTimeString(); let participant;
if (room.localParticipant.audioTrackPublications.has(trackId)) {
participant = room.localParticipant;
} else {
participant = room.remoteParticipants.values().find(p => p.audioTrackPublications.has(trackId));
}
const captionsTextarea = document.getElementById("captions"); const captionsTextarea = document.getElementById("captions");
captionsTextarea.value += `[${timestamp}] ${speaker}: ${message}\n`; const timestamp = new Date().toLocaleTimeString();
const participantIdentity =
participant == room.localParticipant ? "You" : participant.identity;
captionsTextarea.value += `[${timestamp}] ${participantIdentity}: ${message}\n`;
captionsTextarea.scrollTop = captionsTextarea.scrollHeight; captionsTextarea.scrollTop = captionsTextarea.scrollHeight;
} }
} }
@ -91,7 +100,7 @@ async function joinRoom() {
// Publish your camera and microphone // Publish your camera and microphone
await room.localParticipant.enableCameraAndMicrophone(); await room.localParticipant.enableCameraAndMicrophone();
const localVideoTrack = this.room.localParticipant.videoTrackPublications const localVideoTrack = room.localParticipant.videoTrackPublications
.values() .values()
.next().value.track; .next().value.track;
addTrack(localVideoTrack, userName, true); addTrack(localVideoTrack, userName, true);