Skip to content

A light framework that provides functionality for listeners on web clients and publishers on Rails servers. Keep your business logic on the server whenever you can!

License

Notifications You must be signed in to change notification settings

edraut/foreign-office

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

foreign_office

Documentation

See full documentation here

Install it

In your gemfile:

gem 'foreign_office'

Configure it

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

in your javascript manifest...

//= require foreign_office

in any javscript file you like:

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.

Let's use it!

Create a Listener

<div data-listener="true" data-channel="Transaction_123" data-key="grand_total">
</div>

Publish a message

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.

Want more integrations?

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

  • want a different bus?
  • want a new subscription event js behavior?

Authors and Contributors

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

About

A light framework that provides functionality for listeners on web clients and publishers on Rails servers. Keep your business logic on the server whenever you can!

Resources

License

Stars

Watchers

Forks

Packages

No packages published