I'm trying to make an online multiplayer game with express, socket.io, and nodejs. This is my first time using nodejs, and my first time asking a question so if I do anything wrong please tell me. The problem is happening in the sign in part. I've figured out that the client isn't responding to a server emission. I've looked at this question, Socket.IO server not receiving message from client but it didn't help.
This is the relevant server code:
var io = require('socket.io')(serv,{});
io.sockets.on('connection', function(socket) {
socket.id = Math.random();
SOCKET_LIST[socket.id] = socket;
socket.on('signIn',function(data){
if(data.username === 'bob' && data.password === "asd"){
Player.onConnect(socket);
socket.emit('signInResponse',{success:true});
console.log('got this far')
}else {
socket.emit('signInResponse',{success:false});
}
})
This is the relevant client code:
<script>
var socket = io();
//sign
var signDiv = document.getElementById('signDiv');
var signDivUsername = document.getElementById('signDiv-username');
var signDivSignIn = document.getElementById('singDiv-singIn');
var signDivSignUp = document.getElementById('signDiv-singUp');
var signDivPassword = document.getElementById('signDiv-password');
signDivSignInfunc = function(){
console.log('it started')
socket.emit('signIn',{username:signDivUsername.value,password:signDivPassword.value});
}
socket.on('signInResponse',function(data){
console.log('almost there')
if(data.success){
signDiv.style.display = 'none';
gameDiv.style.display = 'inline-block';
console.log('worked')
}else
alert('Sign in unsuccessful');
})
Help would be greatly appreciated, thank you.