Reputation: 1137
This is becoming a head scratcher for me and hope maybe someone could help shed some new light on this.
I have a MVC app that is using SignalR and is hosted on Azure.
on the client I have this js
window.connection = $.hubConnection('https://giveabuck.azurewebsites.net', { qs: "access_token=" + sessionStorage.getItem("accessToken") });
$.signalR.ajaxDefaults.headers = { Authorization: "Bearer " + sessionStorage.getItem("accessToken") };
window.proxy = connection.createHubProxy('signalRHub');
proxy.on("relaythis", function (callOut) { alert(callOut) });
proxy.on("joinedSession", function (data) { alert(data)});
connection.logging = true;
connection.start({transport: 'longPolling'});
On the server, this
[Authorize]
public class SignalRHub : Hub
{
private readonly Broadcaster _Broadcaster;
public SignalRHub()
: this(Broadcaster.Instance) { }
public SignalRHub(Broadcaster broadcaster)
{
_Broadcaster = broadcaster;
}
public override Task OnConnected()
{
this.connectedCallback(this.Context.User.Identity.Name);
return base.OnConnected();
}
public void relayThis(string userName, string message)
{
Clients.User(userName).relaythis(message);
}
public void connectedCallback(string connectedClient){
Clients.All.joinedSession(connectedClient + " has joined!");
}
}
The PhoneGap app has the same client side script with one configuration difference where I keep a static version of the generated hub.js as it can not be auto generated.
The issue is that the PhoneGap version the message will not arrive to the specified username when calling relayThis() ie calling proxy.invoke("relayThis", "[email protected]", "Hello"). However, if I do the same and the user is on the hosted website, the message arrives. Furthermore, it is not that signalr is plain not working on the app. When the app starts a connection, the app gets the message that "[email protected]" has joined.
Viewing the logs on the PhoneGap app shows activity when "joinedSession" is called but no activity for "relaythis".
Best I can think is that for some reason the PhoneGap user is not being added to the hub Clients but I have yet to find a way to assert that.
Also, I use OAuth for authorization and but I don't suspect it causing any problems as I mentioned, the PhoneGap app will receive joinedSession and it can make requests of its own, so it is passing Auth.
Upvotes: 1
Views: 249
Reputation: 1137
SignalR userId strings are case sensitive!!!
Well here it is. The reason the app was not sending to a specific user is because my phone has this nice tendency to want to capitalize even email addresses. So the app spins up a nice OAuth token with the identity name a [email protected] When I called signalR I was inputting the user name the way I registered [email protected]. and for SignalR, they are not the same thing and only know what was found in the OAuth data.
Upvotes: 1