Наследование: EventEmitter
Пример #1
0
        public Gateway()
        {
            PusherClient.Pusher pusher = new PusherClient.Pusher("7b4abaf489e799ceeceb");

            Channel alarmChannel = pusher.Subscribe("alarms");
            Channel cmdChannel = pusher.Subscribe("commands");

            alarmChannel.Bind("ack", (dynamic data) =>
            {
                try
                {
                    EventAcknowled(data);
                }
                catch (Exception ex)
                {
                    var e = ex;
                }

            });

            cmdChannel.Bind("action", (dynamic data) =>
            {
                try
                {
                    EventCommand(data);
                }
                catch (Exception ex)
                {
                    var e = ex;
                }

            });

            pusher.Connect();
        }
        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();
        }
Пример #3
0
        public Gateway()
        {
            PusherClient.Pusher pusher = new PusherClient.Pusher("7b4abaf489e799ceeceb");

            Channel alarmChannel = pusher.Subscribe("alarms");
            Channel cmdChannel   = pusher.Subscribe("commands");

            alarmChannel.Bind("ack", (dynamic data) =>
            {
                try
                {
                    EventAcknowled(data);
                }
                catch (Exception ex)
                {
                    var e = ex;
                }
            });

            cmdChannel.Bind("action", (dynamic data) =>
            {
                try
                {
                    EventCommand(data);
                }
                catch (Exception ex)
                {
                    var e = ex;
                }
            });

            pusher.Connect();
        }
Пример #4
0
        public PusherLiteMessageBusService(string appKey, string appId,
                                           string appSecret,
                                           string cluster, IAuthorizer authorizer = null)
        {
            _channelManager = new ConcurrentDictionary <MessageChannel, PusherMessageChannelOption>();
            _channelInitializationManager =
                new ConcurrentDictionary <MessageChannel, ReplaySubject <AddedChannelEvent> >();

            _broadcaster = new PusherServer.Pusher(appId, appKey,
                                                   appSecret,
                                                   new PusherOptions
            {
                Cluster   = cluster,
                Encrypted = true
            });

            _recipient = new PusherClient.Pusher(appKey,
                                                 new PusherClient.PusherOptions
            {
                Cluster    = cluster,
                Authorizer = authorizer
            });

            _recipient.Connected    += OnRecipientConnected;
            _recipient.Disconnected += OnRecipientDisconnected;
        }
