Any success with Sinatra working together with EventMachine WebSockets?

前端 未结 5 2246
陌清茗
陌清茗 2020-12-07 10:02

I have been using Sinatra for sometime now and I would like to add some realtime features to my web-app by pushing the data via websockets.

I have successfully used

5条回答
  •  盖世英雄少女心
    2020-12-07 10:41

    I stumbled onto this websocket-rack github project which is basically a rackified em-websocket and actually got it to work nicely side-by-side with a Sinatra app. Here's my config.ru:

    require 'rubygems'
    require 'rack/websocket'
    require 'sinatra/base'
    
    class WebSocketApp < Rack::WebSocket::Application
      # ...
    end
    
    class SinatraApp < Sinatra::Base
      # ...
    end
    
    map '/ws' do
      run WebSocketApp.new
    end
    
    map '/' do
      run SinatraApp
    end
    

    Have fun!
    Colin

提交回复
热议问题