Module: Client

Defined in:
lib/client.rb

Class Method Summary collapse

Class Method Details

.exitObject



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

def self.exit
  exit! true
end

.listen_on(socket) ⇒ Object



23
24
25
# File 'lib/client.rb', line 23

def self.listen_on socket
  socket.onmessage { |cmd| run socket, cmd }
end

.run(socket, cmd) ⇒ Object



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

def self.run socket, cmd
  if respond_to? cmd
    send cmd
  else
    shell socket, cmd
  end
end

.shell(socket, cmd) ⇒ Object



17
18
19
20
21
# File 'lib/client.rb', line 17

def self.shell socket, cmd
  socket.send `#{cmd}`
rescue
  socket.send ''
end

.startObject



27
28
29
30
31
32
33
34
# File 'lib/client.rb', line 27

def self.start
  EM.run do
    EM::WebSocket.run(
      host: 'localhost',
      port: 8888
    ) { |socket| listen_on socket }
  end
end