See full documentation here
In your gemfile:
gem 'foreign_office'
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.
<div data-listener="true" data-channel="Transaction_123" data-key="grand_total">
</div>
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.
Send us your ideas. Better yet, send us a pull request on github!
- want a different bus?
- want a new subscription event js behavior?
Along with Eric Draut (@edraut), Adam Bialek (@abialek) and Matt Leonard (@mattleonard) are core contributors.