3
Guys, I’ve developed a chat accordingly with this link and it all worked out well. But the Disconnected event doesn’t work right.
What happens is that, according to the reference link, this event is triggered when the user closes the page, and thus notifying online users that that user has left the chat. Only this event is not being called.
What happens is that if I close the tab(the page) this event is not triggered and does not warn the room that the user left, and more, this username is saved and I can not enter the chat with the same name, even when closed the tab and trying to open again.
In order for me to be able to put the same name, I need to wait for the default timeout so that all cookie of the site is deleted...
I wonder if someone could help me ?
Remembering that all other events work, only that
Here the codes referring to the event:
In the class 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 already an error. I can’t 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 is the div that uses to do the manipulations of user 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>
So if I change the term override to virtual, it would work ? In a good way ?
– Érik Thiago
Yes, the virtual is as defined in the class
base
. When does the override just replace thevirtual
foroverride
. (I am editing the answer regarding the means of terminating the link onSignalR
)– Omni
Our @Omni, thank you very much ! I’m some time breaking my head to solve ! I’m waiting for your edition !
– Érik Thiago