locked
Connect to external HUB ( another web api project) using angularjs RRS feed

  • Question

  • User1514804031 posted

    Suppose I have my hub 

    [HubName("ticketHub")]
        public class TicketHub : Microsoft.AspNet.SignalR.Hub
        {
    
        }

    My Api controller

            // POST: api/Tickets
            public void Post([FromBody]Ticket ticket)
            {
                _repository.AddTicket(ticket);
    
                var _context = GlobalHost.ConnectionManager.GetHubContext<TicketHub>();
                _context.Clients.All.addNewTicket(ticket);
    
            }

    Script :

    angular.module('realtimeData.data', ['ngResource'])
        .factory('Tickets', ['$resource', function ($resource) {
            'use strict';
    
            return $resource('/api/tickets');
        }])   
        .factory('TicketStream', ['$rootScope', function ($rootScope) {
            'use strict';
    
           
            return {
                on: function (eventName, callback) {
                    var connection = $.hubConnection();
                    var ticketHubProxy = connection.createHubProxy('ticketHub');
                  
                    ticketHubProxy.on(eventName, function () {                  
                        var args = arguments;
                        $rootScope.$apply(function () {
                            callback.apply(ticketHubProxy, args);
                        });
                    });
    
                    connection.start().done(function () { });
    
                }
            };
        }]);

    Now I create client project . 

    How is it possible to connect to the hub and display real time data using angularjs?

    _context.Clients.All.addNewTicket(ticket);

    best regards

    Tuesday, November 17, 2015 6:09 AM

All replies