Invert participants/mixers when drawing tracks. Add timers to find mixers later as they show up. Remove hack to add client id to local tracks (bridge doing it now)
This commit is contained in:
parent
0d9d8af52b
commit
1fb40b5540
|
|
@ -21,6 +21,10 @@
|
|||
var currentMixerRangeMin = null;
|
||||
var currentMixerRangeMax = null;
|
||||
|
||||
var lookingForMixersCount = 0;
|
||||
var lookingForMixersTimer = null;
|
||||
var lookingForMixers = {};
|
||||
|
||||
var defaultParticipant = {
|
||||
tracks: [{
|
||||
instrument_id: "unknown"
|
||||
|
|
@ -147,8 +151,9 @@
|
|||
}
|
||||
|
||||
function renderSession() {
|
||||
$('#session-mytracks-container').empty();
|
||||
$('#session-livetracks-container').empty();
|
||||
_updateMixers();
|
||||
_fixClientIds();
|
||||
_renderTracks();
|
||||
_wireTopVolume();
|
||||
_addVoiceChat();
|
||||
|
|
@ -161,23 +166,30 @@
|
|||
mixers = holder.mixers;
|
||||
}
|
||||
|
||||
function _fixClientIds() {
|
||||
// Set the client_id of all the mixers that are in my local groups
|
||||
for (var i=0; i< mixers.length; i++) {
|
||||
if (mixers[i].group_id === 2) {
|
||||
mixers[i].client_id = app.clientId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _participantForClientId(clientId) {
|
||||
var foundParticipant = null;
|
||||
$.each(session.participants, function(index, participant) {
|
||||
if (participant.client_id === clientId) {
|
||||
foundParticipant = participant;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return foundParticipant; // no matching participant
|
||||
return foundParticipant;
|
||||
}
|
||||
|
||||
function _mixerForClientId(clientId, groupIds) {
|
||||
var foundMixer = null;
|
||||
$.each(mixers, function(index, mixer) {
|
||||
if (mixer.client_id === clientId) {
|
||||
for (var i=0; i<groupIds.length; i++) {
|
||||
if (mixer.group_id === groupIds[i]) {
|
||||
foundMixer = mixer;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return foundMixer;
|
||||
}
|
||||
|
||||
function _wireTopVolume() {
|
||||
|
|
@ -233,48 +245,105 @@
|
|||
}
|
||||
|
||||
function _renderTracks() {
|
||||
$.each(mixers, function(index, mixer) {
|
||||
// Only handle local music input and peer music here.
|
||||
if (mixer.group_id === 2 || mixer.group_id === 7) {
|
||||
var myTrack = (mixer.group_id === 2);
|
||||
var participant = _participantForClientId(mixer.client_id);
|
||||
if (!(participant)) {
|
||||
participant = defaultParticipant;
|
||||
}
|
||||
var name = participant.user.name;
|
||||
if (!(name)) {
|
||||
name = participant.user.first_name + ' ' + participant.user.last_name;
|
||||
}
|
||||
var instrumentIcon = _instrumentIconFromId(participant.tracks[0].instrument_id);
|
||||
var photoUrl = participant.user.photo_url;
|
||||
if (!(photoUrl)) {
|
||||
photoUrl = "/assets/shared/avatar_default.jpg";
|
||||
}
|
||||
// Participants are here now, but the mixers don't update right away.
|
||||
// Draw tracks from participants, then setup timers to look for the
|
||||
// mixers that go with those participants, if they're missing.
|
||||
lookingForMixersCount = 0;
|
||||
$.each(session.participants, function(index, participant) {
|
||||
|
||||
var name = participant.user.name;
|
||||
if (!(name)) {
|
||||
name = participant.user.first_name + ' ' + participant.user.last_name;
|
||||
}
|
||||
var instrumentIcon = _instrumentIconFromId(participant.tracks[0].instrument_id);
|
||||
var photoUrl = participant.user.photo_url;
|
||||
if (!(photoUrl)) {
|
||||
photoUrl = "/assets/shared/avatar_default.jpg";
|
||||
}
|
||||
|
||||
var myTrack = false;
|
||||
|
||||
// Default trackData to participant + no Mixer state.
|
||||
var trackData = {
|
||||
clientId: participant.client_id,
|
||||
name: name,
|
||||
instrumentIcon: instrumentIcon,
|
||||
avatar: photoUrl,
|
||||
latency: "good",
|
||||
gainPercent: 0,
|
||||
muteClass: 'muted',
|
||||
mixerId: ""
|
||||
};
|
||||
|
||||
var mixer = _mixerForClientId(participant.client_id, [2,7]);
|
||||
if (mixer) {
|
||||
myTrack = (mixer.group_id === 2);
|
||||
var gainPercent = percentFromMixerValue(
|
||||
mixer.range_low, mixer.range_high, mixer.volume_left);
|
||||
var muteClass = "enabled";
|
||||
if (mixer.mute) {
|
||||
muteClass = "muted";
|
||||
}
|
||||
var trackData = {
|
||||
clientId: mixer.client_id,
|
||||
name: name,
|
||||
instrumentIcon: instrumentIcon,
|
||||
avatar: photoUrl,
|
||||
latency: "good",
|
||||
gainPercent: gainPercent,
|
||||
muteClass: muteClass,
|
||||
mixerId: mixer.id
|
||||
};
|
||||
_addTrack(trackData);
|
||||
// Show settings icons only for my tracks
|
||||
if (myTrack) {
|
||||
$('div[mixer-id="' + mixer.id + '"].track-icon-settings').show();
|
||||
trackData.gainPercent = gainPercent;
|
||||
trackData.muteClass = muteClass;
|
||||
trackData.mixerId = mixer.id;
|
||||
} else { // No mixer to match, yet
|
||||
lookingForMixers[participant.client_id] = true;
|
||||
if (!(lookingForMixersTimer)) {
|
||||
lookingForMixersTimer = context.setInterval(lookForMixers, 300);
|
||||
}
|
||||
}
|
||||
_addTrack(trackData);
|
||||
// Show settings icons only for my tracks
|
||||
if (myTrack) {
|
||||
$('div[mixer-id="' + mixer.id + '"].track-icon-settings').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function called on an interval when participants change. Mixers seem to
|
||||
// show up later, so we render the tracks from participants, but keep track
|
||||
// of the ones there weren't any mixers for, and continually try to find them
|
||||
// and get them connected to the mixers underneath.
|
||||
function lookForMixers() {
|
||||
lookingForMixersCount++;
|
||||
_updateMixers();
|
||||
var keysToDelete = [];
|
||||
for (var key in lookingForMixers) {
|
||||
var mixer = _mixerForClientId(key, [2,7]);
|
||||
if (mixer) {
|
||||
keysToDelete.push(key);
|
||||
var gainPercent = percentFromMixerValue(
|
||||
mixer.range_low, mixer.range_high, mixer.volume_left);
|
||||
var $track = $('div.track[client-id="' + key + '"]');
|
||||
// Set mixer-id attributes
|
||||
$track.find('.vu').attr('mixer-id', mixer.id);
|
||||
$track.find('.track-gain').attr('mixer-id', mixer.id);
|
||||
$track.find('.track-icon-mute').attr('mixer-id', mixer.id);
|
||||
$track.find('.track-icon-settings').attr('mixer-id', mixer.id);
|
||||
|
||||
// Set gain position
|
||||
$track.find('.track-gain-slider').css('bottom', gainPercent + '%');
|
||||
|
||||
// Set mute state
|
||||
_toggleVisualMuteControl($track.find('.track-icon-mute'), mixer.mute);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=0; i<keysToDelete.length; i++) {
|
||||
delete lookingForMixers[keysToDelete[i]];
|
||||
}
|
||||
|
||||
if (context.JK.dlen(lookingForMixers) === 0 ||
|
||||
lookingForMixersCount > 10) {
|
||||
lookingForMixersCount = 0;
|
||||
lookingForMixers = {};
|
||||
context.clearTimeout(lookingForMixersTimer);
|
||||
lookingForMixersTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Given a mixerID and a value between 0.0-1.0,
|
||||
// light up the proper VU lights.
|
||||
function _updateVU(mixerId, value) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,19 @@
|
|||
return template;
|
||||
};
|
||||
|
||||
/*
|
||||
* Get the length of a dictionary
|
||||
*/
|
||||
context.JK.dlen = function(d) {
|
||||
var count = 0;
|
||||
for (var i in d) {
|
||||
if (d.hasOwnProperty(i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
/*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
|
|
|
|||
Loading…
Reference in New Issue