Module: Revent::ASRServer

Defined in:
lib/revent/as_r.rb

Overview

To make your class a server, just include Revent::ASRServer in it.

The server has the following methods:

  • start_server

  • on_connect

  • on_unbind

  • on_message

For more control, it uses “cons” directly.

Constant Summary collapse

DEFAULT_MAX_DATA_SIZE =

For security check, normally command cannot be too long

1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#consObject (readonly)

Returns the value of attribute cons.



124
125
126
# File 'lib/revent/as_r.rb', line 124

def cons
  @cons
end

#loggerObject

Returns the value of attribute logger.



123
124
125
# File 'lib/revent/as_r.rb', line 123

def logger
  @logger
end

#max_data_sizeObject

Returns the value of attribute max_data_size.



123
124
125
# File 'lib/revent/as_r.rb', line 123

def max_data_size
  @max_data_size
end

#policyObject

Returns the value of attribute policy.



123
124
125
# File 'lib/revent/as_r.rb', line 123

def policy
  @policy
end

Instance Method Details

#on_connect(con) ⇒ Object



148
149
# File 'lib/revent/as_r.rb', line 148

def on_connect(con)
end

#on_message(con, message) ⇒ Object



154
155
# File 'lib/revent/as_r.rb', line 154

def on_message(con, message)
end

#on_unbind(con) ⇒ Object



151
152
# File 'lib/revent/as_r.rb', line 151

def on_unbind(con)
end

#start_server(host, port) ⇒ Object

Set logger, max_data_size, policy if you don’t want the default values before calling this method.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/revent/as_r.rb', line 128

def start_server(host, port)
  @logger = Logger.new(STDOUT) if @logger.nil?
  @max_data_size = DEFAULT_MAX_DATA_SIZE if @max_data_size.nil?
  if @policy.nil?
    @policy = %Q{
<cross-domain-policy>
<allow-access-from domain="*" to-ports="#{port}" />
</cross-domain-policy>
}
  end

  @cons = []
  EventMachine::start_server(host, port, ASRCon) do |con|
    # con is an instance of a class that has included ASRCon
    @cons.synchronize { @cons << con }
    con.user = self
    on_connect(con)
  end
end