Пример #5
0
 private static void InitPusher()
 {
     _pusher = new Pusher("7899dd5cb232af88083d", new PusherOptions(){
         Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
Пример #6
0
 private static void InitPusher()
 {
     _pusher = new Pusher("527784eba833ff169524", new PusherOptions() {
         Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
Пример #7
0
 void Start()
 {
     PusherSettings.Verbose     = true;
     PusherSettings.AppKey      = "3a375f8a13577d092e5897e6ce3a02";
     PusherSettings.HttpAuthUrl = "http://test.flave.world:8080";
     pusherClient            = new PusherClient.Pusher();
     pusherClient.Connected += HandleConnected;
     pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
     pusherClient.Connect();
 }
        private void websocket_Closed(object sender, EventArgs e)
        {
            Pusher.Log("Websocket connection has been closed");

            ChangeState(ConnectionState.Disconnected);

            if (_allowReconnect)
            {
                Connect();
            }
        }
Пример #9
0
    // Initialize
    void Start()
    {
        // TODO: Replace these with your app values
        PusherSettings.Verbose     = true;
        PusherSettings.AppKey      = "";
        PusherSettings.HttpAuthUrl = "http://richmond.kingdoms.metamoki.com/bin/pusher-auth.php";

        pusherClient            = new PusherClient.Pusher();
        pusherClient.Connected += HandleConnected;
        pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
        pusherClient.Connect();
    }
Пример #10
0
        public StampSocket(Action<dynamic> msgHandler)
        {
            _msgHandler = msgHandler;

            _pusher = new Pusher(_key);
            _pusher.ConnectionStateChanged += ConnectionStateChanged;
            _pusher.Error += Error;

            _orderBookChannel = _pusher.Subscribe("order_book");
            _orderBookChannel.Subscribed += OrderBookSubscribed;
            _orderBookChannel.Bind("data", _msgHandler);
        }
    // Initialize
    void Start()
    {
        // TODO: Replace these with your app values
        PusherSettings.Verbose = true;
        PusherSettings.AppKey = "";
        PusherSettings.HttpAuthUrl = "http://richmond.kingdoms.metamoki.com/bin/pusher-auth.php";

        pusherClient = new PusherClient.Pusher();
        pusherClient.Connected += HandleConnected;
        pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
        pusherClient.Connect();
    }
Пример #12
0
    // Initialize
    void Start()
    {
        // TODO: Replace these with your app values
        PusherSettings.Verbose     = true;
        PusherSettings.AppKey      = this.pusherAppKey;
        PusherSettings.Host        = "ws-" + this.pusherCluster + ".pusher.com";
        PusherSettings.HttpAuthUrl = this.pusherHttpAuthUrl;

        pusherClient            = new PusherClient.Pusher();
        pusherClient.Connected += HandleConnected;
        pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
        pusherClient.Connect();
    }
Пример #13
0
    public void StartPusher(string url, string channel)
    {
        this.channel = channel;

        PusherSettings.Verbose     = true;
        PusherSettings.AppKey      = "3a375f8a13577d092e5897e6ce3a02";
        PusherSettings.HttpAuthUrl = url;
        pusherClient            = new PusherClient.Pusher();
        pusherClient.Connected += HandleConnected;
        pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
        pusherClient.Connect();

        StartCoroutine(testConnection());
    }
Пример #14
0
        public void Start()
        {
            var pusher = new PusherClient.Pusher("de504dc5763aeef9ff52");

            pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            pusher.Error += _pusher_Error;
            foreach (var pair in _currencyPairs)
            {
                // Setup private channel
                // RegisterTradeChannel(pusher, pair);
                RegisterOrderBookChannel(pusher, pair);
            }
            pusher.Connect();
        }
Пример #15
0
        public void InitializePusherClient(string key, bool useSSL = false, string customHost = null)
        {
            Log($"Initializing PusherClient with key = {key}, useSSL = {useSSL}, customHost = {customHost}");
            pusherClient = new PusherClient.Pusher(key, new PusherOptions()
            {
                Encrypted = useSSL
            });
            if ((customHost != null) && (customHost != ""))
            {
                pusherClient.Host = customHost;
            }

            pusherClient.Error += PusherClientError;
            pusherClient.ConnectionStateChanged += PusherClientConnectionStateChanged;
        }
        public CommandManager()
        {
            if (!LiberatioConfiguration.IsConnectedToInternet() || !LiberatioConfiguration.IsRegistered())
                return;

            try
            {
                string _authParams = string.Format("token={0}", LiberatioConfiguration.GetValue("communicationToken"));
                string _authUrl = "http://www.getliberatio.com/pusher/auth?token=" + LiberatioConfiguration.GetValue("communicationToken"); //HttpUtility.UrlEncode(_authParams);

                EventLog.WriteEntry("LiberatioAgent", "Attempting to connect", EventLogEntryType.Information);
                _pusher = new Pusher("b64eb9cae3befce08a2f", new PusherOptions()
                {
                    Authorizer = new HttpAuthorizer(_authUrl)
                });
                _pusher.Connected += pusher_Connected;
            }
            catch (Exception exception)
            {
                EventLog.WriteEntry("LiberatioAgent", exception.ToString(), EventLogEntryType.Error);
            }
        }
Пример #17
0
 public PresenceChannel(string channelName, Pusher pusher) : base(channelName, pusher)
 {
 }
Пример #18
0
 public Channel(string channelName, Pusher pusher)
 {
     _pusher   = pusher;
     this.Name = channelName;
 }
        private void websocket_MessageReceived(object sender, MessageEventArgs e)
        {
            Pusher.Log("Websocket message received: " + e.Data);

            if (e.IsPing)
            {
                Send("{\"event\": \"pusher:pong\"}");
                return;
            }

            PusherEventData message = PusherEventData.FromJson(e.Data);

            _pusher.EmitEvent(message.eventName, message.data);

            if (message.eventName.StartsWith("pusher"))
            {
                // Assume Pusher event
                switch (message.eventName)
                {
                case Constants.ERROR:
                    ParseError(message.data);
                    break;

                case Constants.CONNECTION_ESTABLISHED:
                    ParseConnectionEstablished(message.data);
                    break;

                case Constants.CHANNEL_SUBSCRIPTION_SUCCEEDED:

                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];
                        channel.SubscriptionSucceeded(message.data);
                    }

                    break;

                case Constants.CHANNEL_SUBSCRIPTION_ERROR:

                    throw new PusherException("Error received on channel subscriptions: " + e.Data, ErrorCodes.SubscriptionError);

                case Constants.CHANNEL_MEMBER_ADDED:

                    // Assume channel event
                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];

                        if (channel is PresenceChannel)
                        {
                            ((PresenceChannel)channel).AddMember(message.data);
                            break;
                        }
                    }

                    Pusher.LogWarning("Received a presence event on channel '" + message.channel + "', however there is no presence channel which matches.");
                    break;

                case Constants.CHANNEL_MEMBER_REMOVED:

                    // Assume channel event
                    if (_pusher.Channels.ContainsKey(message.channel))
                    {
                        var channel = _pusher.Channels[message.channel];

                        if (channel is PresenceChannel)
                        {
                            ((PresenceChannel)channel).RemoveMember(message.data);
                            break;
                        }
                    }

                    Pusher.LogWarning("Received a presence event on channel '" + message.channel + "', however there is no presence channel which matches.");
                    break;
                }
            }
            else
            {
                // Assume channel event
                if (_pusher.Channels.ContainsKey(message.channel))
                {
                    _pusher.Channels[message.channel].EmitEvent(message.eventName, message.data);
                }
            }
        }
 internal void Send(string message)
 {
     Pusher.Log("Sending: " + message);
     _websocket.SendAsync(message, delegate(bool obj) { });
 }
 private void websocket_Error(object sender, WebSocketSharp.ErrorEventArgs e)
 {
     // TODO: What happens here? Do I need to re-connect, or do I just log the issue?
     Pusher.LogWarning("Websocket error: " + e.Message);
 }
 public Connection(Pusher pusher, string url, IProxyConnector proxy = null)
 {
     this._url = url;
     this._pusher = pusher;
     this._proxy = proxy;
 }
 private void websocket_Opened(object sender, EventArgs e)
 {
     Pusher.Log("Websocket opened OK.");
 }
 public Channel(string channelName, Pusher pusher)
 {
     _pusher = pusher;
     this.Name = channelName;
 }
Пример #25
0
        /// <summary>
        /// Connects to Pusher and subscribes to the user's private channel.
        /// </summary>
        /// <param name="user"></param>
        private void SetupPusher(VpdbUserFull user)
        {
            // initialize pusher
            if (_pusher == null) {
                _pusher = new Pusher(user.ChannelConfig.ApiKey, new PusherOptions() {
                    Encrypted = true,
                    Authorizer = new PusherAuthorizer(this, _crashManager, _logger)
                });
            }

            var isNewConnection = _connectedApiEndpoint == null;
            var isSameConnection = !isNewConnection && _connectedApiEndpoint.Equals(_settingsManager.Settings.Endpoint);
            var isDifferentConnection = !isNewConnection && !isSameConnection;

            if (isNewConnection) {
                _logger.Info("Setting up Pusher...");

                _pusher.ConnectionStateChanged += PusherConnectionStateChanged;
                _pusher.Error += PusherError;

                _pusher.Connect();
            }

            if (isDifferentConnection) {
                _logger.Info("Unsubscribing from previous channel.");
                _userChannel.Unsubscribe();
            }

            if (isNewConnection || isDifferentConnection) {
                _logger.Info("Subscribing to user channel.");
                _userChannel = _pusher.Subscribe("private-user-" + user.Id);
                _userChannel.Subscribed += PusherSubscribed;
            }

            _connectedApiEndpoint = _settingsManager.Settings.Endpoint;
        }
 public Connection(Pusher pusher, string url)
 {
     this._url = url;
     this._pusher = pusher;
 }
 private void InitPusher()
 {
     _pusher = new Pusher(PUSHER_APP_KEY, new PusherOptions()
     {
         Authorizer = new HttpAuthorizer(PUSHER_AUTH_HOST + "/auth/" + HttpUtility.UrlEncode(_name))
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
 public PrivateChannel(string channelName, Pusher pusher) : base(channelName, pusher) { }
Пример #29
0
        void HandleSteamMessage (CallbackMsg msg)
        {
            log.Debug(msg.ToString());

            #region Login
            msg.Handle<SteamClient.ConnectedCallback> (callback =>
            {
                log.Debug ("Connection Callback: " + callback.Result);

                if (callback.Result == EResult.OK)
                {
                    UserLogOn();
                }
                else
                {
                    log.Error ("Failed to connect to Steam Community, trying again...");
                    SteamClient.Connect ();
                }

            });

            msg.Handle<SteamUser.LoggedOnCallback> (callback =>
            {
                log.Debug ("Logged On Callback: " + callback.Result);

                if (callback.Result == EResult.OK)
                {
                    MyLoginKey = callback.WebAPIUserNonce;
                }
                else
                {
                    log.Error ("Login Error: " + callback.Result);
                }

                if (callback.Result == EResult.AccountLogonDenied)
                {
                    log.Interface ("This account is SteamGuard enabled. Enter the code via the `auth' command.");

                    // try to get the steamguard auth code from the event callback
                    var eva = new SteamGuardRequiredEventArgs();
                    FireOnSteamGuardRequired(eva);
                    if (!String.IsNullOrEmpty(eva.SteamGuard))
                        logOnDetails.AuthCode = eva.SteamGuard;
                    else
                        logOnDetails.AuthCode = Console.ReadLine();
                }

                if (callback.Result == EResult.InvalidLoginAuthCode)
                {
                    log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command.");
                    logOnDetails.AuthCode = Console.ReadLine();
                }
            });

            msg.Handle<SteamUser.LoginKeyCallback> (callback =>
            {
                while (true)
                {
                    bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token, MyLoginKey);

                    if (authd)
                    {
                        botCookies = new CookieContainer();
                        botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("steamLogin={0}", token));
                        botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("sessionid={0};", sessionId));
                        GenericInventory.SetCookie(botCookies, SteamUser.SteamID);
                        log.Success ("User Authenticated!");
                        BotSteamIds.Add(SteamUser.SteamID);

                        tradeManager = new TradeManager(apiKey, sessionId, token);
                        tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval);
                        tradeManager.OnTimeout += OnTradeTimeout;
                        break;
                    }
                    else
                    {
                        log.Warn ("Authentication failed, retrying in 2s...");
                        Thread.Sleep (2000);
                    }
                }

                SteamFriends.SetPersonaName (DisplayNamePrefix+DisplayName);
                SteamFriends.SetPersonaState (EPersonaState.Online);

                log.Success ("Steam Bot Logged In Completely!");

                IsLoggedIn = true;

                botCookies = new CookieContainer();                
                botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("steamLogin={0}", token));
                botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("sessionid={0}", sessionId));
                GenericInventory.SetCookie(botCookies, SteamUser.SteamID);

                Pusher = new Pusher("51a9410427d703c5a743");
                Pusher.Connected += Pusher_Connected;
                Pusher.Connect();

                GetUserHandler(SteamClient.SteamID).OnLoginCompleted();
            });

            // handle a special JobCallback differently than the others
            if (msg.IsType<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>())
            {
                msg.Handle<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>(
                    jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID)
                );
            }
            #endregion

            #region Friends
            msg.Handle<SteamFriends.FriendsListCallback>(callback =>
            {
                foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList)
                {
                    if (friend.SteamID.AccountType == EAccountType.Clan)
                    {
                        if (!groups.Contains(friend.SteamID))
                        {
                            groups.Add(friend.SteamID);
                            if (friend.Relationship == EFriendRelationship.RequestRecipient)
                            {
                                if (GetUserHandler(friend.SteamID).OnGroupAdd())
                                {
                                    AcceptGroupInvite(friend.SteamID);
                                }
                                else
                                {
                                    DeclineGroupInvite(friend.SteamID);
                                }
                            }
                        }
                        else
                        {
                            if (friend.Relationship == EFriendRelationship.None)
                            {
                                groups.Remove(friend.SteamID);
                            }
                        }
                    }
                    else if (friend.SteamID.AccountType != EAccountType.Clan)
                    {
                    if (!friends.Contains(friend.SteamID))
                    {
                        friends.Add(friend.SteamID);
                        if (friend.Relationship == EFriendRelationship.RequestRecipient &&
                            GetUserHandler(friend.SteamID).OnFriendAdd())
                        {
                            SteamFriends.AddFriend(friend.SteamID);
                        }
                    }
                    else
                    {
                        if (friend.Relationship == EFriendRelationship.None)
                        {
                            friends.Remove(friend.SteamID);
                            GetUserHandler(friend.SteamID).OnFriendRemove();
                        }
                    }
                }
                }
            });


            msg.Handle<SteamFriends.FriendMsgCallback> (callback =>
            {
                EChatEntryType type = callback.EntryType;

                if (callback.EntryType == EChatEntryType.ChatMsg)
                {
                    log.Info (String.Format ("Chat Message from {0}: {1}",
                                         SteamFriends.GetFriendPersonaName (callback.Sender),
                                         callback.Message
                                         ));
                    GetUserHandler(callback.Sender).OnMessage(callback.Message, type);
                }
            });
            #endregion

            #region Group Chat
            msg.Handle<SteamFriends.ChatMsgCallback>(callback =>
            {
                GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message);
            });
            #endregion

            #region Trading
            msg.Handle<SteamTrading.SessionStartCallback> (callback =>
            {
                bool started = HandleTradeSessionStart (callback.OtherClient);

                if (!started)
                    log.Error ("Could not start the trade session.");
                else
                    log.Debug ("SteamTrading.SessionStartCallback handled successfully. Trade Opened.");
            });

            msg.Handle<SteamTrading.TradeProposedCallback> (callback =>
            {
                try
                {
                    tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient);
                }
                catch (WebException we)
                {                 
                    SteamFriends.SendChatMessage(callback.OtherClient,
                             EChatEntryType.ChatMsg,
                             "Trade error: " + we.Message);

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }
                catch (Exception)
                {
                    SteamFriends.SendChatMessage(callback.OtherClient,
                             EChatEntryType.ChatMsg,
                             "Trade declined. Could not correctly fetch your backpack.");

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }

                if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ())
                    SteamTrade.RespondToTrade (callback.TradeID, true);
                else
                    SteamTrade.RespondToTrade (callback.TradeID, false);
            });

            msg.Handle<SteamTrading.TradeResultCallback> (callback =>
            {
                if (callback.Response == EEconTradeResponse.Accepted)
                {
                    log.Debug ("Trade Status: " + callback.Response);
                    log.Info ("Trade Accepted!");
                    GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString());
                }
                else
                {
                    log.Warn ("Trade failed: " + callback.Response);
                    CloseTrade ();
                    GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString());
                }

            });
            #endregion

            #region Disconnect
            msg.Handle<SteamUser.LoggedOffCallback> (callback =>
            {
                IsLoggedIn = false;
                log.Warn ("Logged Off: " + callback.Result);
            });

            msg.Handle<SteamClient.DisconnectedCallback> (callback =>
            {
                IsLoggedIn = false;
                CloseTrade ();
                log.Warn ("Disconnected from Steam Network!");
                SteamClient.Connect ();
            });
            #endregion
        }
 public PresenceChannel(string channelName, Pusher pusher)
     : base(channelName, pusher)
 {
 }
Пример #31
0
 public Connection(Pusher pusher, string url)
 {
     this._url    = url;
     this._pusher = pusher;
 }
Пример #32
0
 public PrivateChannel(string channelName, Pusher pusher) : base(channelName, pusher)
 {
 }
 private void InitPusher()
 {
     var proxyEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.87"), 8888);
     _pusher = new Pusher(PUSHER_APP_KEY, new PusherOptions()
     {
         Authorizer = new HttpAuthorizer(PUSHER_AUTH_HOST + "/auth/" + HttpUtility.UrlEncode(_name), proxyEndPoint),
         ProxyEndPoint = proxyEndPoint,
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }