Class: DRb::WebSocket::Server
- Inherits:
-
Object
- Object
- DRb::WebSocket::Server
- Defined in:
- lib/drb/websocket/server.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #accept ⇒ Object
- #close ⇒ Object
-
#initialize(uri, config) ⇒ Server
constructor
A new instance of Server.
- #on_message(data) ⇒ Object
- #on_session_start(ws) ⇒ Object
- #push(callback) ⇒ Object
Constructor Details
#initialize(uri, config) ⇒ Server
Returns a new instance of Server.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/drb/websocket/server.rb', line 46 def initialize(uri, config) @uri = uri @config = config @queue = Thread::Queue.new Faye::WebSocket.load_adapter('thin') u = URI.parse(uri) RackApp.register(uri, self) if RackApp.config.standalone Thread.new do app = RackApp.new(-> { [400, {}, []] }) thin = Rack::Handler.get('thin') thin.run(app, Host: u.host, Port: u.port) end.run end end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
44 45 46 |
# File 'lib/drb/websocket/server.rb', line 44 def uri @uri end |
Instance Method Details
#accept ⇒ Object
73 74 75 76 |
# File 'lib/drb/websocket/server.rb', line 73 def accept callback = @queue.pop ServerSide.new(callback, @config, uri) end |
#close ⇒ Object
65 66 67 |
# File 'lib/drb/websocket/server.rb', line 65 def close RackApp.close(@uri) end |
#on_message(data) ⇒ Object
78 79 80 81 82 |
# File 'lib/drb/websocket/server.rb', line 78 def (data) callback = Callback.new(self) res = callback.recv_mesg(data.pack('C*')) @ws.send(res.bytes) end |
#on_session_start(ws) ⇒ Object
84 85 86 |
# File 'lib/drb/websocket/server.rb', line 84 def on_session_start(ws) @ws = ws end |
#push(callback) ⇒ Object
69 70 71 |
# File 'lib/drb/websocket/server.rb', line 69 def push(callback) @queue.push(callback) end |