Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!