Sha256: 8c1df9abf9cbf66b1a34722b752e8bfed5e94cb80ffedadeae56bd9516aed54d

Contents?: true

Size: 617 Bytes

Versions: 5

Compression:

Stored size: 617 Bytes

Contents

require "sinatra"
require "sinatra-websocket"

module Blogdoor
  class Server < Sinatra::Base
    set :sockets, []

    get "/websocket" do
      if !request.websocket?
        return [400, {}, []]
      end

      request.websocket do |socket|
        socket.onopen do
          settings.sockets << socket
        end

        socket.onclose do
          settings.sockets.delete(socket)
        end

        socket.onerror do
          puts "connection error"
        end
      end
    end

    post "/" do
      EM.next_tick do
        settings.sockets.each { |socket| socket.send("") }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blogdoor-0.0.5 lib/blogdoor/server.rb
blogdoor-0.0.4 lib/blogdoor/server.rb
blogdoor-0.0.3 lib/blogdoor/server.rb
blogdoor-0.0.2 lib/blogdoor/server.rb
blogdoor-0.0.1 lib/blogdoor/server.rb