Example #1
0
        // Pusher Initiation / Connection
        private static async Task InitPusher()
        {
            _pusher = new Pusher(Config.AppKey, new PusherOptions
            {
                Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
            });
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;

            // Setup private channel
            _chatChannel             = _pusher.SubscribeAsync("private-channel").Result;
            _chatChannel.Subscribed += ChatChannel_Subscribed;

            // Inline binding!
            _chatChannel.Bind("client-my-event", (dynamic data) =>
            {
                Console.WriteLine("[" + data.name + "] " + data.message);
            });

            // Setup presence channel
            _presenceChannel                = (PresenceChannel)_pusher.SubscribeAsync("presence-channel").Result;
            _presenceChannel.Subscribed    += PresenceChannel_Subscribed;
            _presenceChannel.MemberAdded   += PresenceChannel_MemberAdded;
            _presenceChannel.MemberRemoved += PresenceChannel_MemberRemoved;

            await _pusher.ConnectAsync();
        }
        private static void InitPusher()
        {
            _pusher = new Pusher("7899dd5cb232af88083d", new PusherOptions()
            {
                Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
            });
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;

            // Setup private channel
            _chatChannel             = _pusher.Subscribe("private-channel");
            _chatChannel.Subscribed += _chatChannel_Subscribed;

            // Inline binding!
            _chatChannel.Bind("client-my-event", (dynamic data) =>
            {
                Console.WriteLine("[" + data.name + "] " + data.message);
            });

            // Setup presence channel
            _presenceChannel                = (PresenceChannel)_pusher.Subscribe("presence-channel");
            _presenceChannel.Subscribed    += _presenceChannel_Subscribed;
            _presenceChannel.MemberAdded   += _presenceChannel_MemberAdded;
            _presenceChannel.MemberRemoved += _presenceChannel_MemberRemoved;

            _pusher.Connect();
        }
Example #3
0
 public KeepAliveService(PresenceChannel channel, IUserInfo user, TimeSpan keepAliveSyncTime)
 {
     this.channel           = channel;
     this.keepAliveSyncTime = keepAliveSyncTime;
     keepAliveMessage       = Message.FromSender <KeepAliveMessage>(user);
     aliveUsers             = new Dictionary <IUserInfo, DateTime>();
 }
Example #4
0
        static void pusher_Connected(object sender)
        {
            // Setup private channel
            _chatChannel             = _pusher.Subscribe("private-channel");
            _chatChannel.Subscribed += _chatChannel_Subscribed;

            // Setup presence channel
            _presenceChannel                = (PresenceChannel)_pusher.Subscribe("presence-channel");
            _presenceChannel.Subscribed    += _presenceChannel_Subscribed;
            _presenceChannel.MemberAdded   += _presenceChannel_MemberAdded;
            _presenceChannel.MemberRemoved += _presenceChannel_MemberRemoved;
        }
Example #5
0
        public void Start()
        {
            bridgeHost = new BridgeHost(this, bridgeEndPointExternal, bridgeEndPointInternal);
            bridgeHost.PresenceMessageForwarded += bridgeHost_PresenceMessageForwarded;
            bridgeHost.ChatMessageReceived      += bridgeHost_ChatMessageReceived;
            bridgeHost.Start();

            routeTable       = new RouteTable();
            messageInspector = new PresenceMessageInspector(routeTable, presenceServiceEndPoint, bridgeEndPointInternal);

            presenceChannel = new PresenceChannel(multicastEndPoint, multicastReceiveEndPoint, presenceServiceEndPoint);
            presenceChannel.Start();
            presenceChannel.MessageReceived += presenceChannel_MessageReceived;
        }
Example #6
0
        public PresenceService(PresenceServiceOptions options)
        {
            thisUser = new UserInfo()
            {
                ID                = options.ChatEndPoint.ClientID,
                ChatEndPoint      = options.ChatEndPoint.Address,
                KeepAliveSyncTime = options.KeepAliveTime,
                PresenceEndPoint  = options.PresenceServiceEndPoint
            };

            channel = new PresenceChannel(options.MulticastEndPoint, options.MulticastReceiveEndPoint, options.PresenceServiceEndPoint);

            this.discovery            = new UserDiscovery(channel);
            discovery.UserOnline     += discovery_UserOnline;
            discovery.UserOffline    += discovery_UserOffline;
            discovery.UserUpdated    += discovery_UserUpdated;
            discovery.UserDiscovered += discovery_UserDiscovered;

            this.keepAlive                 = new KeepAliveService(channel, thisUser, options.KeepAliveTime);
            this.keepAlive.UserLost       += keepAlive_UserLost;
            this.keepAlive.UserLosing     += keepAlive_UserLosing;
            this.keepAlive.UserDiscovered += keepAlive_UserDiscovered;
        }
Example #7
0
 public UserDiscovery(PresenceChannel channel)
 {
     this.channel     = channel;
     this.onlineUsers = new ConcurrentDictionary <string, IUserInfo>();
 }