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.
184 185 186 187 188 189 190 |
# File 'lib/faye/websocket.rb', line 184 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
192 193 194 |
# File 'lib/faye/websocket.rb', line 192 def each(&callback) @stream_send ||= callback end |
#fail ⇒ Object
196 197 198 |
# File 'lib/faye/websocket.rb', line 196 def fail @web_socket.close(1006, '', false) end |
#receive(data) ⇒ Object
200 201 202 |
# File 'lib/faye/websocket.rb', line 200 def receive(data) @web_socket.__send__(:parse, data) end |
#write(data) ⇒ Object
204 205 206 207 |
# File 'lib/faye/websocket.rb', line 204 def write(data) return unless @stream_send @stream_send.call(data) rescue nil end |