Class: MultiScreen

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/multi_screen.rb

Class Method Summary collapse

Class Method Details

.channelsObject



9
10
11
12
13
14
15
16
# File 'lib/sinatra/multi_screen.rb', line 9

def self.channels
  @@channels ||= Hash.new{|h,channel_id|
    h[channel_id] = {
      'tv' => [],
      'remote' => []
    }
  }
end

.push(event, data, opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sinatra/multi_screen.rb', line 18

def self.push(event, data, opts={})
  ids = nil
  channel = opts[:channel].to_s
  type = opts[:type].to_s
  if !channel.empty? and !type.empty?
    ids = channels[channel][type] or []
  elsif !channel.empty?
    ids = channels[channel].values.flatten or []
  elsif !type.empty?
    ids = channels.values.map{|i| i[type] }.flatten or []
  else
    ids = channels.values.map{|i| i.values }.flatten or []
  end
  ids.each do |session_id|
    CometIO.push(:__multiscreen__server,
                 {:event => event, :data => data},
                 {:to => session_id})
  end
end