Class: Adsf::Live::WebSocketServer

Inherits:
Object
  • Object
show all
Defined in:
lib/adsf/live/web_socket_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:) ⇒ WebSocketServer

Returns a new instance of WebSocketServer.



6
7
8
9
10
11
12
13
14
# File 'lib/adsf/live/web_socket_server.rb', line 6

def initialize(host:, port:)
  @host = host
  @port = port

  @thread = start
  @sockets = []

  @stopped_waiter = SizedQueue.new(1)
end

Instance Method Details

#reload(paths) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/adsf/live/web_socket_server.rb', line 21

def reload(paths)
  paths.each do |path|
    data =
      JSON.dump(
        command: 'reload',
        path: "#{Dir.pwd}#{path}",
      )

    @sockets.each { |ws| ws.send(data) }
  end
end

#stopObject



16
17
18
19
# File 'lib/adsf/live/web_socket_server.rb', line 16

def stop
  EventMachine.stop
  @stopped_waiter.pop
end