Class: Faye::WebSocket::Stream
- Inherits:
-
Object
- Object
- Faye::WebSocket::Stream
- Extended by:
- Forwardable
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/faye/websocket.rb
Instance Method Summary collapse
- #each(&callback) ⇒ Object
- #fail ⇒ Object
-
#initialize(web_socket) ⇒ Stream
constructor
A new instance of Stream.
- #receive(data) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(web_socket) ⇒ Stream
Returns a new instance of Stream.
185 186 187 188 189 190 191 |
# File 'lib/faye/websocket.rb', line 185 def initialize(web_socket) @web_socket = web_socket @connection = web_socket.env['em.connection'] @stream_send = web_socket.env['stream.send'] @connection.socket_stream = self if @connection.respond_to?(:socket_stream) end |
Instance Method Details
#each(&callback) ⇒ Object
193 194 195 |
# File 'lib/faye/websocket.rb', line 193 def each(&callback) @stream_send ||= callback end |
#fail ⇒ Object
197 198 199 |
# File 'lib/faye/websocket.rb', line 197 def fail @web_socket.close(1006, '', false) end |
#receive(data) ⇒ Object
201 202 203 |
# File 'lib/faye/websocket.rb', line 201 def receive(data) @web_socket.__send__(:parse, data) end |
#write(data) ⇒ Object
205 206 207 208 |
# File 'lib/faye/websocket.rb', line 205 def write(data) return unless @stream_send @stream_send.call(data) rescue nil end |