We have a SignalR server in .Net Framework which serves to Windows as well as Web clients.
For Web clients we are using Javascript library provided for SignalR and we are using it for our Angular app.
Issue is for following scenario.
If sender is windows app and receiver being Web App, Web App doesn't receive a message unless Web App clicks on send message button we have.
Same scenario with web to windows. If Web app is sending a message, message is only received when windows app again sends a message.
Both are using same hub, joined same group.
While checking I found that message does go to server however, receive message gets fired only when send message is invoked.
Web to Web and Windows to Windows app works fine without any issues.
Please let me know if more information is required.
Windows Code for hub connection:
_hubConnection = new HubConnection(signalRHubAddress);
//We Add SAML Token into the header as hub is secured by SAML.
_hubConnection.Credentials = CredentialCache.DefaultCredentials;
_hubConnection.Closed += OnDisconnected;
_hubConnection.Reconnecting += OnReconnecting;
_hubConnection.Error += OnError;
_hubConnection.StateChanged += OnStateChanged;
_hubProxy = _hubConnection.CreateHubProxy(applicationHub);
_hubProxy["environmentName"] = "Environment";
_hubConnection.Start();
_hubProxy.On<string>("JoinGroupMessage", msg => ProcessJoinGroupMessage(msg,false));
_hubProxy.On<string>("ReJoinGroupMessage", msg => ProcessJoinGroupMessage(msg,true));
_hubProxy.On<string>("LeaveGroupMessage", msg => ProcessLeaveGroupMessage(msg));
_hubProxy.On<string>("ReceiveMessage", msg => ProcessReceiveMessage(msg));
Web Client Code:
$.ajax({
url: hubParam.homeUrl,
type: 'Post',
dataType: "json",
contentType: "application/x-www-form-urlencoded;charset=utf-8",
data: {
SAMLToken: token
},
success: function (Id) {
myHub.assertionId = Id;
myHub.connection = getConnection(hubParam.hubUrl);
myHub.hubProxy = getHubProxy(myHub.connection, hubParam.hubName);
myHub.hubProxy.on(clientFuncName, function (msg) {
callbackFunc(msg);
});
myHub.connection.start().done(function () {
console.log(resources.connectionStarted);
})
.fail(function (err) {
console.log(resources.connectionFailed + err.toString());
});
}
getConnection = function(hubUrl) {
if (myHub.connection == null || myHub.connection === 'undefined') {
myHub.connection = $.hubConnection(hubUrl);
myHub.connection.qs = {
'version': myHub.version
};
}
else if(myHub.connection.state === 4) {
myHub.connection.start();
}
return myHub.connection;
};
getHubProxy = function (hubConn, hubName) {
if (myHub.hubProxy == null || myHub.hubProxy === 'undefined') {
myHub.hubProxy = hubConn.createHubProxy(hubName);
}
return myHub.hubProxy;
};
Thanks, Vatsal