Push notification 当Firebase有一个新的子对象时向客户端推送通知';行不通

Push notification 当Firebase有一个新的子对象时向客户端推送通知';行不通,push-notification,socket.io,firebase,Push Notification,Socket.io,Firebase,下面的代码正在侦听添加到Firebase的新子级,然后使用socket.io将其推送到客户端,问题是socket.io无法触发发射,您知道如何让它将数据发送到客户端吗 服务器: FirebaseRef.endAt().limitToLast(1).on('child_added', function (childSnapshot, prevChildKey) { console.log('new GPS point added ' + childSnapshot.val()); io.on('

下面的代码正在侦听添加到Firebase的新子级,然后使用socket.io将其推送到客户端,问题是socket.io无法触发发射,您知道如何让它将数据发送到客户端吗

服务器:

FirebaseRef.endAt().limitToLast(1).on('child_added', function (childSnapshot, prevChildKey) {
console.log('new GPS point added ' + childSnapshot.val());

io.on('connection', function (socket) {
    console.log('new GPS point added 2' + childSnapshot.val());
    socket.volatile.emit('GpsPoint', childSnapshot.val());

    socket.on('my other event', function (data) {
        console.log(data);
    });
}); });
客户:(内部角度控制)


插座连接应在Firebase功能外完成:

var sockets=[];
io.on('connection', function (socket) {
console.log('New socket: '+ socket);
sockets.push(socket);});  
在Firebase函数中,我们应该使用已经连接到客户端的套接字:

FirebaseRef.endAt().limitToLast(1).on('child_added', function (childSnapshot, prevChildKey) {
  for(var i=0;i<sockets.length;++i) {
      console.log('Socket'+sockets[i]);
      socket=sockets[i];
      socket.volatile.emit('GpsPoint', childSnapshot.val());
}});
FirebaseRef.endAt().limitToLast(1).on('child_added',函数(childSnapshot,prevChildKey){
对于(var i=0;i
FirebaseRef.endAt().limitToLast(1).on('child_added', function (childSnapshot, prevChildKey) {
  for(var i=0;i<sockets.length;++i) {
      console.log('Socket'+sockets[i]);
      socket=sockets[i];
      socket.volatile.emit('GpsPoint', childSnapshot.val());
}});