Class: Cyperful::UiServer

Inherits:
Object
  • Object
show all
Defined in:
lib/cyperful/ui_server.rb

Defined Under Namespace

Classes: ReverseProxy

Instance Method Summary collapse

Constructor Details

#initialize(port:) ⇒ UiServer

Returns a new instance of UiServer.



14
15
16
17
18
19
20
# File 'lib/cyperful/ui_server.rb', line 14

def initialize(port:)
  @port = port

  @notify_queue = Queue.new

  build_server
end

Instance Method Details

#notify(data) ⇒ Object



26
27
28
# File 'lib/cyperful/ui_server.rb', line 26

def notify(data)
  @notify_queue.enq(data)
end

#on_command(&block) ⇒ Object



30
31
32
# File 'lib/cyperful/ui_server.rb', line 30

def on_command(&block)
  @on_command = block
end

#shutdownObject



144
145
146
147
148
# File 'lib/cyperful/ui_server.rb', line 144

def shutdown
  @thread&.kill

  @server.shutdown
end

#start_asyncObject



135
136
137
138
139
140
141
142
# File 'lib/cyperful/ui_server.rb', line 135

def start_async
  # start server in background i.e. non-blocking
  @thread =
    Thread.new do
      Thread.current.abort_on_exception = true
      @server.start
    end
end

#url_originObject



22
23
24
# File 'lib/cyperful/ui_server.rb', line 22

def url_origin
  "http://localhost:#{@port}"
end