I have trouble with binding AJAX to Socket IO. I make a web chat with registration. After registration client send ajax request to the server and it opens web socket to chatting. And i actually don't know am I actyally do this(I mean can I just open socket without AJAX)
var app = express();
var cors = require('cors')
var server = app.listen(4000);
...
function WebSocket(server, accessMessage)
{
var io = require('socket.io')(server);
io.on('connection', (ws) => { // ws -- web socket
var currentroom = room_list[0]; // Global room (like a menu)
console.log(accessMessage);
for (var i = 0; i <= user_list.length; i++) {
if (!user_list[i]) {
user_list[i] = {
Id: ws,
name: "",
room: "",
Auth: false,
data: {
ImgHASH: ""
}
};
//joinroom(ws,currentroom);
break;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire