如何在 Meteor 的集合(cursor.observeChanges)中插入新记录时播放音频以通知

How to play an audio to notify when new record is inserted in collection(cursor.observeChanges) in Meteor

我有一个流星应用程序,当新记录输入 collection.For 时,我试图在客户端通知我,我尝试使用 cursor.observeChanges 并能够在客户端发出通知消息side..但除此之外,我需要播放小音频或警报,以便我们可以轻松识别它。我试过了,但它不起作用

var cursor = customerDetails.find();
    cursor.observeChanges({
    added: function(id, object) {
   Notification.error('NEW Record');
   var audio = new Audio('audio.mp3');
    audio.addEventListener('cursor.observeChanges', function() {
        console.log("Inside Audio");
    audio.play();
    });
     }
    });

我将音频文件保存在 public folder.Can 有人帮助我如何播放这个

您在每次添加记录时都添加了一个事件侦听器,但侦听器没有被触发。相反,只要添加记录,您就应该 运行 audio.play()

var audio = new Audio('audio.mp3');
var cursor = customerDetails.find();
cursor.observeChanges({
    added: function(id, object) {
        Notification.error('NEW Record');
        console.log("Record added")
        audio.play();
    }
});