Skip to content

Commit

Permalink
Toggle audience participation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dermah committed Oct 14, 2019
1 parent 4dd0c6a commit 16e63dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
17 changes: 15 additions & 2 deletions pulsar/assets/js/audience/audience-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ new p5(p => {
let fireflyPower;
let fireflyDecay;

channel.on("pulse", ({ type, size, energy, amplitude, decay }) => {
let inputAllowed = false;

const instrumentMap = [
"bass/synth",
"drums",
"percussion",
"horns",
"melody"
];

channel.on("pulse", ({ type, size, energy, amplitude, decay, value }) => {
if (type === "waveform") {
energyData = energy;
totalAmp = amplitude;
} else if (type === "firefly") {
fireflyPower = size;
fireflyDecay = decay;
} else if (type === "inputAllowed") {
inputAllowed = value;
} else {
pulseSize = widthPc(size * 100);
}
Expand Down Expand Up @@ -107,7 +119,8 @@ new p5(p => {

p.textAlign(p.CENTER);
p.fill(255);
p.text(`You are ${instrument}`, p.width / 2, 15);
inputAllowed &&
p.text(`You are ${instrumentMap[instrument]}`, p.width / 2, 15);
p.push();
p.translate(p.width / 2, p.height / 2);

Expand Down
15 changes: 14 additions & 1 deletion pulsar/assets/js/clicker/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,31 @@ socket.connect();
let channel = socket.channel("audience:lobby", {});
let slideChannel = socket.channel("slides:lobby", {});
let broadcasting = true;
let allowAudience = false;

const clearButton = document.querySelector("#clear-button");
const leftButton = document.querySelector("#left-button");
const rightButton = document.querySelector("#right-button");
const fireflyButton = document.querySelector("#firefly-button");

var broadcastCheckbox = document.querySelector("#broadcasting");
const broadcastCheckbox = document.querySelector("#broadcasting");
const audienceCheckbox = document.querySelector("#allow-audience");

broadcastCheckbox.onchange = function() {
broadcasting = broadcastCheckbox.checked;
};

const audienceEnableBroadcast = () => {
channel.push("pulse", { type: "inputAllowed", value: allowAudience });
};

audienceCheckbox.onchange = function() {
allowAudience = audienceCheckbox.checked;
audienceEnableBroadcast();
};

// setInterval(() => audienceEnableBroadcast(), 2000);

clearButton.addEventListener("click", e => {
channel.push("clear", {});
});
Expand Down
9 changes: 8 additions & 1 deletion pulsar/lib/pulsar_web/templates/clicker/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
<button id="left-button">◀️</button>
<button id="right-button">▶️</button>
</div>

<button id="firefly-button">🌅</button>

<div>
<input id="broadcasting" type="checkbox" checked="true" />
<label for="broadcasting">Broadcast</label>
</div>

<button id="firefly-button">🌅</button>
<div>
<input id="allow-audience" type="checkbox"/>
<label for="allow-audience">Audience</label>
</div>

</div>

0 comments on commit 16e63dc

Please sign in to comment.