Module: Roda::RodaPlugins::WebSockets
- Defined in:
- lib/roda/plugins/websockets.rb
Overview
The websockets plugin integrates the async-websocket gem into Roda’s routing tree. See the async-websocket docs for usage details.
The following example is an echo server that sleeps one second after receiving a message before echoing that same message back to the client and closing the connection:
plugin :websockets
def (connection)
Enumerator.new do |yielder|
while ( = connection.read)
yielder <<
end
end
end
def (connection, message:)
Async do |task|
task.sleep(1)
connection.write()
connection.flush
connection.close
end
end
route do |r|
r.root do
r.websocket do |connection|
(connection).each do ||
(connection, message: )
end
end
end
end
Defined Under Namespace
Modules: RequestMethods