Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
digitallysavvy committed Apr 3, 2024
1 parent c6ee2ce commit 3fc9d59
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions agora-live-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ const startScreenShare = async () => {
}

// move the main user from the full-screen div
await createRemoteUserDiv(mainStreamUid)
remoteUsers[mainStreamUid].videoTrack.play(`remote-user-${mainStreamUid}-video`)
if(!mainIsEmpty) {
await createRemoteUserDiv(mainStreamUid)
remoteUsers[mainStreamUid].videoTrack.play(`remote-user-${mainStreamUid}-video`)
}

// publish the tracks
let tracks = [localTracks.screen.video]
Expand Down Expand Up @@ -249,7 +251,12 @@ const stopScreenShare = async () => {
localTrackActive.screen = false
// ui clean-up
getById('full-screen-video').replaceChildren() // Remove all children of the main div
setNewMainVideo(mainStreamUid)
if(mainStreamUid) {
await setNewMainVideo(mainStreamUid)
} else if (Object.keys(remoteUsers) > 0) {
const newMainUid = getNewUidForMainUser()
await setNewMainVideo(newMainUid)
}
}

const handleLeaveChannel = async () => {
Expand Down

0 comments on commit 3fc9d59

Please sign in to comment.