Skip to content
Extraits de code Groupes Projets
Valider 088da254 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

RS, DG; We now delete channels when there is nobody subscribed to them

parent 59147eb2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -26,17 +26,26 @@ module WebSocket ...@@ -26,17 +26,26 @@ module WebSocket
def self.push_to_user(uid, data) def self.push_to_user(uid, data)
puts "Pushing to #{uid}" puts "Pushing to #{uid}"
@channels[uid.to_s].push(data) if @channels[uid.to_s] @channels[uid.to_s][0].push(data) if @channels[uid.to_s]
end end
def self.subscribe(uid, ws) def self.subscribe(uid, ws)
puts "Subscribing #{uid}" puts "Subscribing #{uid}"
@channels[uid] ||= EM::Channel.new self.ensure_channel(uid)
@channels[uid].subscribe{ |msg| ws.send msg } @channels[uid][0].subscribe{ |msg| ws.send msg }
@channels[uid][1] += 1
end
def self.ensure_channel(uid)
@channels[uid] ||= [EM::Channel.new, 0 ]
end end
def self.unsubscribe(uid,sid) def self.unsubscribe(uid,sid)
@channels[uid].unsubscribe(sid) if @channels[uid] @channels[uid][0].unsubscribe(sid) if @channels[uid]
@channels[uid][1] -= 1
if @channels[uid][1] <= 0
@channels[uid] = nil
end
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter