Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 30225f0
Showing
14 changed files
with
801 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) + ')') |
Oops, something went wrong.