Class: Nodectl::Stream::FileSession
- Inherits:
-
Object
- Object
- Nodectl::Stream::FileSession
- Defined in:
- lib/nodectl/stream/file_session.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#websocket ⇒ Object
readonly
Returns the value of attribute websocket.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(websocket, handshake, file) ⇒ FileSession
constructor
A new instance of FileSession.
- #onclose(&block) ⇒ Object
- #publish(message) ⇒ Object
Constructor Details
#initialize(websocket, handshake, file) ⇒ FileSession
Returns a new instance of FileSession.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nodectl/stream/file_session.rb', line 7 def initialize(websocket, handshake, file) @websocket = websocket @handshake = handshake @file = file @buffer = Nodectl::Stream::Buffer.new @file.onread do |chunk| @buffer << chunk publish(@buffer.read) end self.class[self.class.next_id] = self end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/nodectl/stream/file_session.rb', line 5 def file @file end |
#websocket ⇒ Object (readonly)
Returns the value of attribute websocket.
4 5 6 |
# File 'lib/nodectl/stream/file_session.rb', line 4 def websocket @websocket end |
Instance Method Details
#close ⇒ Object
26 27 28 29 30 |
# File 'lib/nodectl/stream/file_session.rb', line 26 def close self.class.delete(self) @file.close @websocket.close unless @websocket.closed? end |
#onclose(&block) ⇒ Object
32 33 34 |
# File 'lib/nodectl/stream/file_session.rb', line 32 def onclose(&block) @websocket.onclose(&block) end |