class Jebanni::Channel
Attributes
connections[R]
history[R]
id[R]
server[R]
Public Class Methods
new(id, server)
click to toggle source
# File lib/jebanni/channel.rb, line 5 def initialize(id, server) @id = id @history = [] @last_event_id = 0 @server = server @connections = [] end
Public Instance Methods
broadcast(data, event = nil)
click to toggle source
# File lib/jebanni/channel.rb, line 28 def broadcast(data, event = nil) @last_event_id += 1 @history << {id: @last_event_id, event: event, data: data} #only keep the last 5000 Events if @history.size >= 6000 @history.slice!(0, @history.size - 1000) end server.broadcast_to(self, data, event, @last_event_id) end
join(connection)
click to toggle source
# File lib/jebanni/channel.rb, line 13 def join(connection) @connections << connection end
leave(connection)
click to toggle source
# File lib/jebanni/channel.rb, line 17 def leave(connection) @connections.delete connection end
refrain(since)
click to toggle source
# File lib/jebanni/channel.rb, line 21 def refrain(since) @history.each do |history| next if history[:id] <= since server.broadcast_to(self, history[:data], history[:event], history[:id]) end end