module ObjectsFramework::PubSub

Public Class Methods

included(child) click to toggle source
# File lib/objectsframework/pubsub.rb, line 8
def self.included(child)
        child.add_hook :filter => "request.capture", :method => "pubsub_capture_request"
        child.extend ClassExtend
end

Public Instance Methods

pubsub_capture_request() click to toggle source
# File lib/objectsframework/pubsub.rb, line 13
def pubsub_capture_request
        # TODO: hijack rack request

        if(@env["HTTP_UPGRADE"] == "websocket")
                # Request is websockets hijacking
                tubesock = Tubesock.hijack(@env)

                @@channels[request.path.split("/")[2]].sockets << tubesock

                tubesock.onclose do
                                @@channels[request.path.split("/")[2]].sockets.delete(tubesock)
                end

                tubesock.listen

                [-1, {}, []]
        else
                return continue
        end
end