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
import{LocalVideoTrack,RemoteParticipant,RemoteTrack,RemoteTrackPublication,Room,RoomEvent}from"livekit-client";import"./App.css";import{useState}from"react";importVideoComponentfrom"./components/VideoComponent";importAudioComponentfrom"./components/AudioComponent";typeTrackInfo={trackPublication: RemoteTrackPublication;participantIdentity: string;};// When running OpenVidu locally, leave these variables empty// For other deployment type, configure them with correct URLs depending on your deploymentletAPPLICATION_SERVER_URL="";letLIVEKIT_URL="";configureUrls();functionconfigureUrls(){console.log("call configureUrls");// If APPLICATION_SERVER_URL is not configured, use default value from OpenVidu Local deploymentif(!APPLICATION_SERVER_URL){if(window.location.hostname==="43.202.81.12"){APPLICATION_SERVER_URL="http://43.202.81.12:6080/";}else{APPLICATION_SERVER_URL="http://43.202.81.12:6080/";// APPLICATION_SERVER_URL = "https://" + window.location.hostname + ":6443/";}}// If LIVEKIT_URL is not configured, use default value from OpenVidu Local deploymentif(!LIVEKIT_URL){if(window.location.hostname==="43.202.81.12"){LIVEKIT_URL="ws://43.202.81.12:7880/";}else{LIVEKIT_URL="wss://43.202.81.12:7880/";// LIVEKIT_URL = "wss://" + window.location.hostname + ":7443/";}}console.log("window.location.hostname : ",window.location.hostname);console.log("APPLICATION_SERVER_URL : ",APPLICATION_SERVER_URL);console.log("LIVEKIT_URL : ",LIVEKIT_URL);}functionApp(){console.log("call App");const[room,setRoom]=useState<Room|undefined>(undefined);const[localTrack,setLocalTrack]=useState<LocalVideoTrack|undefined>(undefined);const[remoteTracks,setRemoteTracks]=useState<TrackInfo[]>([]);const[participantName,setParticipantName]=useState("Participant"+Math.floor(Math.random()*100));const[roomName,setRoomName]=useState("Test Room");asyncfunctionjoinRoom(){console.log("call joinRoom");// Initialize a new Room objectconstroom=newRoom();setRoom(room);// Specify the actions when events take place in the room// On every new Track received...room.on(RoomEvent.TrackSubscribed,(_track: RemoteTrack,publication: RemoteTrackPublication,participant: RemoteParticipant)=>{setRemoteTracks((prev)=>[
...prev,{trackPublication: publication,participantIdentity: participant.identity}]);});// On every Track destroyed...room.on(RoomEvent.TrackUnsubscribed,(_track: RemoteTrack,publication: RemoteTrackPublication)=>{setRemoteTracks((prev)=>prev.filter((track)=>track.trackPublication.trackSid!==publication.trackSid));});try{// Get a token from your application server with the room name and participant nameconsole.log(1);consttoken=awaitgetToken(roomName,participantName);// Connect to the room with the LiveKit URL and the tokenconsole.log(2);awaitroom.connect(LIVEKIT_URL,token);// Publish your camera and microphoneconsole.log(3);awaitroom.localParticipant.enableCameraAndMicrophone();// setLocalTrack(room.localParticipant.videoTrackPublications.values().next().value.videoTrack);console.log(4);setLocalTrack(room.localParticipant.videoTrackPublications.values().next().value?.videoTrack);}catch(error){console.log("There was an error connecting to the room:",(errorasError).message);awaitleaveRoom();}}asyncfunctionleaveRoom(){console.log("call leaveRoom");// Leave the room by calling 'disconnect' method over the Room objectawaitroom?.disconnect();// Reset the statesetRoom(undefined);setLocalTrack(undefined);setRemoteTracks([]);}/** * -------------------------------------------- * GETTING A TOKEN FROM YOUR APPLICATION SERVER * -------------------------------------------- * The method below request the creation of a token to * your application server. This prevents the need to expose * your LiveKit API key and secret to the client side. * * In this sample code, there is no user control at all. Anybody could * access your application server endpoints. In a real production * environment, your application server must identify the user to allow * access to the endpoints. */asyncfunctiongetToken(roomName: string,participantName: string){console.log("call getToken");constresponse=awaitfetch(APPLICATION_SERVER_URL+"token",{method: "POST",headers: {"Content-Type": "application/json"},body: JSON.stringify({roomName: roomName,participantName: participantName})});if(!response.ok){consterror=awaitresponse.json();thrownewError(`Failed to get token: ${error.errorMessage}`);}constdata=awaitresponse.json();returndata.token;}return(<>{!room ? (<divid="join"><divid="join-dialog"><h2>Join a Video Room</h2><formonSubmit={(e)=>{joinRoom();e.preventDefault();}}><div><labelhtmlFor="participant-name">Participant</label><inputid="participant-name"className="form-control"type="text"value={participantName}onChange={(e)=>setParticipantName(e.target.value)}required/></div><div><labelhtmlFor="room-name">Room</label><inputid="room-name"className="form-control"type="text"value={roomName}onChange={(e)=>setRoomName(e.target.value)}required/></div><buttonclassName="btn btn-lg btn-success"type="submit"disabled={!roomName||!participantName}>
Join!
</button></form></div></div>) : (<divid="room"><divid="room-header"><h2id="room-title">{roomName}</h2><buttonclassName="btn btn-danger"id="leave-room-button"onClick={leaveRoom}>
Leave Room
</button></div><divid="layout-container">{localTrack&&(<VideoComponenttrack={localTrack}participantIdentity={participantName}local={true}/>)}{remoteTracks.map((remoteTrack)=>remoteTrack.trackPublication.kind==="video" ? (<VideoComponentkey={remoteTrack.trackPublication.trackSid}track={remoteTrack.trackPublication.videoTrack!}participantIdentity={remoteTrack.participantIdentity}/>) : (<AudioComponentkey={remoteTrack.trackPublication.trackSid}track={remoteTrack.trackPublication.audioTrack!}/>))}</div></div>)}</>);}exportdefaultApp;
Click the join button
awaitroom.connect(LIVEKIT_URL,token);
In that line
There was an error connecting to the room: could not establish pc connection
I deployed to AWS EC2 according to the official documentation guide.
I modified the App.tsx file as follows:
Click the join button
In that line
I am getting this error.
Why?
The backend log responds normally as follows:
The text was updated successfully, but these errors were encountered: