steep-balloon-41261
12/12/2023, 2:32 PMadventurous-twilight-28575
12/12/2023, 6:25 PM2023-12-12T18:27:50.398Z INFO livekit service/roommanager.go:812 created TURN password {"username": "5Z1UEhkbTBnRDpnRfKIo47IZWrMsuaujMaOlMKJoCC", "password": "Z1UXtugN50aR4BM0jeM8hugUJT5I9dsGwHVeP7FDYWn"}
index.html (change URL and access token):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Livekit Example</title>
</head>
<body>
<div id="video-container">
</div>
<br/>
<script src="<https://cdn.jsdelivr.net/npm/livekit-client/dist/livekit-client.umd.js>"></script>
<script>
const url = "<ws://192.168.188.88:7880>"
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQ2MDIxODcsImlzcyI6ImRldmtleSIsIm5hbWUiOiJOZWlsIiwibmJmIjoxNzAxMDAyMTg3LCJzdWIiOiJOZWlsIiwidmlkZW8iOnsicm9vbSI6ImFiY2RlIiwicm9vbUpvaW4iOnRydWV9fQ.kdAIdvL4sSDWkTLO5eS8zfXK9rHaQ8fUCH7FvaEYS1M"
// creates a new room with options
const room = new LivekitClient.Room()
// pre-warm connection, this can be called as early as your page is loaded
room.prepareConnection(url, token)
// set up event listeners
room
.on(LivekitClient.RoomEvent.TrackSubscribed, handleTrackSubscribed)
.on(LivekitClient.RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
.on(LivekitClient.RoomEvent.ActiveSpeakersChanged, handleActiveSpeakerChange)
.on(LivekitClient.RoomEvent.Disconnected, handleDisconnect)
.on(LivekitClient.RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished)
.on(LivekitClient.RoomEvent.ConnectionQualityChanged, handleConnectionQualityChanged)
function handleConnectionQualityChanged(connectionQuality, participant) {
}
function handleTrackSubscribed(track, publication, participant) {
console.log("track subscribed", track)
if (track.kind === "video") {
// attach it to a new HTMLVideoElement or HTMLAudioElement
const videoElement = document.getElementById('video-container');
const element = track.attach();
videoElement.appendChild(element);
}
}
function handleTrackUnsubscribed(track, publication, participant) {
// remove tracks from all attached elements
console.log("track unsubscribed", track)
track.detach();
}
function handleLocalTrackUnpublished(publication, participant) {
// when local tracks are ended, update UI to remove them from rendering
publication.track.detach();
}
function handleActiveSpeakerChange(speakers) {
// show UI indicators when participant is speaking
}
function handleDisconnect() {
console.log('disconnected from room');
}
async function subscribeToRoom(token, url) {
await room.connect(url, token)
}
subscribeToRoom(token, url);
</script>
</body>
</html>dry-elephant-14928
12/13/2023, 7:48 AMacceptable-crayon-19032
12/13/2023, 9:14 AM