Exemplo n.º 1
0
        public VideoController(
            IHostingEnvironment hostingEnvironment,
            IVideoService service,
            IHubContext <VideoHub, IVideoHub> videoHub,
            IHubContext <ManagementHub, IManagementHub> managementHub)
        {
            _videoPath     = $"{hostingEnvironment.WebRootPath}\\Videos";
            _service       = service;
            _videoHub      = videoHub;
            _managementHub = managementHub;
            var categories       = CategoryInfos();
            var clientIdentities = GetClientIdentities1();

            _service.Init(_videoPath, categories, clientIdentities);
            ManagementHub.AddNotifyEvent(
                (sender, args) =>
            {
                _managementHub.Clients.All.getOnlineUsers(Utility.VideoUtility.GetClientCount());
            }
                );
            VideoHub.AddConnectedEvent(
                (senger, args) =>
            {
                _service.AddClientIdentity(
                    args.Id, args.Ip, true);
                _managementHub.Clients.All.getOnlineUsers(Utility.VideoUtility.GetClientCount());
            });

            VideoHub.AddDisconnectedEvent((senger, args) =>
            {
                _service.AddClientIdentity(
                    args.Id, args.Ip, false);
                _managementHub.Clients.All.getOnlineUsers(Utility.VideoUtility.GetClientCount());
            });
        }