This message was deleted.
# helpdesk
s
This message was deleted.
a
I built me a simple "index.html" from the sample code here https://github.com/livekit/client-sdk-js I'm having a self-hosted livekit server instance in the cloud somewhere. This instance has TURN enabled. When I'm serving my index.html (e.g. with Node's live-server), a trace in the server appears. It looks as like these creds are created whenever a participant joins. I don't know anything about their life time, but I think it is just a couple of hours. Then I went to https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ and created a server entry for the TURN(s) instance(s) using this credentials. The server trace:
Copy code
2023-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):
Copy code
<!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>
d
Yeah Neil's right, the embedded TURN server creates a unique set of credentials for each participant. It's only designed to be used with LiveKit connections and not a generic TURN server. You can test with our connection tester to validate that TURN server is set up correctly
a
Thanks for the responses!