Hi Everyone,
I am facing a strange issue. I have 2 ionic apps. I have implemented SignalR in both application.
Now the issue is it is working fine in one app. In another app, it can connect to server and create Connection Id, but unable to receive message.
Can anyone help me to find out the reason why it is not working in another app?
Here is my ionic code and it is same for both apps.
import { Injectable } from '@angular/core';
const win = window as any ;
const $ = win.$ ;
@Injectable()
export class BackgroundServiceProvider {
constructor() {
console.log('Hello BackgroundServiceProvider');
}
startSignalR(){
$(function () {
//Set the hubs URL for the connection
$.connection.hub.url = "http://localhost/api/signalr";
var connectionId;
$.connection.hub.start({ jsonp: true })
.done(function(){
connectionId = $.connection.hub.id;
console.log('Now connected, connection ID=' + $.connection.hub.id);
}).fail(function(e){
console.log(e);
});
$.connection.myHub.client.onMessageRecieved = function (userName, userType, message, notificationType) {
console.log(userName + " " + userType + " " + message + " " + notificationType);
}
});
}
}
Here is my C# code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;
using Application.Models;
namespace Application
{
public class MyHub : Hub
{
public static class UserHandler
{
public static HashSet<string> ConnectedId = new HashSet<string>();
}
public override Task OnConnected()
{
UserHandler.ConnectedId.Add(Context.ConnectionId);
return base.OnConnected();
}
public override Task OnDisconnected(bool flag)
{
return base.OnDisconnected(flag);
}
public void sendNotification(string userName, string userType, string message, string notificationType)
{
Clients.All.onMessageRecieved(userName, userType, message, notificationType);
}
public void GetConnectionId()
{
Clients.Client(Context.ConnectionId).getUser(UserHandler.ConnectedId);
}
}
}
Thanks