Foreign-office

A light browser push framework that provides listeners on web clients and publishers on Rails servers. If you can keep all your business logic on the server and maintain a dumb client, life is serene. If you can do that while offering a live, interactive page with real-time updates, you're a rock star.

View the Project on GitHub edraut/foreign-office

How it works

Create a listener on the client

<div <%= listener_attrs(@transaction,:grand_total) %>>
</div>

Publish a message from the server

ForeignOffice.publish(
  channel: "Transaction#{@transaction.id}",
  object: {grand_total: @transaction.grand_total})

After you publish, your div will show the latest grand total via browser-push. Your server can update your client on demand!

See here for all the ui actions you can trigger when you receive a message.

Install it

In your gemfile:

gem 'foreign_office'

Configure it

Server side

ForeignOffice.config(
  bus: {
    klass: ForeignOffice::Busses::PusherBus,
    app_id: <YOUR PUSHER APP ID>,
    key: <YOUR PUSHER KEY>,
    secret: <YOUR PUSHER SECRET>
    })

Client side

//= require foreign_office
foreign_office.config({
  bus_name: 'PusherBus',
  key: '<YOUR PUSHER KEY>'
});

If you'd rather use Pubnub, see here.

If you'd like to wrap each publish request so you can background it or instrument it, then see here.

Want more integrations?

Send us your ideas. Better yet, send us a pull request on github!

Authors and Contributors

Along with Eric Draut (@edraut), Adam Bialek (@abialek) and Matt Leonard (@mattleonard) are core contributors.