Server code

7 views
Skip to first unread message

Lon

unread,
Jul 8, 2009, 3:10:58 PM7/8/09
to Liverpie Support
Hi guys,

I have been working with liverpie, building a prototype for a client
and comparing it to other solutions, such as Freec.

Have to say, I really like how it lets me keep the logic for the
application separate from the Freeswitch platform.

Anyway, I ran into a few issue with events not being handled or
causing an error in Liverpie.

It seems to revolve around the receive_data method in liverpie_server.

Running the latest SVN of Freeswitch, events don't conform to the
structure being parsed. Namely, always ending with two line breaks.

So I am playing with the following solution, which seems to solve the
issue.

---
def add_to_buffer(data)
data.split(/\n\n/i).each do |part|
next if part.nil?
if part.include?('Event-Name')
event_hash = hashify(part)
@receive_buffer.push(event_hash)
end
end
end

def receive_data data

add_to_buffer(data)

# Replace parsing for data ending in two newlines
@receive_buffer.each do |event|
......
---

Any feedback is welcome form more experience users of liverpie.

Lon Baker
Kickass Pixels
-
(office) +1-415-287-0973
(mobile) +1-415-279-5019
(skype) lonbaker
-
http://kickasspixels.com
http://twitter.com/kickasspixels
http://www.linkedin.com/in/lonbaker
--


Alex Deva

unread,
Jul 14, 2009, 2:37:41 AM7/14/09
to liverpie...@googlegroups.com
Hi Lon,

As far as I've been told, Freeswitch doesn't always wait for the
entire event contents to be sent before sending the double newline;
sometimes it'll do that in chunks.

That makes it extremely difficult for Liverpie to judge when and what
to process, but then it'd make it difficult for any app working
directly with Freeswitch, so Liverpie simply massages everything into
the HTTP parameters that it sends to the webapp. Washes its hands of
the problem :)

Thanks for your contribution, I'll give it a try and if it solves any
issues I'll add it; in the meantime, could you be a little more
descriptive about the error which you say Liverpie threw? Or could
you help me replicate a context in which events aren't handled?

Alex

P.S. It's not the goal of Liverpie to handle *ALL* FS events; in fact
it only handles DTMF events (if so requested), and whatever event YOU
tell it to wait for after having sent FS a command via Liverpie.
Everything else is duly ignored. Indeed it would be nice for it to
better handle hangup / answer events, but I haven't yet found a
satisfactory way to do that yet.

Lon Baker

unread,
Jul 15, 2009, 4:31:52 AM7/15/09
to liverpie...@googlegroups.com
Alex,

Thanks. I understand. The changes were needed to work with the current SVN version of Freeswitch.

The hang up event was causing liverpie to crash, since it didn't end with double newlines.

I am a few weeks away from a couple freeswitch projects going into alpha and will let you know what I see when they do.

After talking to other developers I may rewrite the event handling code to pay attentions to the HTTP content-length and collect the entire event before passing it on to the web apps.

Also, I am considering adding either deferrable events or gserver threads to avoid any blocking, but only if I see blocking issue arise.

The more I use liverpie the more I like you solution! Very elegant and flexible.

Alex Deva

unread,
Jul 15, 2009, 5:54:19 AM7/15/09
to liverpie...@googlegroups.com
Thank you Lon. I'm glad you like my idea.

When you have stable code that looks at content-length instead of the double newlines, I'd like to add it to Liverpie with your permission and credit.
Reply all
Reply to author
Forward
0 new messages