Geo
Geo

Reputation: 96767

What's the preferred way of using Rails and Flex?

I'd like to create a service, similar to a chat application (realtime app).

From what I can see from my research, BlazeDS is the preferred way, but it involves Java and Java EE. Also, the latest Ruby results seem to be from 2009-2010, so they are likely outdated.

Are there any actively maintained Ruby/Rails solutions for integrating push notifications with Flex?

Upvotes: 1

Views: 479

Answers (4)

istrasci
istrasci

Reputation: 1351

You can use the RestfulX gem & Flex framework. That's what I use for Rails/Flex.

Upvotes: 0

Ivan Dyachenko
Ivan Dyachenko

Reputation: 1348

You can use https://github.com/rubyamf/rubyamf or https://github.com/victorcoder/rubyamf_plugin

But you will be have problem with realtime messaging because rubyamf and rubyamf_plugin don't support RTMP.

Upvotes: 0

Nick Kwiatkowski
Nick Kwiatkowski

Reputation: 31

If you want to live within the Ruby world, you can use regular WebSockets to talk to a Flex application. It won't be pretty, but it would work, and you could avoid the Java back-end. This would be a lot more raw than telling BlazeDS to fling structures around, but it should be doable.

On the Flex client side, there is a library written by Kaazing, that is bundled with their WebSocket servers. Download one of their WebSocket servers, and in the client-libs folder, there should be a swc (with docs) that you can use to talk to em-websocket (or really, any websocket tech).

Now, all this being said, you won't have nearly the scaleability of BlazeDS or GraniteDS, but it should work for smaller implementations and demos.

Upvotes: 3

Mark Thomas
Mark Thomas

Reputation: 37507

The current situation

Do you have to use Flex? HTML5 websockets is a nascent but growing technology and there are implementations now. Flex's days are numbered. Yet, websockets doesn't yet have native support in IE.

  • em-websocket is a ruby websocket server based on eventmachine. The service Pusher is based on it.
  • Faye is a websocket server and client. (Railscast)
  • There are other Ruby implementations such as Cramp and Socky.
  • If you're open to servers in other technologies such as Node, there are many with Ruby or Javascript clients ready to go.

Update: I might mention that I looked into doing something similar with Flex a while back, and got a copy of Flex on Rails. The book's server push example uses Juggernaut, which unfortunately has stopped further development. The author states that Server-Sent Events (SSEs) make Juggernaut redundant. All major browsers except IE support them natively, similar to the situation with websockets.

There are shims ("polyfills") that use javascript to bring these missing capabilities to the browsers. For example, the jQuery Graceful WebSocket is a jQuery plugin that implements a websocket client but falls back to AJAX polling so the functionality will still work in IE, just won't be quite as instant. Because it detects websocket support, as soon as a browser supports websockets they will be used.

Bridging the Gap

We seem to be caught in a transition period, where we are at the sunset era of Flash but not yet at broad support for its replacement technologies. There is one library that may bridge the gap: Socket.IO. This library selects the most capable technology transport at runtime. It will use Flash if present, but can also use websockets, AJAX long polling, AJAX multipart streaming, a "forever iframe" if necessary. This gives it broad browser support:

  • IE 5.5+
  • Safari 3+
  • Google Chrome 4+
  • Firefox 3+
  • Opera 10.61+
  • iPhone Safari
  • iPad Safari
  • Android Webkit
  • WebOS Webkit

This is actually broader compatibility than either Flash/Flex or WebSockets alone. Socket.IO is implemented in Javascript for both server and client, so you need a server-side Javascript runtime such as Node.

Possible solutions

While there don't seem to be many current references to a Rails 3 -> Flex solution (as you have found), it appears there is some traction with the combination of Ruby/Rails and Socket.IO.

If you want to add chat to a Rails app using Socket.IO, there's a nice reference blog post by Liam Kaufman who creates a chat app in Rails 3 using Socket.IO: http://liamkaufman.com/blog/2012/02/25/adding_real-time_to_rails_with_socket.IO_nodejs_and_backbonejs_with_demo/

There's also a socket.io gem which adds support to the Cramp server mentioned above.

There also seem to be other stackoverflow questions with others working on the Rails 3 and Socket.IO combination.

TL;DR summary

While there isn't much indication that folks are doing direct-to-Flex from Rails anymore, there are other solutions with the most promising being a combination of Rails and Socket.IO.

Upvotes: 7

Related Questions