Well, I've developed a chat according with this link and everything worked fine. But the disconnected event does not work right.
What happens is that, according to the referral link, this event is triggered when the user closes the page, thus notifying users online that that user has left the chat. Except that this event is not being called.
What happens is that if I close the tab this event is not triggered and does not tell the room that the user left, and more, that username is saved and I can not chat with the user. same name, even when you closed the tab and trying to open it again.
So that I can put the same name, I need to wait for the default timeout so that the entire site cookie is deleted ...
Could anyone help me?
Remembering that all other events work, only the one that does not
Here are the codes for the event:
In the class I'm extending HUB, the OnDisconnected method:
public override Task OnDisconnected()
{
var name = dic.FirstOrDefault(x => x.Value == Context.ConnectionId.ToString());
string s;
dic.TryRemove(name.Key, out s);
return Clients.All.disconnected(name.Key);
}
- Here is an error. I can not use the override:
'SignalIRChatMVC.Hubs.MyHub.OnDisconnected ()': no suitable method found to override
The event in javascript
chat.client.disconnected = function (name) {
//Calls when someone leaves the page
$('#chats').append('<div class="border"><i>' + name + ' saiu da sala </i></div>');
$('#onlineList div').remove(":contains('" + name + "')");
$("#users option").remove(":contains('" + name + "')");
}
And here's the div you use to do user manipulations online or offline
<div style="height: 80%;">
<div id="chats" style="width: 80%; float: left;"></div>
<div id="onlineList" style="width: 19%; float: right; border-left: solid red 2px; height: 100%;">
<div style="font-size: 20px; border-bottom: double">Usuários online</div>
</div>