Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
AgoraRTC can't add multiple users in the webpage. can't figure out what went wrong

i was trying to make a streaming website using Agora.io in my JavaScript, i made a player template which will add to my webpage every time a new user enters. the client.on method should detect a new user coming & call back the function which should add the new user to the stream!

const APP_ID = "fe45f285661941ada5ef5d451fe8f626"
const CHANNEL = "main"
const TOKEN = "006fe45f285661941ada5ef5d451fe8f626IABxEPnj4KCl8i4+gcrg2F7Cc+nmjmOiRWq49ICnSOHfdGTNKL8AAAAAEACXVkQu42OcYgEAAQC9Y5xi"

const client = AgoraRTC.createClient({mode:"rtc",codec:"vp8"})

let localTracks = []
let remoteUsers = {}
let UID

let joinAndDisplayLocalStreams = async ()=> {

    client.on("user-published",handleUserJoined)

    UID = await client.join(APP_ID,CHANNEL,TOKEN,null)

    localTracks = await AgoraRTC.createMicrophoneAndCameraTracks()
    let player = ` <div class="video-container" id="user-container-${UID}">
                     <div class="name-wrapper"><span class="user-name">My name</span></div>
                         <div class="video-player" id="user-${UID}"></div>
                </div>`
    document.getElementById("video-streams").insertAdjacentHTML("beforeend",player)
    
    localTracks[1].play(`user-${UID}`)
    await client.publish([localTracks[0],localTracks[1]])
}

let handleUserJoined = async(user,mediaType)=>{
    remoteUsers[user.uid]= user
    await client.subscribe(user,mediaType)
    console.log(mediaType)

    if(mediaType==="video"){
        let player = document.getElementById(`user-container-${user.uid}`)
        if(player!=null){
            player.remove()
        }
        player = `<div class="video-container" id="user-container-${user.uid}">
                     <div class="name-wrapper"><span class="user-name">My name</span></div>
                         <div class="video-player" id="user-${user.uid}"></div>
                </div>`

        document.getElementById("video-streams").insertAdjacentElement("beforeend",player)
        user.videoTrack.play(`user-${user.uid}`)
    }
    if(mediaType==="audio"){
        user.audioTrack.play()
    }
}

joinAndDisplayLocalStreams()
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda