drop the global user list
This global user list is not apprpriated to a normal usage Also simplifies the code: rollback on user authenticated js flag. And finally Fixes a bug, trying to reconnect the hub ([TODO] middleware black listing IP's prsenting abnormal rate on connections queries).
This commit is contained in:
parent
a7f6a2116b
commit
a7c5e6be34
2 changed files with 31 additions and 33 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
<label><input type="checkbox" id="mute" />Muet</label>
|
<label><input type="checkbox" id="mute" />Muet</label>
|
||||||
|
|
||||||
<div class="container disabled panel" id="chatview" data="fullchatview"
|
<div class="container disabled panel" id="chatview" data="fullchatview"
|
||||||
data-chans="yavsc" data-is_auth="@ViewBag.IsAuthenticated" data-mutectl="mute" ></div>
|
data-chans="yavsc" data-mutectl="mute" ></div>
|
||||||
|
|
||||||
@section scripts {
|
@section scripts {
|
||||||
<!--Reference the autogenerated SignalR hub script. -->
|
<!--Reference the autogenerated SignalR hub script. -->
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@ window.ChatHubHandler = (function ($) {
|
||||||
|
|
||||||
// the channel list
|
// the channel list
|
||||||
var chans = [];
|
var chans = [];
|
||||||
// authencitated flagf from server
|
|
||||||
var is_auth = $view.data('is_auth');
|
|
||||||
// private chat list
|
// private chat list
|
||||||
var userlist = [];
|
var userlist = [];
|
||||||
|
|
||||||
|
|
@ -62,12 +60,12 @@ window.ChatHubHandler = (function ($) {
|
||||||
// Create a function that the hub can call back to display messages.
|
// Create a function that the hub can call back to display messages.
|
||||||
chat.client.addMessage = function (name, room, message) {
|
chat.client.addMessage = function (name, room, message) {
|
||||||
// Add the message to the page.
|
// Add the message to the page.
|
||||||
var $userTag = $("<a>" + htmlEncode(name) + "</a>").click(function(){
|
var $userTag = $('<a>' + htmlEncode(name) + '</a>').click(function() {
|
||||||
buildPv(name);
|
buildPv(name);
|
||||||
});
|
});
|
||||||
var $li = $('<li class="discussion"></li>');
|
var $li = $('<li class="discussion"></li>');
|
||||||
$userTag.appendTo($li)
|
$userTag.appendTo($li);
|
||||||
$li.append(' '+ htmlEncode(message));
|
$li.append(' ' + htmlEncode(message));
|
||||||
$li.appendTo($('#r' + room));
|
$li.appendTo($('#r' + room));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -82,8 +80,13 @@ window.ChatHubHandler = (function ($) {
|
||||||
|
|
||||||
chat.client.notifyRoom = function (tag, targetid, message) {
|
chat.client.notifyRoom = function (tag, targetid, message) {
|
||||||
// Add the notification to the page.
|
// Add the notification to the page.
|
||||||
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
if (tag === 'connected' || tag === 'reconnected') {
|
||||||
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
onUserConnected(targetid, message);
|
||||||
|
return;
|
||||||
|
} else if (tag === 'disconnected') {
|
||||||
|
onUserDisconnected(targetid, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// eslint-disable-next-line no-warning-comments
|
// eslint-disable-next-line no-warning-comments
|
||||||
// TODO reconnected userpart userjoin deniedpv
|
// TODO reconnected userpart userjoin deniedpv
|
||||||
$('<li></li>').addClass(tag).append(tag + ': ' + targetid + ' ').append(message).addClass(tag).appendTo($('#room_' + targetid));
|
$('<li></li>').addClass(tag).append(tag + ': ' + targetid + ' ').append(message).addClass(tag).appendTo($('#room_' + targetid));
|
||||||
|
|
@ -127,7 +130,6 @@ window.ChatHubHandler = (function ($) {
|
||||||
|
|
||||||
var buildChan = function (chdp, chanType, chanName, sendCmd) {
|
var buildChan = function (chdp, chanType, chanName, sendCmd) {
|
||||||
var chanId = chanType + chanName;
|
var chanId = chanType + chanName;
|
||||||
// if ($('#' + chanId)) return;
|
|
||||||
var roomTag = $('<a>' + chdp + chanName + '</a>').addClass('btn');
|
var roomTag = $('<a>' + chdp + chanName + '</a>').addClass('btn');
|
||||||
roomTag.prop('id', 'sel_' + chanId).click(function () {
|
roomTag.prop('id', 'sel_' + chanId).click(function () {
|
||||||
setActiveChan(chanId);
|
setActiveChan(chanId);
|
||||||
|
|
@ -155,37 +157,36 @@ window.ChatHubHandler = (function ($) {
|
||||||
this.value = '';
|
this.value = '';
|
||||||
}
|
}
|
||||||
}).appendTo(roomview);
|
}).appendTo(roomview);
|
||||||
if (chanType == 'r')
|
if (chanType == 'r') chans.push(chanName);
|
||||||
chans.push(chanName);
|
else if (chanType == 'u' || chanType == 'a') userlist.push(chanName);
|
||||||
else if (chanType == 'u' || chanType == 'a')
|
|
||||||
userlist.push(chanName);
|
|
||||||
setActiveChan(chanId);
|
setActiveChan(chanId);
|
||||||
};
|
};
|
||||||
var buildRoom = function (roomName) {
|
var buildRoom = function (roomName) {
|
||||||
if (chans.some(function(cname){ return cname == roomName ; }))
|
if (chans.some(function(cname) { return cname == roomName; })) setActiveChan('r' + roomName);
|
||||||
setActiveChan('r' + roomName);
|
else buildChan('#', 'r', roomName, chat.server.send);
|
||||||
else
|
};
|
||||||
buildChan('#', 'r', roomName, chat.server.send); };
|
|
||||||
var buildPv = function (userName) {
|
var buildPv = function (userName) {
|
||||||
if (userlist.some(function(uname){ return uname == userName ; }))
|
if (userlist.some(function(uname) { return uname == userName; })) setActiveChan('u' + userName);
|
||||||
setActiveChan('u' + userName);
|
|
||||||
else
|
else
|
||||||
if (userName[0]=='?') buildChan('@?', 'a', userName.slice(1), chat.server.sendPV);
|
if (userName[0] == '?') buildChan('@?', 'a', userName.slice(1), chat.server.sendPV);
|
||||||
else buildChan('@', 'u', userName, chat.server.sendPV);
|
else buildChan('@', 'u', userName, chat.server.sendPV);
|
||||||
};
|
};
|
||||||
|
|
||||||
$view.data('chans').split(',').forEach(function (chan) {
|
$view.data('chans').split(',').forEach(function (chan) {
|
||||||
buildRoom(chan);
|
buildRoom(chan);
|
||||||
});
|
});
|
||||||
var getUsers = function () {
|
|
||||||
|
/*var getUsers = function () {
|
||||||
$.get('/api/chat/users').done(function (users) {
|
$.get('/api/chat/users').done(function (users) {
|
||||||
$.each(users, function () {
|
$.each(users, function () {
|
||||||
var user = this;
|
var user = this;
|
||||||
addChatUser(user.UserName);
|
addChatUser(user.UserName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};*/
|
||||||
function onCx(recting) {
|
// eslint-disable-next-line no-warning-comments
|
||||||
|
// TODO only query user list for a given channel, and only for a participant
|
||||||
|
function onCx() {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
chans.forEach(function (room) {
|
chans.forEach(function (room) {
|
||||||
chat.server.join(room).done(function (chatInfo) {
|
chat.server.join(room).done(function (chatInfo) {
|
||||||
|
|
@ -203,17 +204,16 @@ window.ChatHubHandler = (function ($) {
|
||||||
|
|
||||||
// Start the connection.
|
// Start the connection.
|
||||||
$.connection.hub.start().done(function () {
|
$.connection.hub.start().done(function () {
|
||||||
onCx(false);
|
onCx();
|
||||||
});
|
});
|
||||||
|
|
||||||
$.connection.hub.disconnected(function () {
|
$.connection.hub.disconnected(function () {
|
||||||
|
|
||||||
onDisCx();
|
onDisCx();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$.connection.hub.start().done(function () {
|
$.connection.hub.start().done(function () {
|
||||||
onCx(true);
|
onCx();
|
||||||
}); }
|
});
|
||||||
, 30000); // Re-start connection after 30 seconds
|
}, 30000); // Re-start connection after 30 seconds
|
||||||
});
|
});
|
||||||
|
|
||||||
chanName.keydown(function (event) {
|
chanName.keydown(function (event) {
|
||||||
|
|
@ -251,8 +251,6 @@ window.ChatHubHandler = (function ($) {
|
||||||
.appendTo(ulist);
|
.appendTo(ulist);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This optional function html-encodes messages for display in the page.
|
// This optional function html-encodes messages for display in the page.
|
||||||
function htmlEncode(value) {
|
function htmlEncode(value) {
|
||||||
var encodedValue = $('<div />').text(value).html();
|
var encodedValue = $('<div />').text(value).html();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue