I am using SignalR version 2.2.0. With the code below, I get an exception indicating that $ does not define hubConnection. I know that I have script paths correctly, because I can set breakpoints in the signalr script and see what they hit. I even stepped to where the hubConnection function is defined, and yet I get an exception. What am I doing wrong?
<script type="text/javascript" src="~/scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="~/scripts/jquery.signalR-2.2.0.js"></script>
<script type="text/javascript">
$(function() {
initAvailabilitySignalR("D420A92E163C43AB85CE342D5C10106B");
});
function initAvailabilitySignalR(tenantId) {
try {
var connection = $.hubConnection();
var proxy = connection.createHubProxy('SignalRHub');
proxy.on('AvailabilityChangedNotification', function(message) {
try {
alert(message.UserId + " changed from " + message.OldAvailabilityId + " to " + message.NewAvailabilityId);
} catch(ex) {
alert("Exception[On]: " + ex);
}
});
connection.start().done(function() {
try {
proxy.invoke("Connect", tenantId, "SOMEDOMAIN\\someuser");
} catch(ex) {
alert("Exception: " + ex);
}
});
} catch(ex) {
alert("Exception: " + ex);
}
};
</script>
source
share