Reputation: 747
I can set a breakpoint at my server method and it is being called on hub start. And if i put a breakpoint at hub.start(), I do see that the connection already has the client side version of the method bound. But somehow the method is not being called from server. Here is my code:
Server method
[HubName("MovementHub")]
public class MovementHub : Hub
{
public void UpdatePlayerPosServer(PlayerPosition playerPosition)
{
playerPosition.LastUpdatedBy = Context.ConnectionId;
Clients.AllExcept(playerPosition.LastUpdatedBy).updatePlayerPosClient(playerPosition); //debugging here shows the playerposition all filled out nicely. this hub method is HIT.
}
}
Client Method
$(() => {
var connection = (<any>$.connection).MovementHub;
//this method is never called
connection.client.updatePlayerPosClient = (playerPosModel) => {
alert("updatingremotePlayers: " + playerPosModel);
}
});
Hub Start (typescript class. method is called from another class)
public updateServerPos = (x: number, y: number) => {
var connection = (<any>$.connection).MovementHub;
this.LoginID = $("#displayname").val();
$.connection.hub.start().done(() => {
var playerposModel = { Id: this.LoginID, X: x, Y: y };
connection.server.updatePlayerPosServer(playerposModel); //debugging here shows me that "connection" has the client method bound at this point
}).fail(function(error) {
console.log(error);
});
}
I've read a few posts on this that specify you have to have the client method bound before hub start, but IT IS. And the server method is getting called correctly. So not sure what's goin on here.
Edit: I realized, I'm an idiot and might be falling victim to being skipped by the "AllExcept" call on clients. I was the exception! lol
The only remaining problem onw is why I have to have the client Method "instantiated" in an IFFE? I'd like to put it in the same Typescript class where the server method is being called from.
Upvotes: 1
Views: 385
Reputation: 747
Turns out MIXING javascript IIFE calls with typescript calls can be hazardous. I have a totally unrelated (i thought) hub start happening BEFORE this client method was bound. I realized, even tho, I have two Hubs, there's really only one hub.start(); silly me.
Upvotes: 1