Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created June 19, 2013 20:16
Show Gist options
  • Save ToeJamson/5817648 to your computer and use it in GitHub Desktop.
Save ToeJamson/5817648 to your computer and use it in GitHub Desktop.
PubNub + jQTouch
// Overlay (div)
var over = $('#over');
// ====================
// STEP 1: SUBSCRIBE()
// ====================
// Listen for updates on 'jqtouch' channel.
$.PUBNUB.subscribe( { channel : 'jqtouch' }, function(message) {
// Get Orientation on Local and Remote Device
var local_orientation = jQT.getOrientation()
, remote_orientation = message.orientation;
// Indicate Not Same Orientation (Show or Hide div#over)
if (local_orientation != remote_orientation) over.show();
else over.hide();
// Console Debug
console.log({
local_orientation : local_orientation,
remote_orientation : remote_orientation,
message : message
});
} ); // -- end Subscribe()
// ====================
// STEP 2: PUBLISH()
// ====================
// Orientation callback event
$('body').bind( 'turn', function( e, data ) {
// Send update to 'jqtouch' channel.
$.PUBNUB.publish({
channel : 'jqtouch',
message : { orientation : data.orientation }
}); // -- end Publish()
}); // -- end Orientation Event Bind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment