尝试使用实时数据库通信时未收到通知

Not getting a notification when trying to use real-time database communications

我正在尝试使用网络套接字向我的应用添加新通知。我正在使用 Backand 作为我的服务器,但似乎无法掌握如何响应新事件。这是我发送事件的服务器端代码:

//Action: Update - After data saved and committed 
function backandCallback(userInput, dbRow, parameters, userProfile) {  
   //Send to array of users   
   socket.emitUsers("new_notification",userInput, ["admins"]);
  return {}; 
} 

我的客户端接收代码:

//Wait for server updates on 'items' object 
Backand.on('new_notification', function (data) {   
  //Get the 'items' object that have changed   
  console.log(data);
});

但是当我尝试在我的应用程序代码中接收事件时,我从未看到 "new_notification" 类型的通知。有人可以告诉我发生了什么事吗?

确保您使用的是 emitRole 而不是 emitUsers。上面的代码发送到一个用户数组,但看起来您想向 "admins" 角色发送通知。将其更改为 emitRole(),您应该没问题。

对于您希望保持区分大小写的角色,它将是: socket.emitRole("items_updated",userInput, "Admin");

对于用户来说,语法是: socket.emitUsers("items_updated",userInput, ["user2@gmail.com","user1@gmail.com"]);