https://github.com/mark24code/sinatra-websocket-example
Sinatra websocket example ( Ruby 3 + Puma + faye-websocket + Websocket DSL )
https://github.com/mark24code/sinatra-websocket-example
example sinatra websocket
Last synced: 5 months ago
JSON representation
Sinatra websocket example ( Ruby 3 + Puma + faye-websocket + Websocket DSL )
- Host: GitHub
- URL: https://github.com/mark24code/sinatra-websocket-example
- Owner: Mark24Code
- License: mit
- Created: 2025-03-06T06:16:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-03-06T06:27:43.000Z (11 months ago)
- Last Synced: 2025-03-06T07:37:54.652Z (11 months ago)
- Topics: example, sinatra, websocket
- Language: Ruby
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sinatra WebSocket Example
Ruby 3.4.2
Sinatra + Puma + faye-websocket
This is an example project using Sinatra and Faye::WebSocket.
## Run
clone this repository and do follwings.
```
$ bundle install
$ ruby server.rb
```
## Websocket DSL
```ruby
class App < Sinatra::Base
get "/" do
erb :index
end
websocket "/ws" do |connect|
connect.on(:open) do |event|
puts 'On Open'
end
connect.on(:message) do |msg|
connect.send(msg.data.reverse) # Reverse and reply
end
connect.on(:close) do |event|
puts 'On Close'
end
end
end
```