fix https, prevent audio spam
This commit is contained in:
parent
f9307278c6
commit
7d30426a08
1 changed files with 13 additions and 1 deletions
|
@ -15,6 +15,7 @@ export class MSAgentClient {
|
||||||
private socket: WebSocket | null;
|
private socket: WebSocket | null;
|
||||||
private events: Emitter;
|
private events: Emitter;
|
||||||
private users: User[];
|
private users: User[];
|
||||||
|
private playingAudio: Map<string, HTMLAudioElement> = new Map();
|
||||||
|
|
||||||
private username: string | null = null;
|
private username: string | null = null;
|
||||||
private agent: string | null = null;
|
private agent: string | null = null;
|
||||||
|
@ -37,7 +38,7 @@ export class MSAgentClient {
|
||||||
case "http:":
|
case "http:":
|
||||||
url.protocol = "ws:";
|
url.protocol = "ws:";
|
||||||
break;
|
break;
|
||||||
case "https":
|
case "https:":
|
||||||
url.protocol = "wss:";
|
url.protocol = "wss:";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -125,6 +126,9 @@ export class MSAgentClient {
|
||||||
let remUserMsg = msg as MSAgentRemoveUserMessage;
|
let remUserMsg = msg as MSAgentRemoveUserMessage;
|
||||||
let user = this.users.find(u => u.username === remUserMsg.data.username);
|
let user = this.users.find(u => u.username === remUserMsg.data.username);
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
|
if (this.playingAudio.has(user!.username)) {
|
||||||
|
this.playingAudio.delete(user!.username);
|
||||||
|
}
|
||||||
this.users.splice(this.users.indexOf(user), 1);
|
this.users.splice(this.users.indexOf(user), 1);
|
||||||
this.events.emit('remuser', user);
|
this.events.emit('remuser', user);
|
||||||
break;
|
break;
|
||||||
|
@ -135,6 +139,14 @@ export class MSAgentClient {
|
||||||
this.events.emit('chat', user, chatMsg.data.message);
|
this.events.emit('chat', user, chatMsg.data.message);
|
||||||
if (chatMsg.data.audio !== undefined) {
|
if (chatMsg.data.audio !== undefined) {
|
||||||
let audio = new Audio(this.url + chatMsg.data.audio);
|
let audio = new Audio(this.url + chatMsg.data.audio);
|
||||||
|
if (this.playingAudio.has(user!.username)) {
|
||||||
|
this.playingAudio.get(user!.username)?.pause();
|
||||||
|
this.playingAudio.delete(user!.username);
|
||||||
|
}
|
||||||
|
this.playingAudio.set(user!.username, audio);
|
||||||
|
audio.addEventListener('ended', () => {
|
||||||
|
this.playingAudio.delete(user!.username);
|
||||||
|
});
|
||||||
audio.play();
|
audio.play();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue