Наследование: PrivateChannel
        private Channel CreateChannel(string channelName)
        {
            ChannelTypes type = Channel.GetChannelType(channelName);
            Channel      result;

            switch (type)
            {
            case ChannelTypes.Private:
            case ChannelTypes.PrivateEncrypted:
                AuthEndpointCheck(channelName);
                result = new PrivateChannel(channelName, this);
                break;

            case ChannelTypes.Presence:
                AuthEndpointCheck(channelName);
                result = new PresenceChannel(channelName, this);
                break;

            default:
                result = new Channel(channelName, this);
                break;
            }

            if (!Channels.TryAdd(channelName, result))
            {
                result = Channels[channelName];
            }

            return(result);
        }
Пример #2
0
        private void CreateChannel(ChannelTypes type, string channelName)
        {
            switch (type)
            {
            case ChannelTypes.Public:
                Channels[channelName] = new Channel(channelName, this);
                break;

            case ChannelTypes.Private:
                AuthEndpointCheck();
                Channels[channelName] = new PrivateChannel(channelName, this);
                break;

            case ChannelTypes.Presence:
                AuthEndpointCheck();

                Channel channel;
                if (_presenceChannelFactories.TryGetValue(channelName, out var factory))
                {
                    channel = factory.Item2();
                }
                else
                {
                    channel = new PresenceChannel(channelName, this);
                }

                Channels[channelName] = channel;
                break;
            }
        }
        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();
        }
Пример #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;
        }
Пример #5
0
        private void CreateChannel(ChannelTypes type, string channelName)
        {
            switch (type)
            {
            case ChannelTypes.Public:
                Channels[channelName] = new Channel(channelName, this);
                break;

            case ChannelTypes.Private:
                AuthEndpointCheck();
                Channels[channelName] = new PrivateChannel(channelName, this);
                break;

            case ChannelTypes.Presence:
                AuthEndpointCheck();
                Channels[channelName] = new PresenceChannel(channelName, this);
                break;
            }
        }
Пример #6
0
        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;
        }
        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;
        }