Class: WebSocket::EventMachine::Server
- Inherits:
-
Base
- Object
- Base
- WebSocket::EventMachine::Server
- Defined in:
- lib/websocket/eventmachine/server.rb,
lib/websocket/eventmachine/server/version.rb
Overview
WebSocket Server (using EventMachine)
Constant Summary collapse
- VERSION =
'1.0.1'
Class Method Summary collapse
-
.start(options, &block) ⇒ Object
Start server.
Instance Method Summary collapse
-
#close(code = 1000, data = nil) ⇒ Boolean
Close connection.
-
#initialize(args) ⇒ Server
constructor
Initialize connection.
-
#onclose(&blk) ⇒ Object
Called when connection is closed.
-
#onerror(&blk) ⇒ Object
Called when error occurs.
-
#onmessage(&blk) ⇒ Object
Called when message is received.
-
#onopen(&blk) ⇒ Object
Called when connection is opened.
-
#onping(&blk) ⇒ Object
Called when ping message is received One parameter passed to block: message - string with ping message.
-
#onpong(&blk) ⇒ Object
Called when pond message is received One parameter passed to block: message - string with pong message.
-
#ping(data = '') ⇒ Boolean
Send ping message.
-
#pong(data = '') ⇒ Boolean
Send pong message.
-
#post_init ⇒ Object
Eventmachine internal.
-
#send(data, args = {}) ⇒ Boolean
Send data.
Constructor Details
#initialize(args) ⇒ Server
Initialize connection
36 37 38 39 40 41 |
# File 'lib/websocket/eventmachine/server.rb', line 36 def initialize(args) @debug = !!args[:debug] @secure = !!args[:secure] @secure_proxy = args[:secure_proxy] || @secure @tls_options = args[:tls_options] || {} end |
Class Method Details
.start(options, &block) ⇒ Object
Start server
24 25 26 27 28 |
# File 'lib/websocket/eventmachine/server.rb', line 24 def self.start(, &block) ::EventMachine::start_server([:host], [:port], self, ) do |c| block.call(c) end end |
Instance Method Details
#close(code = 1000, data = nil) ⇒ Boolean
Close connection
114 |
# File 'lib/websocket/eventmachine/server.rb', line 114 def close(code = 1000, data = nil); super; end |
#onclose(&blk) ⇒ Object
Called when connection is closed. No parameters are passed to block
81 |
# File 'lib/websocket/eventmachine/server.rb', line 81 def onclose(&blk); super; end |
#onerror(&blk) ⇒ Object
Called when error occurs. One parameter passed to block:
error - string with error message
86 |
# File 'lib/websocket/eventmachine/server.rb', line 86 def onerror(&blk); super; end |
#onmessage(&blk) ⇒ Object
Called when message is received. Two parameters passed to block:
message - string with received message
type - type of message. Valid values are :text and :binary
92 |
# File 'lib/websocket/eventmachine/server.rb', line 92 def (&blk); super; end |
#onopen(&blk) ⇒ Object
Called when connection is opened. No parameters are passed to block
77 |
# File 'lib/websocket/eventmachine/server.rb', line 77 def onopen(&blk); super; end |
#onping(&blk) ⇒ Object
Called when ping message is received One parameter passed to block:
message - string with ping message
97 |
# File 'lib/websocket/eventmachine/server.rb', line 97 def onping(&blk); super; end |
#onpong(&blk) ⇒ Object
Called when pond message is received One parameter passed to block:
message - string with pong message
102 |
# File 'lib/websocket/eventmachine/server.rb', line 102 def onpong(&blk); super; end |
#ping(data = '') ⇒ Boolean
Send ping message
118 |
# File 'lib/websocket/eventmachine/server.rb', line 118 def ping(data = ''); super; end |
#pong(data = '') ⇒ Boolean
Send pong message
122 |
# File 'lib/websocket/eventmachine/server.rb', line 122 def pong(data = ''); super; end |
#post_init ⇒ Object
Eventmachine internal
49 50 51 52 53 |
# File 'lib/websocket/eventmachine/server.rb', line 49 def post_init @state = :connecting @handshake = WebSocket::Handshake::Server.new(:secure => @secure_proxy) start_tls(@tls_options) if @secure end |
#send(data, args = {}) ⇒ Boolean
Send data
110 |
# File 'lib/websocket/eventmachine/server.rb', line 110 def send(data, args = {}); super; end |