Class: InternetSampler::Service
- Inherits:
-
Object
- Object
- InternetSampler::Service
- Defined in:
- lib/internet-sampler/service.rb
Instance Attribute Summary collapse
-
#sampler ⇒ Object
readonly
Returns the value of attribute sampler.
Instance Method Summary collapse
- #add(ws) ⇒ Object
- #delete(ws) ⇒ Object
-
#initialize(subscribers, sampler) ⇒ Service
constructor
A new instance of Service.
- #play(slug, msec) ⇒ Object
- #track_info(slug) ⇒ Object
- #tracks ⇒ Object
- #update_subscribers_count ⇒ Object
Constructor Details
#initialize(subscribers, sampler) ⇒ Service
Returns a new instance of Service.
5 6 7 8 |
# File 'lib/internet-sampler/service.rb', line 5 def initialize(subscribers, sampler) @sub = subscribers @sampler = sampler end |
Instance Attribute Details
#sampler ⇒ Object (readonly)
Returns the value of attribute sampler.
3 4 5 |
# File 'lib/internet-sampler/service.rb', line 3 def sampler @sampler end |
Instance Method Details
#add(ws) ⇒ Object
26 27 28 |
# File 'lib/internet-sampler/service.rb', line 26 def add ws @sub.add ws end |
#delete(ws) ⇒ Object
30 31 32 |
# File 'lib/internet-sampler/service.rb', line 30 def delete ws @sub.delete ws end |
#play(slug, msec) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/internet-sampler/service.rb', line 10 def play slug, msec if @sampler.has_track? slug i = @sampler.incr slug EM.next_tick do @sub.broadcast({ type: :play, count: i, slug: slug, msec: msec }.to_json) end else puts :err end end |
#track_info(slug) ⇒ Object
45 46 47 |
# File 'lib/internet-sampler/service.rb', line 45 def track_info slug @sampler.track_info slug end |
#tracks ⇒ Object
41 42 43 |
# File 'lib/internet-sampler/service.rb', line 41 def tracks @sampler.tracks end |
#update_subscribers_count ⇒ Object
34 35 36 37 38 39 |
# File 'lib/internet-sampler/service.rb', line 34 def update_subscribers_count @sub.broadcast({ type: :num, count: @sub.count, }.to_json) end |