Class: WebSocketRb::Service::FramesSender
- Inherits:
-
Object
- Object
- WebSocketRb::Service::FramesSender
- Defined in:
- lib/web_socket_rb/service/frames_sender.rb
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Instance Method Summary collapse
-
#frame_to_broadcast(frame) ⇒ Object
Method to send frame in all connections.
-
#frame_to_send(frame) ⇒ Object
Method to send frame in current connection.
-
#initialize(connections, connection) ⇒ FramesSender
constructor
A new instance of FramesSender.
Constructor Details
#initialize(connections, connection) ⇒ FramesSender
Returns a new instance of FramesSender.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/web_socket_rb/service/frames_sender.rb', line 6 def initialize(connections, connection) @connections = connections @connection = connection @frames_to_send = [] @frames_to_broadcast = [] Thread.new do loop do frame = @frames_to_send.shift send_frame(frame) unless frame.nil? frame = @frames_to_broadcast.shift broadcast_frame(frame) unless frame.nil? end end end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
4 5 6 |
# File 'lib/web_socket_rb/service/frames_sender.rb', line 4 def connections @connections end |
Instance Method Details
#frame_to_broadcast(frame) ⇒ Object
Method to send frame in all connections
27 28 29 |
# File 'lib/web_socket_rb/service/frames_sender.rb', line 27 def frame_to_broadcast(frame) @frames_to_broadcast << frame end |
#frame_to_send(frame) ⇒ Object
Method to send frame in current connection
22 23 24 |
# File 'lib/web_socket_rb/service/frames_sender.rb', line 22 def frame_to_send(frame) @frames_to_send << frame end |