bougyman-freeswitcher 0.1.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/examples/ies_demo.rb DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pp'
4
- require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
5
- puts $LOAD_PATH.inspect
6
- $stdout.flush
7
- require "fsr/listener/inbound"
8
-
9
-
10
- class IesDemo < FSR::Listener::Inbound
11
-
12
- def on_event(event)
13
- pp event.headers
14
- pp event.content[:event_name]
15
- end
16
-
17
- end
18
-
19
- FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pp'
4
- require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
5
- puts $LOAD_PATH.inspect
6
- $stdout.flush
7
- require "fsr/listener/inbound"
8
-
9
- # EXAMPLE 1
10
- # This adds a hook on CHANNEL_CREATE events. You can also create a method to handle the event you're after. See the next example
11
- FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
12
-
13
- # EXAMPLE 2
14
- # Define a method to handle CHANNEL_HANGUP events.
15
- def custom_channel_hangup_handler(event)
16
- FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
17
- pp event
18
- end
19
- # This adds a hook for EXAMPLE 2
20
- FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
21
-
22
-
23
- # Start FSR Inbound Listener
24
- FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
25
-
@@ -1,131 +0,0 @@
1
- require "yaml"
2
- require "fsr/listener"
3
- module FSR
4
- load_all_applications
5
- module Listener
6
- module Outbound
7
- include FSR::Listener
8
-
9
- # Include FSR::App to get all the applications defined as methods
10
- include FSR::App
11
-
12
- # Redefine the FSR::App methods to wrap sendmsg around them
13
- SENDMSG_METHOD_DEFINITION = "def %s(*args, &block); sendmsg super; end"
14
- APPLICATIONS.each { |app, obj| module_eval(SENDMSG_METHOD_DEFINITION % app.to_s) }
15
-
16
- def post_init
17
- @session = nil # holds the session object
18
- send_data("connect\n\n")
19
- FSR::Log.debug "Accepting connections."
20
- end
21
-
22
- # Received data dispatches the data received by the EM socket,
23
- # Either as a Session, a continuation of a Session, or as a Session's last CommandReply
24
- def receive_data(data)
25
- FSR::Log.debug("received #{data}")
26
- if @session.nil? # if @session is nil, create a new Session object
27
- @session = Session.new(data)
28
- session_initiated(@session) if @session.initiated?
29
- else
30
- # If it's not nil, we add the data to this session, Session knows whether
31
- # or not to create a CommandReply, complete a CommandReply, or simply add to
32
- # its own @data array and @headers/@body structures
33
- if @session.initiated?
34
- @session << data
35
- reply_received(@session.replies.last) if @session.replies.last.complete?
36
- else
37
- @session << data
38
- session_initiated(@session) if @session.initiated?
39
- end
40
- end
41
- @session
42
- end
43
-
44
- def session_initiated(session)
45
- session
46
- end
47
-
48
- def reply_received(command_reply)
49
- command_reply
50
- end
51
-
52
- alias :receive_response :reply_received
53
- # sendmsg sends data to the EM app socket via #send_data, or
54
- # returns the string it would send if #send_data is not defined.
55
- # It expects an object which responds to either #sendmsg or #to_s,
56
- # which should return a EM Outbound Event Socket formatted instruction
57
- def sendmsg(message)
58
- text = message.respond_to?(:sendmsg) ? message.sendmsg : message.to_s
59
- FSR::Log.debug "sending #{text}"
60
- message = "sendmsg\n%s\n" % text
61
- self.respond_to?(:send_data) ? send_data(message) : message
62
- end
63
-
64
-
65
- class SocketResponse
66
- attr_accessor :headers, :body, :data
67
- def initialize(data = "")
68
- @data = [data]
69
- @headers = {}
70
- if data.match(/\n$/)
71
- headers, @body = data.split("\n\n")
72
- headers.each_line do |line|
73
- key, value = line.split(":")
74
- @headers[key] = value.to_s.strip
75
- end
76
- end
77
- @body ||= ""
78
- FSR::Log.debug("New #{self.class.name} created: #{self}")
79
- end
80
-
81
- def <<(data)
82
- if data.match(/\n$/)
83
- @data.last.match(/\n$/) ? @data << data : @data.last << data
84
- extra_headers, more_body = @data.last.split("\n\n")
85
- extra_headers.each_line do |line|
86
- key, value = line.split(":")
87
- @headers[key] = value.to_s.strip
88
- end
89
- @body << more_body unless more_body.nil?
90
- else
91
- @data.last.match(/\n$/) ? @data << data : @data.last << data
92
- end
93
- self
94
- end
95
- end
96
-
97
- class Session < SocketResponse
98
- attr_accessor :replies
99
- def initialize(data = "")
100
- super
101
- @replies = []
102
- end
103
-
104
- def <<(data)
105
- if initiated?
106
- if @replies.empty? or @replies.last.complete?
107
- @replies << CommandReply.new(data)
108
- else
109
- @replies.last << data
110
- end
111
- else
112
- super
113
- end
114
- end
115
-
116
- def initiated?
117
- @headers.keys.include?("Control")
118
- end
119
-
120
- end
121
-
122
- class CommandReply < SocketResponse
123
- # Set this to true for now, fill it in when we know what completed a reply
124
- def complete?
125
- true
126
- end
127
- end
128
- end
129
-
130
- end
131
- end