Module: Strelka::WebSocketServer::Routing

Extended by:
Loggability, Plugin
Includes:
Mongrel2::WebSocket::Constants, Constants
Defined in:
lib/strelka/websocketserver/routing.rb

Overview

Frame routing logic for Strelka WebSocketServers.

For a protocol that defines its own opcodes:

class ChatServer < Strelka::WebSocketServer
   plugin :routing

   on_handshake do |request|
       # ...
   end
   on_text do |request|
       # ...
   end
end

class CustomChatServer < Strelka::WebSocketServer
   plugin :routing
   opcodes :nick => 7,
           :emote => 8

   on_nick do |request|
       nick = request.payload.read
       self.set_nick( request.socket_id, nick )
       return request.response( "Okay, nick set to #{nick}.", :text )
   end

   on_emote do |request|
       emote = request.payload.read
       nick = self.nick_for( request.socket_id )
       msg = "%s %s" % [ nick, emote ]
       self.broadcast( msg )
       return nil
   end
end

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Plugin

#pluggable, #successors

Instance Method Summary collapse

Methods included from Plugin

extended, plugin_name, run_inside, run_outside

Instance Method Details

#handle_websocket_request(request) ⇒ Object

Dispatch the incoming frame to its handler based on its opcode



132
133
134
135
136
137
138
139
140
# File 'lib/strelka/websocketserver/routing.rb', line 132

def handle_websocket_request( request )
	self.log.debug "[:routing] Opcode map is: %p" % [ self.class.opcode_map ]
	opname = self.class.opcode_names[ request.numeric_opcode ]
	self.log.debug "[:routing] Routing request: %p" % [ opname ]

	handler = self.class.op_callbacks[ opname ] or return super

	return handler.bind( self ).call( request )
end