class WebSocketRb::Service::FramesSender
Attributes
connections[R]
Public Class Methods
new(connections, connection)
click to toggle source
# 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
Public Instance Methods
frame_to_broadcast(frame)
click to toggle source
Method to send frame in all connections
# 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)
click to toggle source
Method to send frame in current connection
# File lib/web_socket_rb/service/frames_sender.rb, line 22 def frame_to_send(frame) @frames_to_send << frame end
Private Instance Methods
broadcast_frame(frame)
click to toggle source
Broadcast message through all connections
# File lib/web_socket_rb/service/frames_sender.rb, line 40 def broadcast_frame(frame) @connections.each do |conn| conn.write(frame.to_bytes) end end
send_frame(frame)
click to toggle source
Broadcast message through current connection
# File lib/web_socket_rb/service/frames_sender.rb, line 34 def send_frame(frame) @connection.write(frame.to_bytes) Thread.close if frame.close? end