Commit e66e5a0b authored by Karan Goel's avatar Karan Goel
Browse files

sending and receiving data works

parent 61ebeecc
......@@ -12,68 +12,24 @@ server.listen(port, function () {
// Routing
app.use(express.static(__dirname + '/public'));
// Chatroom
// usernames which are currently connected to the chat
var usernames = {};
var numUsers = 0;
function sendEEGData() {
console.log('sending data');
io.sockets.emit('data', {
'eegPower': { 'beta': 1000 }
});
}
io.on('connection', function (socket) {
var addedUser = false;
// when the client emits 'new message', this listens and executes
socket.on('new message', function (data) {
// we tell the client to execute 'new message'
socket.broadcast.emit('new message', {
username: socket.username,
message: data
});
});
// when the client emits 'add user', this listens and executes
socket.on('add user', function (username) {
// we store the username in the socket session for this client
socket.username = username;
// add the client's username to the global list
usernames[username] = username;
++numUsers;
addedUser = true;
socket.emit('login', {
numUsers: numUsers
});
// echo globally (all clients) that a person has connected
socket.broadcast.emit('user joined', {
username: socket.username,
numUsers: numUsers
});
});
// when the client emits 'typing', we broadcast it to others
socket.on('typing', function () {
socket.broadcast.emit('typing', {
username: socket.username
});
});
io.on('connection', function (socket) {
console.log('Client connected');
// when the client emits 'stop typing', we broadcast it to others
socket.on('stop typing', function () {
socket.broadcast.emit('stop typing', {
username: socket.username
});
});
// let's mock some data and send it every second
setInterval(sendEEGData, 1000);
// when the user disconnects.. perform this
socket.on('disconnect', function () {
// remove the username from global usernames list
if (addedUser) {
delete usernames[socket.username];
--numUsers;
// echo globally that this client has left
socket.broadcast.emit('user left', {
username: socket.username,
numUsers: numUsers
});
}
console.log('Client disconnected');
});
});
......@@ -46,6 +46,7 @@
</footer>
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script src="https://cdn.socket.io/socket.io-1.3.0.js"></script>
<script src="js/app.js"></script>
</body>
</html>
\ No newline at end of file
</html>
......@@ -437,7 +437,7 @@ var Visualizer = function() {
*/
var SoundcloudLoader = function(player,uiUpdater) {
var self = this;
var client_id = "YOUR_SOUNDCLOUD_CLIENT_ID"; // to get an ID go to http://developers.soundcloud.com/
var client_id = "apigee"; // to get an ID go to http://developers.soundcloud.com/
this.sound = {};
this.streamUrl = "";
this.errorMessage = "";
......@@ -592,6 +592,12 @@ var UiUpdater = function() {
window.onload = function init() {
var socket = io();
socket.on('data', function(data) {
console.log(data);
});
var visualizer = new Visualizer();
var player = document.getElementById('player');
var uiUpdater = new UiUpdater();
......@@ -644,7 +650,7 @@ window.onload = function init() {
});
window.addEventListener("keydown", keyControls, false);
function keyControls(e) {
switch(e.keyCode) {
case 32:
......@@ -659,8 +665,8 @@ window.onload = function init() {
// right key pressed
loader.directStream('forward');
break;
}
}
}
};
\ No newline at end of file
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment