Class: Netpump::Client
- Inherits:
-
Object
- Object
- Netpump::Client
- Defined in:
- lib/netpump/client.rb
Instance Method Summary collapse
-
#initialize(mode: "direct", host: "0.0.0.0", port: "8080", proxy_host: "127.0.0.1", proxy_port: 3128, server_url: "wss://s.netpump.org", connection_inactivity_timeout: 30.0, websocket_pool_size: 20, websocket_pool_timeout: 60.0) ⇒ Client
constructor
A new instance of Client.
- #start ⇒ Object
Constructor Details
#initialize(mode: "direct", host: "0.0.0.0", port: "8080", proxy_host: "127.0.0.1", proxy_port: 3128, server_url: "wss://s.netpump.org", connection_inactivity_timeout: 30.0, websocket_pool_size: 20, websocket_pool_timeout: 60.0) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/netpump/client.rb', line 12 def initialize( mode: "direct", host: "0.0.0.0", port: "8080", proxy_host: "127.0.0.1", proxy_port: 3128, server_url: "wss://s.netpump.org", connection_inactivity_timeout: 30.0, websocket_pool_size: 20, websocket_pool_timeout: 60.0 ) @mode = mode if mode == "browser" @host = host @port = port else @host = nil @port = nil end @proxy_host = proxy_host @proxy_port = proxy_port @server_url = URI(server_url) @connection_inactivity_timeout = connection_inactivity_timeout @websocket_pool = EventMachine::Queue.new @websocket_pool_size = websocket_pool_size @websocket_pool_timeout = websocket_pool_timeout @control_ws = nil @log = lambda { |msg, **ctx| log(msg, c: true, **ctx) } @ready = EventMachine::Completion.new @ready.callback do @log.call "[+] np client is ready.", mode: @mode, host: @host, port: @port end end |
Instance Method Details
#start ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/netpump/client.rb', line 46 def start case @mode when "direct" start_proxy_server @ready.succeed when "browser" start_websocket_server print_open_url end @ready end |