You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';// Import the Twilio Video libraryconstVideo=require('twilio-video');// Map to store track class names based on their kind (audio or video)consttrackClassName={audio: 'RemoteAudioTrack',video: 'RemoteVideoTrack'};// Initialize variables to manage room, state, and closing behaviorletroom=null;letshouldClose=false;letisClosing=false;// Function to add indentation to a stringfunctionindent(str,n){returnstr.split('\n').map(line=>` ${line}`).join('\n');}// Listen for unhandled errors and rejections in the window contextwindow.addEventListener('error',event=>{error(`\n\n${indent(event.error.stack)}\n`);});window.onunhandledrejection=event=>{error(`\n\n${indent(event.reason.stack)}\n`);};// Main function responsible for connecting to a Twilio Video roomasyncfunctionmain(token,roomSid){// Log the room SIDinfo(roomSid);// Log the attempt to connect to the roominfo('Connecting to Room...');// Connect to the Twilio Video room using the provided token and room nameroom=awaitVideo.connect(token,{name: roomSid,// tracks:[],// audio:true,// video:false});info(`Connected to Room ${room.sid} as LocalParticipant ${room.localParticipant.sid}.`);if(shouldClose){close();return;}// Handle participants in the roomconstparticipants=[...room.participants.values()];if(!participants.length){info('There are no RemoteParticipants in the Room.');}else{letmessage=`There ${participants.length>1 ? 'are' : 'is'} \${participants.length} RemoteParticipant${participants.length>1 ? 's' : ''} \in the Room:\n\n`;participants.forEach(participant=>{message+=` - RemoteParticipant ${participant.sid}\n`;participant.tracks.forEach(track=>{if(track.kind==='data'){return;}message+=` - ${trackClassName[track.kind]}${track.trackSid}\n`;});});info(message);participants.forEach(participant=>{participant.tracks.forEach(track=>trackSubscribed(track,participant));});}// Set up event handlers for various room and track eventsroom.on('participantConnected',participant=>{info(`RemoteParticipant ${participant.sid} connected.`);});room.on('participantDisconnected',participant=>{info(`RemoteParticipant ${participant.sid} disconnected.`);});room.on('trackSubscribed',(track,_,participant)=>{if(track.kind==='data'){return;}info(`Subscribed to ${trackClassName[track.kind]}${track.sid} published \by RemoteParticipant ${participant.sid}`);trackSubscribed(track,participant);});room.on('trackUnsubscribed',(track,_,participant)=>{if(track.kind==='data'){return;}info(`Unsubscribed from ${trackClassName[track.kind]}${track.sid} \published by RemoteParticipant ${participant.sid}`);trackUnsubscribed(track,participant);});// Handle disconnection from the roomroom.once('disconnected',(room,error)=>{info(`Disconnected from Room.`);close(error);});// Return information about the connected room and local participantreturn{roomSid: room.sid,localParticipantSid: room.localParticipant.sid};}// Expose the main function to the window contextwindow.main=main;// Function to close the bot and disconnect from the roomfunctionclose(error){if(isClosing){return;}isClosing=true;// Cleanup and unsubscribe from tracksrecorders.forEach((recorder,track)=>{trackUnsubscribed(track);});// Disconnect from the room if connectedif(room&&room.state!=='disconnected'){info('Disconnecting from Room...');room.disconnect();}}// Expose the close function to the window contextwindow.close=close;// Handle subscribed trackfunctiontrackSubscribed(track,participant){// Handle subscribed track (e.g., recording)if(track.kind==='data'){return;}letsubscriptionCount=subscriptionCounts.get(track)||0;subscriptionCount++;subscriptionCounts.set(track,subscriptionCount);constfilepath=[room.sid,room.localParticipant.sid,track?.trackSid??track.sid,`${subscriptionCount}.webm`];info(track.kind);if(track.mediaStreamTrack){info(JSON.stringify(track))record(track.mediaStreamTrack,filepath);}}// Handle unsubscribed trackfunctiontrackUnsubscribed(track){// Handle unsubscribed track (e.g., stop recording)constrecorder=recorders.get(track);recorders.delete(track);if(recorder){// info(`Stop recording ${recorder.filename}.`);recorder.stop();}}// Map to store MediaRecorder instances for tracksconstrecorders=newMap();// Map to track subscription counts for tracksconstsubscriptionCounts=newMap();// Function to start recording a trackfunctionrecord(track,filepath){// Create filename for the recordingconstfilename=filepath.join('/');info(`Begin recording ${filename}.`);createRecording(filepath);// Create a MediaStream containing the trackconststream=newMediaStream([track]);// special case for video tracks to work around Chromium bugif(track.kind==='video'){// NOTE(mroberts): This is a hack to workaround the following bug://// https://bugs.chromium.org/p/chromium/issues/detail?id=760760//constaudioContext=newAudioContext();constdestinationNode=audioContext.createMediaStreamDestination();constoscillatorNode=audioContext.createOscillator();oscillatorNode.frequency.setValueAtTime(0,audioContext.currentTime);oscillatorNode.connect(destinationNode);const[audioTrack]=destinationNode.stream.getAudioTracks();stream.addTrack(audioTrack);}// Create a MediaRecorder for the track and start recordingconstmimeType=`${track.kind}/webm`;constrecorder=newMediaRecorder(stream,{ mimeType });recorder.filename=filename;recorders.set(track,recorder);// Handle data available events from the recorderrecorder.ondataavailable=event=>{info(JSON.stringify(event))if(!event.data.size){return;}constfileReader=newFileReader();fileReader.onload=event=>{constbuffer=event.target.result;appendRecording(filepath,arrayBufferToString(buffer));};fileReader.readAsArrayBuffer(event.data);};recorder.start(100);}// Function to convert an ArrayBuffer to a stringfunctionarrayBufferToString(buffer){constbufView=newUint8Array(buffer);constlength=bufView.length;letresult='';letaddition=Math.pow(2,8)-1;for(leti=0;i<length;i+=addition){if(i+addition>length){addition=length-i;}result+=String.fromCharCode.apply(null,bufView.subarray(i,i+addition));}returnresult;}
Expected behavior:
i should receive audio back for other participant.
Actual behavior:
i am not receiving audio back for other participant. i observed that audioLevel for other participant is coming as 0.
The text was updated successfully, but these errors were encountered:
Naveen12345-alt
changed the title
no audio coming while video is coming
no audio coming while video is coming for the other participant.
Aug 12, 2023
or sensitive account information (API keys, credentials, etc.) when reporting this issue.
Code to reproduce the issue:
Expected behavior:
i should receive audio back for other participant.
Actual behavior:
i am not receiving audio back for other participant. i observed that audioLevel for other participant is coming as 0.
The text was updated successfully, but these errors were encountered: