Class: Riddl::Protocols::WebSocket

Inherits:
EventMachine::WebSocket::Connection
  • Object
show all
Defined in:
lib/ruby/riddl/protocols/websocket.rb

Defined Under Namespace

Classes: Error, ParserData

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, socket) ⇒ WebSocket

Returns a new instance of WebSocket.



95
96
97
98
99
100
101
102
# File 'lib/ruby/riddl/protocols/websocket.rb', line 95

def initialize(app, socket)
  @app = app
  @socket = socket
  @ssl = socket.backend.respond_to?(:ssl?) && socket.backend.ssl?
  @closed = true
  socket.websocket = self
  socket.comm_inactivity_timeout = 0
end

Class Method Details

.new(*args) ⇒ Object



69
70
71
72
73
# File 'lib/ruby/riddl/protocols/websocket.rb', line 69

def self.new(*args)
  instance = allocate
  instance.__send__(:initialize, *args)
  instance
end

Instance Method Details

#close_connection(*args) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/ruby/riddl/protocols/websocket.rb', line 81

def close_connection(*args)
  EM.next_tick do
    unless closed?
      @socket.close_connection(*args)
      trigger_on_close
    end
  end
end

#closed?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/ruby/riddl/protocols/websocket.rb', line 104

def closed?
  @closed
end

#send_data(data) ⇒ Object



75
76
77
78
79
# File 'lib/ruby/riddl/protocols/websocket.rb', line 75

def send_data(data)
  EM.next_tick do
    @socket.send_data(data) unless closed?
  end
end

#trigger_on_closeObject



92
# File 'lib/ruby/riddl/protocols/websocket.rb', line 92

def trigger_on_close;           @closed = true;  @app.onclose;              end

#trigger_on_error(error) ⇒ Object



93
# File 'lib/ruby/riddl/protocols/websocket.rb', line 93

def trigger_on_error(error);    @closed = true;  @app.onerror(error); true; end

#trigger_on_message(msg) ⇒ Object



90
# File 'lib/ruby/riddl/protocols/websocket.rb', line 90

def trigger_on_message(msg);    @app.onmessage(msg);                        end

#trigger_on_open(handshake) ⇒ Object



91
# File 'lib/ruby/riddl/protocols/websocket.rb', line 91

def trigger_on_open(handshake); @closed = false; @app.onopen;               end