Navigation Menu

Skip to content

Commit

Permalink
added CDN url for conditional flash sockets on HTTPS contributed by jjb!
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlb committed Sep 20, 2011
1 parent 4fc519a commit ab0aa14
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion javascript/pubnub-3.1.js
Expand Up @@ -223,6 +223,24 @@ var NOW = 1
*/
function unique() { return'x'+ ++NOW+''+(+new Date) }

function rnow() { return+new Date }
function updater( fun, rate ) {
var timeout
, last = 0
, runnit = function() {
if (last + rate > rnow()) {
clearTimeout(timeout);
timeout = setTimeout( runnit, rate );
}
else {
last = rnow();
fun();
}
};

return runnit;
}

/**
* $
* =
Expand Down Expand Up @@ -403,6 +421,32 @@ function encode(path) {
} ).join('');
}

/**
* EVENTS
* ======
* PUBNUB.events.bind( 'you-stepped-on-flower', function(message) {
* // Do Stuff with message
* } );
*
* PUBNUB.events.fire( 'you-stepped-on-flower', "message-data" );
* PUBNUB.events.fire( 'you-stepped-on-flower', {message:"data"} );
* PUBNUB.events.fire( 'you-stepped-on-flower', [1,2,3] );
*
*/
var events = {
list : {},
unbind : function( name ) { events.list[name] = [] },
bind : function( name, fun ) {
(events.list[name] = events.list[name] || []).push(fun);
},
fire : function( name, data ) {
each(
events.list[name] || [],
function(fun) { fun(data) }
);
}
};

/**
* XDR Cross Domain Request
* ========================
Expand Down Expand Up @@ -774,6 +818,8 @@ var PN = $('pubnub') || {}
'search' : search,
'attr' : attr,
'now' : unique,
'events' : events,
'updater' : updater,
'init' : CREATE_PUBNUB
};

Expand All @@ -789,7 +835,7 @@ PUBNUB = CREATE_PUBNUB({

// PUBNUB Flash Socket
var swf = !location.href.indexOf('https') ?
'https://pubnub.s3.amazonaws.com/pubnub.swf' :
'https://dh15atwfs066y.cloudfront.net/pubnub.swf' :
'http://cdn.pubnub.com/pubnub.swf';
css( PN, { 'position' : 'absolute', 'top' : -1000 } );

Expand Down

0 comments on commit ab0aa14

Please sign in to comment.