Application flow:
consider client application is running in separate environment, web Api application is running in separate environment.
here is my hub code for web api project :
public class NotifyHub : Hub
{
public NotifyHub()
{
var request = new PushNotificationRequest
{
FilterProperty = new Common.Filters.FilterProperty { Offset = 0, RecordLimit = 0, OrderBy = "datechecked desc" },
Filters = new List<Common.Filters.FilterObject> { new Common.Filters.FilterObject { LogicOperator = 0, ConditionOperator = 0, Function = 0, FieldName = "", FieldValue = "", FieldType = 0 } }
};
Int16 userId = 3134;
Int16 usertypeid = 1;
INotificationManager inotifity = new NotificationManager();
var taskTimer = Task.Factory.StartNew(async () =>
{
while (true)
{
var NotificationResult = inotifity.PublishResultsAsync(request, userId, usertypeid);
Clients.All.NotificationToClient(NotificationResult);
await Task.Delay(60000);
}
}, TaskCreationOptions.LongRunning
);
}
}
from the above code you can see ,
Int16 userId = 3134;
Actually ,it should be dynamic. In a client application if userid 3134 is logged in, i have to send response data which is belongs to 3134.
response should be respective to the logged in user on client application.
how can i achieve it.
Client application code to connect the Hub:
var app = angular.module('app', []);
app.value('$', $);
app.factory('NotificationService', function ($, $rootScope) {
return {
proxy: null,
initialize: function (NotificationToClientCallback) {
var connection = $.hubConnection("http://localhost:50728/");
this.proxy = connection.createHubProxy('NotifyHub');
this.proxy.on('NotificationToClient', function (message) {
$rootScope.$apply(function () {
NotificationToClientCallback(message);
});
});
connection.start({ jsonp: true })
.done(function () { console.log('Now connected, connection ID=' + connection.id); })
.fail(function () { console.log('Could not connect'); });
},
sendRequest: function (callback) {
this.proxy.invoke('SendNoficationRequest');
}
}
}).controller('NotificationCtrl', ['$scope', 'NotificationService', function NotificationCtrl($scope, NotificationService) {
$scope.text = "";
$scope.SendNoficationRequest = function () {
NotificationService.sendRequest();
}
updateDisplayData = function (text) {
$scope.text = text;
}
NotificationService.initialize(updateDisplayData);
}]);
What I have tried:
I have searched about how to pass parameters for hub, but I cant able to proceed further.