Sha256: b65e32f0975a5b5bbcc41aaeaa96400a596b248a49f7b8b0c1b5626234cfa2b9

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

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,
      ssl           : config.ssl
    });
  },
  subscribe: function(subscription){
    debug_logger.log("subscribing with PubnubBus")
    debug_logger.log(subscription)
    var disconnect_func = function(){
      foreign_office.disconnection(); debug_logger.log('Lost connection to: '); debug_logger.log(subscription.channel)
    };
    var debounced_disconnect = _.debounce(disconnect_func, 5000); //Don't alert unless we're disconnected for 5 seconds, this avoids alerting on a normal page load.
    this.pubnub.subscribe({
      channel : subscription.channel,
      restore : true,
      disconnect : debounced_disconnect,
      reconnect : function(){
        foreign_office.reconnection(); debug_logger.log('Reestablished connection to: '); debug_logger.log(subscription.channel)
      },
      connect : function(){
        foreign_office.connect(); debug_logger.log("Connected to: "); debug_logger.log(subscription.channel)
      },
      message : function(m,env,channel){subscription.callback(m)}
    });

  }
})
PubnubBus.third_party_library = 'PUBNUB'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreign_office-0.14.0 app/assets/javascripts/pubnub_bus.js
foreign_office-0.13.0 app/assets/javascripts/pubnub_bus.js
foreign_office-0.12.3 app/assets/javascripts/pubnub_bus.js