An open API service indexing awesome lists of open source software.

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 )

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

```