Class: Cybertrain::WebSocket::Subscription

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/websocket.rb

Overview

One registered feed, from subscribe. Distinctive accessor names and no #call (NOTES rules 10/34/40).

Instance Method Summary collapse

Instance Method Details

#on_message(&block) ⇒ Subscription

Sets the block called with each message: |conn, data|, a Connection and the bytes (a text message is UTF-8 as the server sent it, not checked). Required before Cybertrain::WebSocket.start!.

Returns:



182
183
184
185
# File 'cybertrain/websocket.rb', line 182

def on_message(&block)
  @sub_message_block = block
  self
end

#on_open(&block) ⇒ Subscription

Sets the block called after each (re)connect, before any message: send the subscription request here. It receives a Connection.

Returns:



172
173
174
175
# File 'cybertrain/websocket.rb', line 172

def on_open(&block)
  @sub_open_block = block
  self
end

#sub_name ⇒ String

Returns the name given to Cybertrain::WebSocket.subscribe.

Returns:



164
165
166
# File 'cybertrain/websocket.rb', line 164

def sub_name
  @sub_name
end