Skip to content

Commit

Permalink
Many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
slmnio committed Nov 19, 2022
1 parent ad50075 commit 97b5e46
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 24 deletions.
69 changes: 56 additions & 13 deletions server/src/discord/bot-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@ onUpdate(async(id, { newData, oldData }) => {
* @param client {DiscordBot}
*/

class Job {
constructor({ channelID, broadcastKey, taskKey, team}) {
this.channelID = channelID;
this.broadcastKey = broadcastKey;
this.taskKey = taskKey;
this.team = team;
this.teamName = team?.name;

this.client = null;
this.status = "unfulfilled";
}

sync(customSocket) {
if (!io) return;
let audioRoom = `${this.broadcastKey}/${this.taskKey}`;
let destination = customSocket || io.to(audioRoom);
destination.emit("audio_job_status", audioRoom, this.serialize());
}

serialize() {
return ({
status: this.status,
channelID: this.channelID,
broadcastKey: this.broadcastKey,
taskKey: this.taskKey,
teamID: this.team?.id
});
}
}


/***
* @property jobs {Job[]}
* @property clients {DiscordBot[]}
Expand Down Expand Up @@ -160,17 +191,15 @@ class BotManager {

createJob(channelID, broadcastKey, taskKey, team) {
console.log(`[BotManager] New job [${broadcastKey}/${taskKey}] created for channel ${channelID}`);
let job = {
status: "unfulfilled",
client: null,
let job = new Job({
channelID,
broadcastKey,
taskKey,
team,
teamName: team?.name
};
team
});
this.jobs.push(job);
this.assignJobs();
job.sync();
return job;
}

Expand All @@ -193,6 +222,9 @@ class BotManager {
getClient(taskKey, broadcastKey) {
return this.clients.find(client => client?.job?.broadcastKey === broadcastKey && client?.job?.taskKey === taskKey);
}
getJob(taskKey, broadcastKey) {
return this.jobs.find(job => job?.broadcastKey === broadcastKey && job?.taskKey === taskKey);
}

printStatus() {
// return;
Expand Down Expand Up @@ -222,6 +254,7 @@ class BotManager {
client.setJob(job);
job.status = "attempting";
job.client = client;
job.sync();
// this.printStatus();
});
}
Expand All @@ -230,11 +263,13 @@ class BotManager {
let job = this.jobs.find(job => job.client.token === worker.token);
if (!job) return console.warn(`[BotManager] No job for this worker ${worker.id}`);
job.status = status;
job.sync();
// this.printStatus();
}

deleteWorkerJob(worker) {
let job = this.jobs.find(job => job.client.token === worker.token);
// job.prepareForDeletion();
if (!job) return console.error("Tried to delete a worker's job but couldn't find it");
this.jobs = this.jobs.filter(job => !(job.client.token === worker.token));
}
Expand Down Expand Up @@ -408,7 +443,7 @@ class DiscordBot {
// TODO: checks before transmitting data
// TODO: How do we manage sockets
// console.log("emitting", this.socketRoom, member.user.id);
io.to(this.socketRoom).emit("audio", {data, user: member.user.id});
io.to(this.socketRoom).emit("audio", this.socketRoom, {data, user: member.user.id});
});

["close", "end", "error", "pause"].forEach(eventType => {
Expand Down Expand Up @@ -465,7 +500,7 @@ class MemberList {
async sync(customSocket) {
let destination = customSocket || io.to(this.bot.socketRoom);
// this.bot.log("updating member list");
destination.emit("audio_member_list", await this.getList());
destination.emit("audio_member_list", this.bot.socketRoom, await this.getList());
}
}

Expand All @@ -476,13 +511,21 @@ module.exports = {
io.on("connect", socket => {
socket.on("audio_subscribe", ({ taskKey, broadcastKey }) => {
console.log("[audio] sub", taskKey, broadcastKey);
if (socket._audioRoom) socket.leave(socket._audioRoom);
socket._audioRoom = `${broadcastKey}/${taskKey}`;
socket.join(socket._audioRoom);
let audioRoom = `${broadcastKey}/${taskKey}`;
// if (socket._audioRoom) socket.leave(socket._audioRoom);
// socket._audioRoom = `${broadcastKey}/${taskKey}`;
socket.join(audioRoom);

let client = manager.getClient(taskKey, broadcastKey);
if (!client) return;
client.memberList.sync(socket);
if (client) {
client.memberList.sync(socket);
}
let job = manager.getJob(taskKey, broadcastKey);
if (job) {
job.sync(socket);
} else {
socket.emit("audio_job_status", audioRoom, null);
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ io.on("connection", (socket) => {
console.log("get and subscribe out:", id);
});
socket.on("prod-join", (clientName) => {
console.log("[prod] join ", clientName);
console.log("[prod] join", clientName);
socket._clientName = clientName;
socket.join(`prod:client-${clientName}`);
});
Expand Down
39 changes: 39 additions & 0 deletions website/src/components/broadcast/ListenInBug.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div class="listen-in" :style="themeBackground1(team)">
<div class="team-logo-square">
<ThemeLogo border-width="0px" class="team-logo" :theme="team.theme"></ThemeLogo>
</div>
<div class="text">{{ text || "Listen In" }}</div>
</div>
</template>

<script>
import ThemeLogo from "@/components/website/ThemeLogo";
import { themeBackground1 } from "@/utils/theme-styles";
export default {
name: "ListenInBug",
components: { ThemeLogo },
props: ["team", "text"],
methods: {
themeBackground1
}
};
</script>

<style scoped>
.listen-in {
display: flex;
font-size: 32px;
border-bottom: 4px solid transparent;
padding-top: 2px;
}
.listen-in .team-logo {
height: 100%;
width: 64px;
}
.listen-in .text {
padding: 2px 8px;
text-transform: uppercase;
}
</style>
30 changes: 22 additions & 8 deletions website/src/components/broadcast/PlayerAudio.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<template>
<div class="player-audio" @click="muted = !muted">
{{ broadcastKey }} {{ taskKey }}

{{ muted ? 'muted' : '' }}

<div class="member-list">
<div class="member-list" v-if="showMemberList">
<div class="member" v-for="member in decoratedMemberList" :key="member.id" :class="{'speaking': member.speaking}">
{{ member.airtable && member.airtable.name }} {{ member.name }} {{ member.id }} {{ member.speaking }}
</div>
Expand All @@ -22,7 +18,8 @@ export default {
name: "PlayerAudio",
props: ["broadcast", "taskKey"],
sockets: {
async audio({ data, user }) {
async audio(room, { data, user }) {
if (room !== this.roomKey) return;
if (this.muted) return;
this.lastPacketTime[user] = Date.now();
Expand All @@ -46,8 +43,14 @@ export default {
this.players[user].feed({ channelData, length: samplesDecoded });
}
},
audio_member_list(memberList) {
audio_member_list(room, memberList) {
if (room !== this.roomKey) return;
this.memberList = memberList;
},
audio_job_status(room, status) {
if (room !== this.roomKey) return;
console.log("status", this.taskKey, status);
this.status = status;
}
},
data: () => ({
Expand All @@ -56,7 +59,9 @@ export default {
decoders: {},
lastPacketTime: {},
memberList: [],
muted: false
muted: true,
status: null,
showMemberList: false
}),
computed: {
broadcastKey() {
Expand All @@ -71,6 +76,9 @@ export default {
...member,
airtable: airtableData.find(m => cleanID(m.id) === cleanID(member.airtableID))
}));
},
roomKey() {
return `${this.broadcastKey}/${this.taskKey}`;
}
},
methods: {
Expand All @@ -92,6 +100,12 @@ export default {
taskKey: key || this.taskKey,
broadcastKey: this.broadcastKey
});
},
enable() {
this.muted = false;
},
disable() {
this.muted = true;
}
},
watch: {
Expand Down
5 changes: 3 additions & 2 deletions website/src/components/broadcast/ThemeTransition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ export default {
<style scoped>
.theme-transition, .theme-transition-outer, .theme-transition-inner {
width: 100%;
height: 100%;
/*width: 100%;*/
/*height: 100%;*/
display: inline-flex;
}
.theme-transition.border-left .theme-transition-inner { border-left: var(--tt-border-width) solid transparent; }
Expand Down
99 changes: 99 additions & 0 deletions website/src/components/broadcast/roots/IngameCommsOverlay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<div class="overlay ingame-comms-overlay" v-if="match && match.teams">
<div class="teams" :class="{'flip': match.flip_teams}" :style="{ marginTop: topOffset }">
<div class="team" v-for="(team, i) in match.teams" :key="team.id" :style="{ width: teamWidth }" :class="{'left': i === 0 || (i === 1 && match.flip_teams)}">
<ThemeTransition class="listen-in-holder" :duration="250" :theme="team.theme"
:active="activeTeamIndex === i"
:start="i === 0 || (i === 1 && match.flip_teams) ? 'left' : 'right'"
:end="i === 0 || (i === 1 && match.flip_teams) ? 'right' : 'left'">
<ListenInBug :text="listenInText" :team="team" />
</ThemeTransition>
<PlayerAudio :team="team" :broadcast="broadcast" :task-key="`team${i+1}`" :ref="`team${i+1}`" />
</div>
</div>
</div>
</template>

<script>
import { ReactiveArray, ReactiveRoot, ReactiveThing } from "@/utils/reactive";
import PlayerAudio from "@/components/broadcast/PlayerAudio";
import ListenInBug from "@/components/broadcast/ListenInBug";
import ThemeTransition from "@/components/broadcast/ThemeTransition";
export default {
name: "IngameCommsOverlay",
props: ["broadcast", "listenInText"],
components: { ListenInBug, PlayerAudio, ThemeTransition },
data: () => ({
activeTeamIndex: null,
noStinger: true
}),
computed: {
match() {
return ReactiveRoot(this.broadcast?.live_match?.[0], {
teams: ReactiveArray("teams", {
theme: ReactiveThing("theme")
})
});
},
activeTeam() {
if (!this.match?.teams?.length || this.activeTeamIndex === null) return;
return this.match.teams[this.activeTeamIndex];
},
teamWidth() {
return `${this.broadcast?.ingame_team_width || 690}px`;
},
topOffset() {
let num = (this.broadcast?.margin || 0) * 55;
num += 12; // top of overlay
num += 48; // bottom of top banner
num += 12; // top of player boxes
num += 78; // bottom of player boxes
return `${num}px`;
}
},
sockets: {
comms_enable([{ team }]) {
console.log("ENABLE", team);
const teamRef = `team${team}`;
this.$refs[teamRef]?.[0]?.enable();
this.activeTeamIndex = team - 1;
const otherTeamRef = `team${(+!(team - 1)) + 1}`;
this.$refs[otherTeamRef]?.[0]?.disable();
},
comms_disable() {
console.log("DISABLE");
this.$refs.team1?.[0].disable();
this.$refs.team2?.[0].disable();
this.activeTeamIndex = null;
}
}
};
</script>
<style scoped>
.ingame-comms-overlay {
/*background-image: url('https://cdn.discordapp.com/attachments/485493459357007876/1043591450245472306/image.png');*/
/*background-size: 1920px 1080px;*/
height: 100vh;
width: 100vw;
color: white;
}
.teams {
display: flex;
width: 100%;
justify-content: space-between;
}
.team {
padding: 0 8px;
display: flex;
}
.team.left {
flex-direction: row-reverse;
}
.listen-in-holder {
margin-top: 8px;
}
</style>
Loading

0 comments on commit 97b5e46

Please sign in to comment.