Class: WebSocketHook
- Inherits:
-
Object
- Object
- WebSocketHook
- Defined in:
- lib/websockethook.rb
Constant Summary collapse
- DEFAULT_HOST =
'ws://websockethook.io'- DEFAULT_SLEEP =
0.1
- DEFAULT_KEEP_ALIVE =
true- DEFAULT_PING =
20
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ WebSocketHook
constructor
A new instance of WebSocketHook.
- #listen(id = nil, &block) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ WebSocketHook
Returns a new instance of WebSocketHook.
11 12 13 14 15 16 17 |
# File 'lib/websockethook.rb', line 11 def initialize( = {}) @stopping = false initialize_host initialize_pause initialize_keep_alive initialize_ping end |
Instance Method Details
#listen(id = nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/websockethook.rb', line 19 def listen(id=nil, &block) fail 'Block must be provided' unless block && block.is_a?(Proc) begin @stopping = false listener(id, &block) restart = @keep_alive && !@stopping if restart block.call type: 'restart', message: 'restarting connection since it was lost' sleep 5 end end while restart end |
#stop ⇒ Object
32 33 34 35 |
# File 'lib/websockethook.rb', line 32 def stop @stopping = true stop_em end |