Class: EventMachine::RTMP::ConnectRequest

Inherits:
Request show all
Defined in:
lib/em-rtmp/connect_request.rb

Constant Summary collapse

DEFAULT_PARAMETERS =
{
  app: '',
  flashVer: 'WIN 10,1,85,3',
  swfUrl: '',
  tcUrl: '',
  fpad: false,
  capabilities: 239,
  audioCodecs: 3191,
  videoCodecs: 252,
  videoFunction: 1,
  pageUrl: nil,
  objectEncoding: 3
}

Instance Attribute Summary collapse

Attributes inherited from Request

#body, #header, #message

Attributes inherited from ConnectionDelegate

#state

Instance Method Summary collapse

Methods inherited from Request

#chunk_count, #chunk_size, #chunks, #header_length_for_chunk, #send_chunk, #update_header

Methods inherited from ConnectionDelegate

#bytes_waiting, #change_state, #read, #write

Methods included from IOHelpers

#read_bitfield, #read_double_be, #read_int29, #read_safe, #read_uint16_be, #read_uint24_be, #read_uint32_be, #read_uint32_le, #read_uint8, #write_bitfield, #write_double_be, #write_int29, #write_uint16_be, #write_uint24_be, #write_uint32_be, #write_uint32_le, #write_uint8

Constructor Details

#initialize(connection) ⇒ ConnectRequest

Initialize the request and set sane defaults for an RTMP connect request (transaction_id, command, header values)

Returns nothing



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/em-rtmp/connect_request.rb', line 28

def initialize(connection)
  super connection

  self.header.channel_id = 3
  self.header.message_type = :amf0
  self.header

  self.message.version = 0
  self.message.transaction_id = 1
  self.message.command = "connect"

  callback do |res|
    Logger.debug "rtmp connect failed, becoming ready"
    @connection.change_state :ready
  end

  errback do |res|
    Logger.debug "rtmp connect failed, closing connection"
    @connection.close_connection
  end
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def app
  @app
end

#audioCodecsObject

Returns the value of attribute audioCodecs.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def audioCodecs
  @audioCodecs
end

#capabilitiesObject

Returns the value of attribute capabilities.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def capabilities
  @capabilities
end

#flashVerObject

Returns the value of attribute flashVer.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def flashVer
  @flashVer
end

#fpadObject

Returns the value of attribute fpad.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def fpad
  @fpad
end

#objectEncodingObject

Returns the value of attribute objectEncoding.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def objectEncoding
  @objectEncoding
end

#pageUrlObject

Returns the value of attribute pageUrl.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def pageUrl
  @pageUrl
end

#swfUrlObject

Returns the value of attribute swfUrl.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def swfUrl
  @swfUrl
end

#tcUrlObject

Returns the value of attribute tcUrl.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def tcUrl
  @tcUrl
end

#videoCodecsObject

Returns the value of attribute videoCodecs.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def videoCodecs
  @videoCodecs
end

#videoFunctionObject

Returns the value of attribute videoFunction.



21
22
23
# File 'lib/em-rtmp/connect_request.rb', line 21

def videoFunction
  @videoFunction
end

Instance Method Details

#command_messageObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/em-rtmp/connect_request.rb', line 59

def command_message
  cm = RocketAMF::Values::CommandMessage.new
  cm.operation = 5
  cm.correlationId = ""
  cm.timestamp = 0
  cm.timeToLive = 0
  cm.messageId = UUID.random
  cm.body = {}
  cm.destination = ""
  cm.headers = { "DSMessagingVersion" => 1, "DSId" => "my-rtmps" }
  cm
end

#parametersObject

Construct a list of parameters given our class attributes, used to form the connect message object.

Returns a Hash of symbols => values



54
55
56
57
# File 'lib/em-rtmp/connect_request.rb', line 54

def parameters
  instance_values = Hash[instance_variables.map {|k| [k.to_s[1..-1].to_sym, instance_variable_get(k)]}]
  DEFAULT_PARAMETERS.merge instance_values.select {|k,v| DEFAULT_PARAMETERS.key? k }
end

#sendObject

Given the specific nature of a connect request, we can just set the message values to our params then encode that as our body before sending.

Returns the result of super



76
77
78
79
80
# File 'lib/em-rtmp/connect_request.rb', line 76

def send
  self.message.values = [parameters, false, "nil", "", command_message]
  self.body = message.encode
  super
end