OnConnected Task does not start when upgrading to SignalR 1.0.0 alpha2

I recently tried updating to signalR 1.0.0 Alpha2. I went through the wiki, changed what I thought I needed to change, also made sure that the assembly was loaded with new files. Here is my js:

$(function () { var Chat = $.connection.ChatHub; ... $.connection.hub.start( .done(function(){ alert("Now connected!"); }) .fail(function(){ alert("Could not Connect!"); }); }); 

Here is my hub class:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR.Hubs; using MyProject.Domain.Abstract; using Microsoft.AspNet.SignalR; using System.Threading.Tasks; using System.Diagnostics; using System.Web.Security; using MyProject.Domain.Entities; using System.Web.Script.Serialization; using System.Text.RegularExpressions; using MyProject.Domain.Concrete; using MyProject.Domain.Helpers; using System.Web.Mvc; namespace MyProject.Web.RealTime { public class ChatMessage { public string ChatId { get; set; } public string Message { get; set; } public string FullName { get; set; } public string Time { get; set; } public string School { get; set; } public string Major { get; set; } public string ImageUrl { get; set; } } [HubName("ChatHub")] public class Chat : Hub { //Initialize Repoisotries private IProfileRepository profileRepository; private ISiteDataRepository siteDataRepository; private IChatRepository chatRepository; private IOnlineUserRepository onlineUserRepository; private IRecentActivityRepository recentActivityRepository; MembershipUser MainUser = Membership.GetUser(); UserProfile MainProfile; //In memory objects //public static Dictionary<Guid, List<string>> onlineUsers = new Dictionary<Guid, List<string>>(); //Constructor Injection for profile repository and site data repository public Chat(IProfileRepository repo, ISiteDataRepository siteRepo, IChatRepository chatRepo, IOnlineUserRepository onlineUserRepo, IRecentActivityRepository recentActivityRepo) { profileRepository = repo; siteDataRepository = siteRepo; chatRepository = chatRepo; onlineUserRepository = onlineUserRepo; MainProfile = profileRepository.GetProfile((Guid)MainUser.ProviderUserKey); recentActivityRepository = recentActivityRepo; } public override Task OnDisconnected() { disconnectUser(); List<ContactItem> contacts = profileRepository.GetFollowedOnlineContacts(MainProfile.UserId); foreach (ContactItem ci in contacts) { Clients.Group(Convert.ToString(ci.ChatId)).onlineUserHandler(Convert.ToString(MainProfile.ChatId), false); } return base.OnDisconnected(); } public override Task OnReconnected() { connectUser(); List<ContactItem> contacts = profileRepository.GetFollowedOnlineContacts(MainProfile.UserId); foreach (ContactItem ci in contacts) { Clients.Group(Convert.ToString(ci.ChatId)).onlineUserHandler(Convert.ToString(ci.ChatId), true); } return base.OnReconnected(); } public override Task OnConnected() { Debug.WriteLine("Connected``````````````````````````````````"); connectUser(); List<ContactItem> contacts = profileRepository.GetFollowedOnlineContacts(MainProfile.UserId); foreach (ContactItem ci in contacts) { Clients.Group(Convert.ToString(ci.ChatId)).onlineUserHandler(Convert.ToString(MainProfile.ChatId), true); } return base.OnConnected(); } private void connectUser() { if (onlineUserRepository.ConnectUser(MainProfile.UserId, Context.ConnectionId)) { Groups.Add(Context.ConnectionId, Convert.ToString(MainProfile.ChatId)); } } private void disconnectUser() { onlineUserRepository.DisconnectUser(MainProfile.UserId, Context.ConnectionId); Groups.Remove(Context.ConnectionId, Convert.ToString(MainProfile.ChatId)); } } } 

On the client side, I get a connection message, but when I start debugging and put a breakpoint in the "OnConnected" task, it never breaks or starts nothing in my hub class. what can i do wrong

This is my build for the new SignalR:

enter image description here

I used this in my NinjectWebCommon.cs file in the App_Start folder, but since I updated it, it has given me errors, so I commented on this, it may also be a problem, but not sure, because signalR.ninject seems to be not working or gave me a bunch of errors:

 GlobalHost.DependencyResolver = new NinjectDependencyResolver(kernel); GlobalHost.DependencyResolver.Register(typeof(IConnectionIdGenerator), () => new MyConnectionFactory()); RouteTable.Routes.MapHubs(new NinjectDependencyResolver(kernel)); 
+4
source share
2 answers

You must add JavaScript before starting the link to the hub:

 $.connection.yourhub.client.connected = function () { }; $.connection.yourhub.client.disconnected = function () { }; 
+2
source

The problem was that I was using a non-updated version of NinjectDependancyResolver, and I'm not sure if they updated it or not. In fact, I stopped using dependency injection in my hub classes because I couldn’t get it working.

+1
source

Source: https://habr.com/ru/post/1447677/


All Articles