Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
james2doyle committed Apr 2, 2013
0 parents commit 30225f0
Show file tree
Hide file tree
Showing 14 changed files with 801 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
.DS_Store
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules

npm-debug.log
Empty file added README.md
Empty file.
50 changes: 50 additions & 0 deletions app.js
@@ -0,0 +1,50 @@
var express = require('express'),
routes = require('./routes'),
http = require('http'),
path = require('path');

var app = express();

app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function() {
app.use(express.errorHandler());
});

// basic route
app.get('/', routes.index);

// create the socket server
var server = http.createServer(app),
io = require('socket.io').listen(server);

// listen on the express port
server.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});

// io.enable('browser client minification'); // send minified client
// io.enable('browser client etag'); // apply etag caching logic based on version number
// io.enable('browser client gzip'); // gzip the file
// io.set('log level', 1); // reduce logging

io.sockets.on('connection', function (socket) {
// listen for device move
socket.on('devicemove', function (data) {
// on devicemove then move square
socket.broadcast.emit('movesquare', data);
});
});
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "devicesocket",
"version": "0.0.1",
"main": "app.js",
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.0",
"jade": "*",
"stylus": "*",
"socket.io": "~0.9.13"
},
"repository": "https://github.com/james2doyle/devicesocket",
"author": "james2doyle",
"license": "BSD"
}
52 changes: 52 additions & 0 deletions public/javascripts/client.js
@@ -0,0 +1,52 @@
// create the socket object
var socket = io.connect('http://localhost');

var logger = document.getElementById('logger');
// the main function that moves the box around the screen
function moveBox(data) {
var box = document.getElementById('box');
var transformstr = 'perspective(500px) rotateX('+data.z+'deg) rotateY('+data.x+'deg)';
box.style.webkitTransform = transformstr;
box.style.MozTransform = transformstr;
}

socket.on('connect', function () {
// let the client know we are connected
logger.style.color = '#22d332';
logger.innerText = 'socket connected';
// listen for move square
socket.on('movesquare', function(data) {
// send the data here for local manipulation
moveBox(data);
});
socket.on('disconnect',function() {
// visually disconnect
logger.style.color = '#d31713';
logger.innerText = 'socket disconnected';
});
});
// get the check box
var is_client = document.getElementById('is_client');
// basic function to grab the device orientation
function handleOrientationEvent(z,x,o) {
var data = {
z: (Math.round(z))*5,
x: (Math.round(x))*5,
o: (Math.round(o))*5
};
if(is_client.checked) {
// emit the devicemove event with the device data attached
socket.emit('devicemove', data);
// move it locally
moveBox(data);
}
}
// create the event handler and its properties
if(window.DeviceOrientationEvent) {
window.addEventListener("deviceorientation", function(event) {
var rotateDegrees = event.alpha;
var leftToRight = event.gamma;
var frontToBack = event.beta;
handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
}, false);
}
38 changes: 38 additions & 0 deletions public/stylesheets/mixins.styl
@@ -0,0 +1,38 @@
border-radius()
-webkit-border-radius arguments
-moz-border-radius arguments
border-radius arguments

box-shadow()
-webkit-box-shadow arguments
-moz-box-shadow arguments
box-shadow arguments

transform()
-webkit-transform arguments
-moz-transform arguments
-ms-transform arguments
-o-transform arguments
transform arguments

transition()
-webkit-transition arguments
-moz-transition arguments
-ms-transition arguments
-o-transition arguments
transition arguments

animation()
-webkit-animation arguments
-moz-animation arguments
-ms-animation arguments
-o-animation arguments
animation arguments

text-shadow()
-webkit-text-shadow arguments
text-shadow arguments

opacity(n)
opacity n
filter unquote('progid:DXImageTransform.Microsoft.Alpha(Opacity=' + round(n * 100) + ')')

0 comments on commit 30225f0

Please sign in to comment.