As a Node.js newbie I am trying to change the Smartphone Remote Control with Node.js and Socket.io example by Nick Anastasov so that a password is not required.
In the original source code the app.js file sends { access : 'granted' }
after the word kittens has been entered into a web form and the script.js starts its main tasks, for example unblurs the web page:
socket.on('access', function(data) {
if (data.access === "granted") { // XXX Tried removing this line
blurredElements.removeClass('blurred');
form.hide();
$(window).on('hashchange', function() {
// ....
});
socket.on('navigate', function(data) {
// ....
});
}
});
I have changed the app.js so that it does not emit access
at all.
Then I have tried removing just the line if (data.access === "granted")
from script.js, but this of course hasn't worked: the web page stays blurred, because no access
event is received anymore (neither granted
, nor denied
).
My question is: how should I please change the above code, so that it is run once the connection is established?
Should I maybe use socket.on('connect')
or socket.on('connection')
or is it same problem (since there is no string connect
being sent)?
UPDATE:
As suggested by Brad (thank you!) I have changed the string in script.js from "access" to "connection", but the web page stays blurred - here is the complete source code:
$(function() {
Reveal.initialize({
history: true
});
var socket = io();
var presentation = $('.reveal');
socket.on('connection', function(data){ // XXX changed this
presentation.removeClass('blurred'); // XXX not called
var ignore = false;
$(window).on('hashchange', function(){
if (ignore){
return;
}
var hash = window.location.hash;
socket.emit('slide-changed', {
hash: hash
});
});
socket.on('navigate', function(data){
window.location.hash = data.hash;
ignore = true;
setInterval(function () {
ignore = false;
},100);
});
});
});
And here is the complete app.js source code:
var express = require('express'),
app = express();
var port = process.env.PORT || 8080;
var io = require('socket.io').listen(app.listen(port));
app.use(express.static(__dirname + '/public'));
var presentation = io.on('connection', function (socket) {
socket.on('slide-changed', function(data){
presentation.emit('navigate', {
hash: data.hash
});
});
});
Aucun commentaire:
Enregistrer un commentaire