Starting to work on some better pinging for usernames

This commit is contained in:
Kasper Rynning-Tønnesen
2017-09-13 18:36:12 +02:00
parent 2931dfc99b
commit 22b62e36cd
6 changed files with 56 additions and 9 deletions

View File

@@ -13,8 +13,7 @@ module.exports = function() {
socket.emit("ok");
});
var ping_timeout;
var socketid = socket.zoff_id;
var coll;
var in_list = false;
@@ -123,9 +122,12 @@ module.exports = function() {
}
});
socket.on('namechange', function(data)
socket.on('namechange', function(msg)
{
Chat.namechange(data, guid, coll);
if(coll == undefined) {
coll = msg.channel;
}
Chat.namechange(msg.name, guid, coll);
});
socket.on('removename', function()
@@ -305,26 +307,36 @@ module.exports = function() {
socket.on('disconnect', function()
{
console.log("disconnect");
clearTimeout(ping_timeout);
List.left_channel(coll, guid, short_id, in_list, socket, false);
});
socket.on('disconnected', function()
{
console.log("disconnected");
clearTimeout(ping_timeout);
List.left_channel(coll, guid, short_id, in_list, socket, false);
});
socket.on('reconnect_failed', function()
{
console.log("reconnect_failed");
clearTimeout(ping_timeout);
List.left_channel(coll, guid, short_id, in_list, socket, false);
});
socket.on('connect_timeout', function()
{
console.log("connect_timeout");
clearTimeout(ping_timeout);
List.left_channel(coll, guid, short_id, in_list, socket, false);
});
socket.on('error', function()
{
console.log("error");
clearTimeout(ping_timeout);
List.left_channel(coll, guid, short_id, in_list, socket, false);
});
@@ -358,8 +370,36 @@ module.exports = function() {
}
});
});
});
/*ping_timeout = setTimeout(function() {
send_ping(guid, coll, socket);
}, 3000);
var send_ping = function(guid, coll, socket) {
console.log(guid, coll);
if(coll == undefined) {
ping_timeout = setTimeout(send_ping, 3000);
} else {
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, docs) {
db.collection("connected_users").update({"_id": "total_users"}, {$inc: {total_users: -1}}, function(err, docs) {
db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, docs) {
db.collection("user_names").find({"guid": guid}, function(err, user_name) {
if(user_name.length > 0) {
db.collection("user_names").remove({"guid": guid}, function(err, docs) {
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: user_name[0].name}}, function(err, docs) {
socket.emit("self_ping");
ping_timeout = setTimeout(function(){
send_ping(guid, coll, socket);
}, 3000);
});
});
}
});
});
});
});
}
}*/
});
send_ping();
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ var Chat = {
namechange: function(newName)
{
socket.emit("namechange", newName);
socket.emit("namechange", {name: newName, channel: chan.toLowerCase()});
Crypt.set_name(newName);
},

View File

@@ -154,6 +154,11 @@ $().ready(function(){
}
});
}
if(conf_arr != undefined && conf_arr.name !== undefined && conf_arr.name !== "") {
setTimeout(function(){
Chat.namechange(conf_arr.name);
}, 1000);
}
});
socket.on("self_ping", function() {

View File

@@ -71,7 +71,9 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
app.use(cookieParser());
/* Starting DB and socketio */
io = require('socket.io')(server, {'pingTimeout': 25000}); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
io = require('socket.io')(server, {
pingTimeout: 25000,
}); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
db = require('./handlers/db.js');
var socketIO = require('./handlers/io.js');
socketIO();