diff --git a/app/assets/javascripts/foreign_office.js b/app/assets/javascripts/foreign_office.js index a4e2528..3a66174 100644 --- a/app/assets/javascripts/foreign_office.js +++ b/app/assets/javascripts/foreign_office.js @@ -9,10 +9,12 @@ var ForeignOffice = Class.extend({ this.channels_by_name = []; }, config: function(config){ - third_party_busname = this.busMap(config.bus_name) - if (typeof(eval(third_party_busname)) != 'undefined') { - bus_class = eval(config.bus_name); - } else { + bus_class = eval(config.bus_name); + third_party_library = this.library_name_for(config.bus_name) + try { + bus_class = eval(third_party_library) + } + catch(err){ bus_class = TestBus } this.bus = new bus_class(config); @@ -33,9 +35,9 @@ var ForeignOffice = Class.extend({ channelNames: function(){ return $.map(this.channels,function(channel){return channel.channel_name}); }, - busMap: function(bus_name) { - var map = { PubnubBus: 'PUBNUB', - PusherBus: 'Pusher'}[bus_name] + library_name_for: function(bus_name){ + var library_map = {PubnubBus: 'PUBNUB', PusherBus: 'Pusher'} + return library_map[bus_name] } }); @@ -44,6 +46,8 @@ foreign_office = new ForeignOffice(); var ForeignOfficeChannel = Class.extend({ init: function(channel_name){ var foreign_office_channel = this; + debug_logger.log("Subscribing to: "); + debug_logger.log(channel_name); foreign_office.bus.subscribe({ channel : channel_name, callback : function(m){ diff --git a/app/assets/javascripts/pubnub_bus.js b/app/assets/javascripts/pubnub_bus.js index bd097a4..06b22e2 100644 --- a/app/assets/javascripts/pubnub_bus.js +++ b/app/assets/javascripts/pubnub_bus.js @@ -1,5 +1,6 @@ var PubnubBus = Class.extend({ init: function(config){ + debug_logger.log("initializing pubnub js") this.pubnub = PUBNUB.init({ publish_key : config.publish_key, subscribe_key : config.subscribe_key, @@ -7,9 +8,10 @@ var PubnubBus = Class.extend({ }); }, subscribe: function(subscription){ + debug_logger.log("subscribing with PubnubBus") + debug_logger.log(subscription) this.pubnub.subscribe({ channel : subscription.channel, - backfill: true, message : function(m){subscription.callback(m)} }); diff --git a/app/assets/javascripts/pusher_bus.js b/app/assets/javascripts/pusher_bus.js index 66216d0..91ccaf5 100644 --- a/app/assets/javascripts/pusher_bus.js +++ b/app/assets/javascripts/pusher_bus.js @@ -7,5 +7,6 @@ var PusherBus = Class.extend({ this.channel.bind('publish', function(data){ subscription.callback(data); }) - } + }, + third_party_library: 'Pusher' }) diff --git a/lib/foreign_office/busses/pubnub_bus.rb b/lib/foreign_office/busses/pubnub_bus.rb index 67ee8b9..ff3c579 100644 --- a/lib/foreign_office/busses/pubnub_bus.rb +++ b/lib/foreign_office/busses/pubnub_bus.rb @@ -44,17 +44,16 @@ def self.publish(message) self.connection.publish( channel: message[:channel], message: message, - http_sync: true, - callback: lambda{|response| - if 0 == JSON.parse(response.instance_variable_get(:@response)).first #pubnub publishing failed - if attempts <= 3 - self.publish!(message, attempts) #retry if we failed - else - Rails.logger.debug("ForeignOffice#publish! failed after #{attempts} attempts. message: #{message.inspect}") - end - end - } - ) + http_sync: true + ) do |envelope| + if '200' != envelope.status_code.to_s + Rails.logger.error "ForeignOffice error esponse:" + Rails.logger.error envelope.message + Rails.logger.error envelope.channel + Rails.logger.error envelope.status_code + Rails.logger.error envelope.timetoken + end + end end end \ No newline at end of file diff --git a/lib/foreign_office/version.rb b/lib/foreign_office/version.rb index ce8fd42..a6adc6c 100644 --- a/lib/foreign_office/version.rb +++ b/lib/foreign_office/version.rb @@ -1,3 +1,3 @@ module ForeignOffice - VERSION = "0.1.1" + VERSION = "0.1.2" end