Class: WebSocketRb::Context::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/web_socket_rb/context/sandbox.rb

Instance Method Summary collapse

Constructor Details

#initialize(frames_sender) ⇒ Sandbox

Returns a new instance of Sandbox.



7
8
9
# File 'lib/web_socket_rb/context/sandbox.rb', line 7

def initialize(frames_sender)
  @frames_sender = frames_sender
end

Instance Method Details

#broadcast_message(destination, message) ⇒ Object

Method to broadcast message to all clients



23
24
25
26
# File 'lib/web_socket_rb/context/sandbox.rb', line 23

def broadcast_message(destination, message)
  frame = Service::BuildTextFrameService.new(destination, message).run
  @frames_sender.frame_to_broadcast(frame)
end

#connections_sizeObject

Method to get count of current connections



12
13
14
# File 'lib/web_socket_rb/context/sandbox.rb', line 12

def connections_size
  @frames_sender.connections.size
end

#send_message(destination, message) ⇒ Object

Method to send message to client



17
18
19
20
# File 'lib/web_socket_rb/context/sandbox.rb', line 17

def send_message(destination, message)
  frame = Service::BuildTextFrameService.new(destination, message).run
  @frames_sender.frame_to_send(frame)
end