Class: Radiodan::Panic
- Inherits:
-
Object
show all
- Includes:
- Logging
- Defined in:
- lib/radiodan/middleware/panic.rb
Instance Method Summary
collapse
Methods included from Logging
included, level, level=, #logger, output, output=
Constructor Details
#initialize(config) ⇒ Panic
Returns a new instance of Panic.
5
6
7
8
9
|
# File 'lib/radiodan/middleware/panic.rb', line 5
def initialize(config)
@panic = false
@timeout = config.delete(:duration).to_i
@playlist = config[:playlist]
end
|
Instance Method Details
#call(player) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/radiodan/middleware/panic.rb', line 11
def call(player)
@player = player
@player.register_event :panic do
panic!
end
end
|
#panic! ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/radiodan/middleware/panic.rb', line 23
def panic!
return true if panic?
@panic = true
original_state = @player.playlist
logger.debug "panic for #{@timeout} seconds"
@player.playlist = @playlist
EM::Synchrony.add_timer(@timeout) do
return_to_state original_state
end
end
|
#panic? ⇒ Boolean
19
20
21
|
# File 'lib/radiodan/middleware/panic.rb', line 19
def panic?
@panic == true
end
|
#return_to_state(playlist) ⇒ Object
37
38
39
40
41
|
# File 'lib/radiodan/middleware/panic.rb', line 37
def return_to_state(playlist)
logger.debug "calming"
@panic = false
@player.playlist = playlist
end
|