Inheritance: EventEmitter
        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();
        }
        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;
        }
Esempio n. 3
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);
        }
        public void Subscribe(string channel, string eventName)
        {
            CheckInitialization("Subscribe");

            PusherClient.Channel chatChannel = pusherClient.Subscribe(channel);
            chatChannel.Bind(eventName, (dynamic data) =>
            {
                var message = Convert.ToString(data);
                Log($"[{channel}][{eventName}]: {message}");

                if (onSubscribedEventMessage != null)
                {
                    onSubscribedEventMessage(channel, eventName, message);
                }
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Executed when the pusher connection with the private user channel
        /// is established and we can subscribe to messages.
        /// </summary>
        /// <param name="userChannel">User channel object</param>
        private void OnChannelJoined(Channel userChannel)
        {
            if (userChannel == null) {
                return;
            }

            // subscribe through a subject so we can do more fun stuff with it
            var star = new Subject<JObject>();
            var unstar = new Subject<JObject>();
            var newReleaseVersion = new Subject<JObject>();
            userChannel.Bind("star", data => { star.OnNext(data as JObject); });
            userChannel.Bind("unstar", data => { unstar.OnNext(data as JObject); });
            userChannel.Bind("new_release_version", data => { newReleaseVersion.OnNext(data as JObject); });

            // star
            star.ObserveOn(RxApp.MainThreadScheduler)
                .Select(msg => StarEvent.GetInstance(msg, true))
                .Where(msg => msg.Type == "release")
                .Subscribe((Subject<StarEvent>) WhenReleaseStarred);

            // unstar
            unstar.ObserveOn(RxApp.MainThreadScheduler)
                .Select(msg => StarEvent.GetInstance(msg, false))
                .Where(msg => msg.Type == "release")
                .Subscribe((Subject<StarEvent>) WhenReleaseStarred);

            // new release version
            newReleaseVersion.ObserveOn(RxApp.MainThreadScheduler)
                .Select(NewVersionEvent.GetInstance)
                .Subscribe((Subject<NewVersionEvent>)WhenReleaseUpdated);
        }
Esempio n. 6
0
 void HandleConnected(object sender)
 {
     Debug.Log("Pusher client connected, now subscribing to private channel");
     pusherChannel = pusherClient.Subscribe("core_items");
     pusherChannel.BindAll(HandleChannelEvent);
 }
Esempio n. 7
0
 void Pusher_Connected(object sender)
 {
     GetUserHandler(SteamClient.SteamID).OnPusherConnected();
     Channel = Pusher.Subscribe("bots");
     Channel.Subscribed += Channel_Subscribed;
 }
        private Channel SubscribeToChannel(ChannelTypes type, string channelName)
        {
            Channel channel = null;
            switch (type)
            {
                case ChannelTypes.Public:
                    channel = new Channel(channelName, this);
                    Channels.Add(channelName, channel);
                    break;
                case ChannelTypes.Private:
                    AuthEndpointCheck();
                    channel = new PrivateChannel(channelName, this);
                    Channels.Add(channelName, channel);
                    break;
                case ChannelTypes.Presence:
                    AuthEndpointCheck();
                    channel = new PresenceChannel(channelName, this);
                    Channels.Add(channelName, channel);
                    break;
            }

            if (type == ChannelTypes.Presence || type == ChannelTypes.Private)
            {
                Task.Factory.StartNew(() => // TODO: if failed, communicate it out
                {
                    try
                    {
                        string jsonAuth = _options.Authorizer.Authorize(channelName, _connection.SocketID);

                        var template = new { auth = String.Empty, channel_data = String.Empty };
                        var message = JsonConvert.DeserializeAnonymousType(jsonAuth, template);

                        _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName, auth = message.auth, channel_data = message.channel_data } }));
                    }
                    catch(Exception ex)
                    {
                        channel.SubscriptionFailed(ErrorCodes.ConnectionFailed, ex.Message);
                    }
                });
            }
            else
            {
                try
                {
                    // No need for auth details. Just send subscribe event
                    _connection.Send(JsonConvert.SerializeObject(new { @event = Constants.CHANNEL_SUBSCRIBE, data = new { channel = channelName } }));
                }
                catch (Exception ex)
                {
                    channel.SubscriptionFailed(ErrorCodes.ConnectionFailed, ex.Message);
                }
            }

            return Channels[channelName];
        }
        private void pusher_Connected(object sender)
        {
            RunOnUiThread(() =>
            {
                _buttonStart.Text = GetString(Resource.String.ButtonDisconnect);
                _buttonStart.Enabled = true;
            });

            // 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;
        }
        /// <summary>
        /// Subscribes to a private Pusher channel that enables remote
        /// desktop communication to this computer on the Website.
        /// </summary>
        /// <param name="sender"></param>
        private void pusher_Connected(object sender)
        {
            string uuid = LiberatioConfiguration.GetValue("uuid");

            try
            {
                // Setup private commands channel if we are told to do so.
                if (LiberatioConfiguration.UseRemoteCommands())
                {
                    EventLog.WriteEntry("LiberatioAgent", "Attempting to subscribe to private channel", EventLogEntryType.Information);
                    _cmdChannel = _pusher.Subscribe(string.Format("private-cmd_{0}", uuid));
                    _cmdChannel.Subscribed += _cmdChannel_Subscribed;
                }

                // Setup presence channel always.
                EventLog.WriteEntry("LiberatioAgent", "Attempting to subscribe to presence channel", EventLogEntryType.Information);
                _presenceChannel = (PresenceChannel)_pusher.Subscribe(string.Format("presence-cmd_{0}", uuid));
                _presenceChannel.Subscribed += _presenceChannel_Subscribed;
            }
            catch (Exception exception)
            {
                EventLog.WriteEntry("LiberatioAgent", "Failed to subscribe", EventLogEntryType.Error);
                EventLog.WriteEntry("LiberatioAgent", exception.ToString(), EventLogEntryType.Error);
            }
        }
        private void pusher_Connected(object sender)
        {
            InvokeOnMainThread(() =>
            {
                this.ButtonStart.SetTitle("Disconnect :(", UIControlState.Normal);
                this.ButtonStart.Enabled = true;
            });

            // 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;
        }
Esempio n. 12
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;
        }
        private void pusher_Connected(object sender)
        {
            RunOnUiThread(() =>
            {
                this.ButtonStart.Content = GetString("StringButtonDisconnect");
                this.ButtonStart.IsEnabled = true;
            });

            // 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;
        }
 void HandleConnected(object sender)
 {
     Debug.Log ( "Pusher client connected, now subscribing to private channel" );
     pusherChannel = pusherClient.Subscribe( "private-testchannel" );
     pusherChannel.BindAll( HandleChannelEvent );
 }