Currently, I am developing a chat application using SignalR 2.0, like many others in the same field.
In my Win8.1 application, when the user closes the application, the hub receives the OnDisconnected event and removes the user from the list on the hub. A message is then sent to all clients informing them that the user has left the chat.
However, when I integrate SignalR and JavaScript into a webpage, the hub does not receive any notification when the tab or browser is closed...
Does anyone have any idea how to properly close the connection?
This is what I have coded:
Startup Hub
[assembly: OwinStartup(typeof(ChatServer.Startup))]
namespace ChatServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Map all hubs to "/signalr"
app.MapSignalR();
}
}
}
Hub
[HubName("ChatHub")]
public class ChatHub : Hub
{
private static List<User> Users = new List<User>();
// Rest of the code remains unchanged...
HTML - Javascript:
Javascript:
// The JavaScript section goes here...
Win8.1 client
// The Win8.1 client part also remains the same...
Even after following these steps, my hub fails to trigger the OnDisconnected event when closing the tab, browser, or navigating to another site. This issue persists despite using Chrome Version 32.0.1700.68 beta-m or Internet Explorer 11 as browsers.