openvidu-components: Play sound when a new message is received

pull/707/head
csantosm 2022-02-23 12:10:16 +01:00
parent 8ab769161b
commit 8ee9d74d3d
1 changed files with 5 additions and 1 deletions

View File

@ -19,7 +19,7 @@ import { MenuType } from '../../models/menu.model';
}) })
export class ChatService { export class ChatService {
messagesObs: Observable<ChatMessage[]>; messagesObs: Observable<ChatMessage[]>;
private messageSound: HTMLAudioElement;
protected _messageList = <BehaviorSubject<ChatMessage[]>>new BehaviorSubject([]); protected _messageList = <BehaviorSubject<ChatMessage[]>>new BehaviorSubject([]);
protected messageList: ChatMessage[] = []; protected messageList: ChatMessage[] = [];
protected log: ILogger; protected log: ILogger;
@ -32,6 +32,8 @@ export class ChatService {
) { ) {
this.log = this.loggerSrv.get('ChatService'); this.log = this.loggerSrv.get('ChatService');
this.messagesObs = this._messageList.asObservable(); this.messagesObs = this._messageList.asObservable();
this.messageSound = new Audio('assets/audio/message_sound.mp3');
this.messageSound.volume = 0.5;
} }
subscribeToChat() { subscribeToChat() {
@ -52,6 +54,8 @@ export class ChatService {
buttonActionText: 'READ' buttonActionText: 'READ'
}; };
this.launchNotification(notificationOptions); this.launchNotification(notificationOptions);
this.messageSound.play().catch(() => {});
} }
this._messageList.next(this.messageList); this._messageList.next(this.messageList);
}); });