Created
August 24, 2021 11:28
-
-
Save davidrinnan/908a9f1df79803654d32f6fd39df2d1f to your computer and use it in GitHub Desktop.
A video wall dilema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A video wall, in Idol they call it Sverigeväggen. A collage of random | |
viewers who are represented by a low resolution live video. | |
The video audience exists in segments in the current group. | |
There are a maximum of 16 video participants in each segment | |
Usually we display 48 participants on a video wall which is randomly | |
produced from the available channels, hence the default 3 for numberOfViews. | |
We only fetch segments that have active participants in them. We do not consider | |
empty channels a burden. | |
Task: | |
Since people sometimes leave a channel this creates blanks (ie a channel | |
may after a while only have 5 participants left). | |
As part of the process of getting random channels we would also like to | |
move participants to fill up empty spots. | |
The worst experience is the display of close to empty groups since this creates | |
lots of visual gaps in a 48 piece grid, giving the experience there are few participants. | |
Assume there is a function this.moveParticipant(fromChannel, toChannel, pid). | |
Such a move will happen asynchronously and will take approx 10 seconds. | |
If a person joins a segment which is currently displayed, the person will pop | |
in nicely in the grid, so dont worry about that. Do however avoid the transfer | |
of participants FROM currently displayed groups. | |
There could be anything from 0 to 100's of channels in a group | |
The getRandomChannels function is usually executed every 60-360 seconds. | |
What we expect: | |
You can solve the task by explaining the thinking behind it, by pseudo code or actual code. | |
The important thing is to explain the thinking part. What potential pitfalls do you see and | |
how do you address them? | |
New participants are always connected to the largest channel with available slots, so they do not need to be considered. | |
If no slots are available in existing groups, a new group is created. | |
*/ | |
getRandomChannels (emeetingId, group, numberOfViews = 3, cb) { | |
if (!this.channels[group]) { | |
cb && cb('err', null); | |
return; | |
} | |
let channels = []; | |
const segments = Object.keys(this.channels[group]); | |
const availableSegments = segments.filter(segment => { | |
const channel = this.channels[group][segment].channel; | |
return this.inChannel[channel] && Object.keys(this.inChannel[channel]).length | |
}); | |
let getNbrChannels = numberOfViews; | |
while (availableSegments.length && getNbrChannels > 0) { | |
const groupSegment = availableSegments.splice(Math.floor(availableSegments.length * Math.random() | 0), 1)[0]; | |
channels.push(this.channels[group][groupSegment].channel); | |
--getNbrChannels; | |
} | |
const randomChannels = { | |
emeetingId, | |
channels, | |
}; | |
cb && cb(null, randomChannels); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment