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.



5
6
7
8
9
10
11
# File 'lib/cyperful/ui_server.rb', line 5

def initialize(port:)
  @port = port

  @notify_queue = Queue.new

  build_server
end

Instance Method Details

#notify(data) ⇒ Object



17
18
19
# File 'lib/cyperful/ui_server.rb', line 17

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

#on_command(&block) ⇒ Object



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

def on_command(&block)
  @on_command = block
end

#shutdownObject



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

def shutdown
  @thread&.kill

  @server.shutdown
end

#start_asyncObject



126
127
128
129
130
131
132
133
# File 'lib/cyperful/ui_server.rb', line 126

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



13
14
15
# File 'lib/cyperful/ui_server.rb', line 13

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