Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web code to the repo #1

Merged
merged 1 commit into from
Sep 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store

101 changes: 101 additions & 0 deletions Web/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

/*
* Module Dependencies.
*/
var express = require('express');
var socketio = require('socket.io');
var crypto = require('crypto');

console.log('Configuring the server...');
process.openStdin();
var app = express();
var server = app.listen(8080);
app.use(express.bodyParser());

var tags = [];
var sessions = [];

console.log('Configuring web sockets...');
var io = socketio.listen(server);
io.sockets.on('connection', function (socket) {
console.log('CONNECTION!!!');
socket.on('gibVideos', function(data) {
socket.emit('hazVideos', sessions);
});
socket.on('gibTags', function(data) {
socket.emit('hazTags', tags);
});
});

function generateUniqueId() {
var chars = "abcdefghijklmnopqrstuwxyz";
var rnd = crypto.randomBytes(6)
, value = new Array(6)
, len = chars.length;

for (var i = 0; i < 6; i++) {
value[i] = chars[rnd[i] % len]
};

return '' + value.join('');
}

console.log('Configuring routes...');
/*
* Get a list of all of the current tags.
*/
app.get('/api/tags', function (req, res) {
res.json(tags);
});
/*
* Adds a tag to the list of available tags.
*/
app.post('/api/tags', function (req, res) {
console.log('Received data for tags!');
console.log(req.body);
console.log(req.body.name);
tags.push(req.body.name);
io.sockets.emit('hazNewTag', {data: req.body.name});
res.json({
success: true
});
});
/*
* Creates a new session for watching videos.
*/
app.post('/api/sessions', function (req, res) {
console.log('Received data for sessions!');
console.log(req.body);
console.log(req.body.latitude);
// Generate the unique ID and secret.
//var uniqueId = generateUniqueId();
var uniqueId = generateUniqueId();

// Create a new session from the provided information, add it to the session list.
var newSession = {
uniqueId: uniqueId,
tag: req.body.tag,
latitude: req.body.latitude,
longitude: req.body.longitude
};
sessions.push(newSession);

console.log(uniqueId);

// Send the response forward.
res.json({
uniqueId: uniqueId
});

// Let all current clients know about the new video.
io.sockets.emit('hazMoreVideo', {uniqueId: uniqueId, tag: req.body.tag});


});

console.log('Configuring interrupts...');
process.on('SIGINT', function() {
console.log('\nGot SIGINT, aborting...');
process.exit(0);
});
1 change: 1 addition & 0 deletions Web/node_modules/.bin/express

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

188 changes: 188 additions & 0 deletions Web/node_modules/body-parser/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Web/node_modules/body-parser/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading