This commit is contained in:
Juho Teperi
2012-10-23 10:10:03 +03:00
parent 86c3fb0537
commit c03a1607a2
2 changed files with 41 additions and 4 deletions

View File

@@ -11,10 +11,7 @@
".cache", ".cache",
".meteor" ".meteor"
], ],
"path": "/home/juho/Source/bicyclesim" "path": "."
},
{
"path": "/home/juho/Source/bicyclesim-bundle"
} }
] ]
} }

View File

@@ -72,8 +72,48 @@ Template.sim.helpers({
} }
}); });
var sock = new SockJS("http://localhost:9999/speed");
function init_sim() { function init_sim() {
sock.onopen = function() {
console.log('open');
};
sock.onmessage = function(e) {
if (Session.equals('page', 'sim') && window.point) {
debug('message', e.data);
var dist = parseInt(e.data, 10) * c();
speed_buffer.push(dist);
Session.set('speed', speed_buffer.sum() / 5);
Session.set('distance', Session.get('distance') + 3 * dist);
window.traveled += 3 * dist;
if (window.traveled >= window.point.distance) {
var next = Points.findOne({_id: window.point.next});
// Stay on current point if no next point exists
if (next) {
window.traveled -= next.distance;
maps.travel(next._id, {route: true});
zoom = 1;
zoom_target = 1;
window.point = next;
}
}
}
};
sock.onclose = function() {
console.log('close');
};
Meteor.autosubscribe(function () { Meteor.autosubscribe(function () {
if (Session.equals('page', 'sim')) { if (Session.equals('page', 'sim')) {
var route = Routes.findOne({_id: Session.get('route')}); var route = Routes.findOne({_id: Session.get('route')});