Skip to content

Commit 9da2032

Browse files
authored
feat: Add voice statuses for participants, channels, and servers (#166)
This will allow marking servers as having active voice members Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
1 parent 3453407 commit 9da2032

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

src/classes/Channel.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { Message } from "./Message.js";
3030
import type { Server } from "./Server.js";
3131
import type { ServerMember } from "./ServerMember.js";
3232
import type { User } from "./User.js";
33-
import { VoiceParticipant } from "./VoiceParticipant.js";
33+
import { VoiceParticipant, VoiceStatus } from "./VoiceParticipant.js";
3434

3535
/**
3636
* Channel Class
@@ -850,4 +850,28 @@ export class Channel {
850850
channel: this.id,
851851
});
852852
}
853+
854+
/**
855+
* The voice status of a channel. Screenshare supersedes video, video
856+
* supersedes voice, and voice supersedes none. This getter takes the highest
857+
* priority status from all participants in the channel.
858+
*/
859+
get voiceStatus(): VoiceStatus {
860+
if (!this.isVoice || this.voiceParticipants.size === 0) {
861+
return "none";
862+
}
863+
864+
let highest: VoiceStatus = "voice";
865+
for (const participant of this.voiceParticipants.values()) {
866+
const status = participant.voiceStatus;
867+
if (status === "screenshare") {
868+
return "screenshare";
869+
}
870+
if (status === "video") {
871+
highest = "video";
872+
}
873+
}
874+
875+
return highest;
876+
}
853877
}

src/classes/Server.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {
1313
DataEditRole,
1414
DataEditServer,
1515
Override,
16-
OverrideField,
1716
Role,
1817
} from "stoat-api";
1918
import { decodeTime } from "ulid";
@@ -35,6 +34,7 @@ import { ServerBan } from "./ServerBan.js";
3534
import { ServerMember } from "./ServerMember.js";
3635
import { ServerRole } from "./ServerRole.js";
3736
import { User } from "./User.js";
37+
import { VoiceStatus } from "./VoiceParticipant.js";
3838

3939
/**
4040
* Server Class
@@ -827,4 +827,28 @@ export class Server {
827827
async deleteEmoji(emojiId: string): Promise<void> {
828828
await this.#collection.client.api.delete(`/custom/emoji/${emojiId}`);
829829
}
830+
831+
/**
832+
* The voice status of a server. Screenshare supersedes video, video
833+
* supersedes voice, and voice supersedes none. This getter takes the highest
834+
* priority status from all channels in the server.
835+
*/
836+
get voiceStatus(): VoiceStatus {
837+
let highest: VoiceStatus = "none";
838+
839+
for (const chan of this.channels) {
840+
const status = chan.voiceStatus;
841+
if (status === "screenshare") {
842+
return "screenshare";
843+
}
844+
if (status === "video") {
845+
highest = "video";
846+
}
847+
if (status === "voice" && highest === "none") {
848+
highest = "voice";
849+
}
850+
}
851+
852+
return highest;
853+
}
830854
}

src/classes/VoiceParticipant.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Accessor, Setter, createSignal } from "solid-js";
33
import type { Client } from "../Client.js";
44
import { UserVoiceState } from "../events/v1.js";
55

6+
/**
7+
* The voice status of an entity. Screenshare supersedes video, video supersedes voice, and voice supersedes none.
8+
*/
9+
export type VoiceStatus = "none" | "voice" | "video" | "screenshare";
10+
611
/**
712
* Voice Participant
813
*/
@@ -71,4 +76,17 @@ export class VoiceParticipant {
7176
this.#setCamera(data.camera);
7277
}
7378
}
79+
80+
/**
81+
* The voice status of a participant. Screenshare supersedes video, video supersedes voice, and voice supersedes none.
82+
*/
83+
get voiceStatus(): VoiceStatus {
84+
if (this.isScreensharing()) {
85+
return "screenshare";
86+
}
87+
if (this.isCamera()) {
88+
return "video";
89+
}
90+
return "voice";
91+
}
7492
}

0 commit comments

Comments
 (0)