Add deafen button

This commit is contained in:
Ryan Alexander
2021-08-22 12:22:44 +10:00
parent db43c02e01
commit ccda5e8609
7 changed files with 124 additions and 16 deletions

View File

@@ -40,6 +40,8 @@ export default class VoiceClient extends EventEmitter<VoiceEvents> {
sendTransport?: Transport;
recvTransport?: Transport;
isDeaf?: boolean;
userId?: string;
roomId?: string;
participants: Map<string, VoiceUser>;
@@ -54,6 +56,8 @@ export default class VoiceClient extends EventEmitter<VoiceEvents> {
this.participants = new Map();
this.consumers = new Map();
this.isDeaf = false;
this.signaling.on(
"data",
(json) => {

View File

@@ -143,6 +143,33 @@ class VoiceStateReference {
}
}
isDeaf() {
if(!this.client)
return false;
return this.client.isDeaf;
}
async startDeafen() {
if(!this.client)
return console.log("No client object"); // ! TODO: let the user know
this.client.isDeaf = true;
this.client?.consumers.forEach(consumer => {
consumer.audio?.pause();
})
}
async stopDeafen() {
if(!this.client)
return console.log("No client object"); // ! TODO: let the user know
this.client.isDeaf = false;
this.client?.consumers.forEach(consumer => {
consumer.audio?.resume();
})
}
async startProducing(type: ProduceType) {
switch (type) {
case "audio": {