Notify clients only if buddies change
This commit is contained in:
		
							parent
							
								
									f2a48823d1
								
							
						
					
					
						commit
						1bce467a7c
					
				| 
						 | 
				
			
			@ -120,24 +120,22 @@ exports.create = function(server) {
 | 
			
		|||
                    }
 | 
			
		||||
                    return result;
 | 
			
		||||
                }, []);
 | 
			
		||||
                var currState = hash(buddies.toString());
 | 
			
		||||
                var socket = client.socket;
 | 
			
		||||
                //protocol
 | 
			
		||||
                var msg = {
 | 
			
		||||
                    buddies: buddies,
 | 
			
		||||
                    isSystemEvent: true,
 | 
			
		||||
                    type: 'buddies'
 | 
			
		||||
                };
 | 
			
		||||
                if (buddies.length) {
 | 
			
		||||
                    client.socket.send(msg);
 | 
			
		||||
                    client.notifiedEmpty = false;
 | 
			
		||||
                if (currState !== socket.lastState) {
 | 
			
		||||
                    socket.send(msg);
 | 
			
		||||
                    socket.lastState = currState;
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                if (!client.notifiedEmpty) {
 | 
			
		||||
                    client.notifiedEmpty = true;
 | 
			
		||||
                    client.socket.send(msg);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setInterval(notifyBuddiesX, 5000);
 | 
			
		||||
    setInterval(notifyBuddiesX, 3000);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue