module DDP::Server::Protocol

Implementation of the DDP protocol Can be included into any class that has an on_open, a read_message and a write_message method

Constants

DDP_VERSION

Attributes

session_id[RW]

Public Instance Methods

handle_connect() click to toggle source
# File lib/ddp/server/protocol.rb, line 23
def handle_connect
        message = read_message

        if message['msg'] == 'connect' && message['version'] == DDP_VERSION
                handle_session(message)
        else
                write_message('msg' => 'failed', 'version' => DDP_VERSION)
                close
        end
end
handle_established() click to toggle source
# File lib/ddp/server/protocol.rb, line 42
def handle_established
        loop do
                @message = read_message

                next if handle_heartbeat
                next if handle_data
                next if handle_rpc
                break
        end

        close
end
handle_session(message) click to toggle source
# File lib/ddp/server/protocol.rb, line 34
def handle_session(message)
        @session_id = message['session'] || new_session_id

        write_message('msg' => 'connected', 'session' => session_id)

        handle_established
end
new_session_id() click to toggle source
# File lib/ddp/server/protocol.rb, line 19
def new_session_id
        SecureRandom.hex
end