RKTUXYN/WebHub


Web Hub C# (SignalR Alternative)

License: CC-BY-4.0

Language: C#

Keywords: csharp, hub, javascript, socket, webhub


WebHub C#

DotNet 4.6.1

1) Map the route for the web socket Hub

using Owin;
using Microsoft.Owin;
using System.Collections.Generic;
[assembly: OwinStartup( typeof( SOW.WebApi.View.Startup ) )]

namespace SOW.WebApi.View {
    using SOW.Web.Hub.Core.Extensions;
    using SOW.Web.Hub.Core.Hub;
    public class Startup {
        public void Configuration( IAppBuilder app ) {
            app.MapWebSocketRoute<Manager>( "/hub", new HubConfiguration {
                EnableDetailedErrors = true,
                EnableJavaScriptProxies = true,
                EnableCrossDomain = true,
                CrossDomains = new List<string> { "sockethub.pc", "api.pc", "lms.pc" },
                StandardHubName = true
            } );
        }
    }
}

2) Inherit Hub from SOW.Web.Hub.Core.Hubs

namespace SOW.Web.Hub.View {
    using System;
    using System.Threading.Tasks;
    using SOW.Web.Hub.Core;
    public class Manager : Hubs {
        public override Task OnConnected( ) {
            ( ( dynamic )Clients.AllExcept( base.ConnectionId ) ).onNewUserConnected( base.Hash, base.ConnectionId, base.UserName, DateTime.Now.ToString( ) );
            return base.OnConnected( );
        }
        public override Task OnReconnected( ) {
            ( ( dynamic )Clients.AllExcept( base.ConnectionId ) ).onReconnected( base.Hash, base.ConnectionId, base.UserName, DateTime.Now.ToString( ) );
            return base.OnReconnected( );
        }
        public override Task OnDisconnected( bool stopCalled ) {
            ( ( dynamic )Clients.AllExcept( base.ConnectionId ) ).onDisconnectUser( base.Hash, base.UserName );
            return base.OnDisconnected( stopCalled );
        }
         #region Private Message
        [Authorize( Roles = "Team, Admin" )]
        public Task SendPrivateMessage( string toHash, string message ) {
            return ( Task )( ( dynamic )Clients.ClientHash( toHash ) ).onPrivateMessage( Hash, UserName, message );
        }
        #endregion  Private Message
    }
}

Screenshots

Repository View 

THANKS to Bryce Godfrey (https://github.com/bryceg/) for Owin.WebSocket

Project Statistics

Sourcerank 2
Repository Size 604 KB
Stars 3
Forks 1
Watchers 0
Open issues 0
Dependencies 5
Contributors 1
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

RKTUXYN

Something wrong with this page? Make a suggestion

Last synced: 2019-04-10 23:55:27 UTC

Login to resync this repository