//private readonly Subject<ResponseMessage> _messageReceivedSubject = new Subject<ResponseMessage>();
        //private readonly Subject<ReconnectionType> _reconnectionSubject = new Subject<ReconnectionType>();
        //private readonly Subject<DisconnectionType> _disconnectedSubject = new Subject<DisconnectionType>();

        /// <summary>
        /// A simple websocket client with built-in reconnection and error handling
        /// </summary>
        /// <param name="url">Target websocket url (wss://)</param>
        /// <param name="clientFactory">Optional factory for native ClientWebSocket, use it whenever you need some custom features (proxy, settings, etc)</param>
        public WebsocketClient(Uri url, Func <ClientWebSocket> clientFactory = null)
            : this(url, GetClientFactory(clientFactory))
        {
            _messageReceivedSubject = new ObservableEvent <ResponseMessage>();
            _reconnectionSubject    = new ObservableEvent <ReconnectionType>();
            _disconnectedSubject    = new ObservableEvent <DisconnectionType>();
        }
Example #2
0
 public void OnNotify(ObservableEvent eventType, EventSubject subject = null)
 {
     if (eventType == ObservableEvent.PLAYER_SPAWN)
     {
         RespawnNavAgent();
     }
 }
        /// <summary>
        /// Initializes a new <see cref="AnalogSensor"/> instance.
        /// </summary>
        public AnalogSensor()
        {
            // Create updater
            updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100));
            updater.SetUpdateAction(Update);
            updater.Starting += (s, e) => EnsureInitialized();

            // Create events
            readingChangedEvent = new ObservableEvent<IAnalogSensor, AnalogSensorReadingChangedEventArgs>(updater);
        }
Example #4
0
        /// <summary>
        /// Initializes a new <see cref="SS944"/> instance.
        /// </summary>
        public SS944()
        {
            // Create updater
            updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100));
            updater.SetUpdateAction(Update);
            updater.Starting += (s, e) => EnsureInitialized();

            // Create events
            readingChangedEvent = new ObservableEvent<IThumbstick, ThumbstickReadingChangedEventArgs>(updater);
        }
Example #5
0
        /// <summary>
        /// Initializes a new <see cref="SS944"/> instance.
        /// </summary>
        public SS944()
        {
            // Create updater
            updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100));
            updater.SetUpdateAction(Update);
            updater.Starting += (s, e) => EnsureInitialized();

            // Create events
            readingChangedEvent = new ObservableEvent <IThumbstick, ThumbstickReadingChangedEventArgs>(updater);
        }
Example #6
0
        /// <summary>
        /// Initializes a new <see cref="AnalogSensor"/> instance.
        /// </summary>
        public AnalogSensor()
        {
            // Create updater
            updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100));
            updater.SetUpdateAction(() => Update(true));
            updater.Starting += (s, e) => EnsureInitialized();

            // Create events
            readingChangedEvent = new ObservableEvent <IAnalogSensor, AnalogSensorReadingChangedEventArgs>(updater);
        }
Example #7
0
        /// <summary>
        /// Initializes a new <see cref="PushButton"/> instance.
        /// </summary>
        public RotaryEncoder()
        {
            // Create helper
            buttonHelper = new PushButtonHelper(this);

            // Lower debounce timeout
            buttonHelper.DebounceTimeout = 10;

            // Create events
            rotatedEvent = new ObservableEvent<IRotaryEncoder, RotaryEncoderRotatedEventArgs>(firstAdded: EnsureInitialized);
        }
Example #8
0
        /// <summary>
        /// Initializes a new <see cref="PushButton"/> instance.
        /// </summary>
        public RotaryEncoder()
        {
            // Create helper
            buttonHelper = new PushButtonHelper(this);

            // Lower debounce timeout
            buttonHelper.DebounceTimeout = 10;

            // Create events
            rotatedEvent = new ObservableEvent <IRotaryEncoder, RotaryEncoderRotatedEventArgs>(firstAdded: EnsureInitialized);
        }
        /// <summary>
        /// Initializes a new <see cref="PushButtonHelper"/> instance.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="IPushButton"/> instance that owns this helper.
        /// </param>
        public PushButtonHelper(IPushButton owner)
        {
            // Validate
            if (owner == null) throw new ArgumentNullException("owner");

            // Store
            this.owner = owner;

            // Create events
            clickEvent = new ObservableEvent<IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
            pressedEvent = new ObservableEvent<IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
            releasedEvent = new ObservableEvent<IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
        }
Example #10
0
        /// <summary>
        /// Initializes a new <see cref="PushButtonHelper"/> instance.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="IPushButton"/> instance that owns this helper.
        /// </param>
        public PushButtonHelper(IPushButton owner)
        {
            // Validate
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            // Store
            this.owner = owner;

            // Create events
            clickEvent    = new ObservableEvent <IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
            pressedEvent  = new ObservableEvent <IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
            releasedEvent = new ObservableEvent <IPushButton, EmptyEventArgs>(firstAdded: EnsureInitialized);
        }
Example #11
0
 public void OnNotify(ObservableEvent eventType, EventSubject subject = null)
 {
     if (eventType == ObservableEvent.PLAYER_SPAWN)
     {
         if (HasFlag())
         {
             DropFlag();
         }
         else if (isCapturingFlag)
         {
             StopFlagCapture();
         }
         else if (isReturningFlag)
         {
             StopFlagReturn();
         }
     }
 }
Example #12
0
 public void OnNotify(ObservableEvent eventType, EventSubject subject = null)
 {
     switch (eventType)
     {
         case ObservableEvent.POINT_SCORED:
             block.Play();
             break;
         case ObservableEvent.PLAYER_DAMAGED:
             damage.Play();
             break;
         case ObservableEvent.FLAG_PICKEDUP:
             columnBumper.Play();
             break;
         case ObservableEvent.PLAYER_ELIMINATED:
             elimination.Play();
             break;
         case ObservableEvent.BUMPER_COLLISION:
             bumper.Play();
             break;
     }
 }
Example #13
0
 /// <summary>
 /// Initializes a new <see cref="Switch"/> instance.
 /// </summary>
 public Switch()
 {
     // Create events
     switchedEvent = new ObservableEvent<ISwitch, bool>(firstAdded: EnsureInitialized);
 }
Example #14
0
 /// <summary>
 /// Initializes a new <see cref="Switch"/> instance.
 /// </summary>
 public Switch()
 {
     // Create events
     switchedEvent = new ObservableEvent <ISwitch, bool>(firstAdded: EnsureInitialized);
 }
Example #15
0
 /// <summary>
 /// Initializes a new <see cref="MCP970X"/> instance.
 /// </summary>
 public MCP970X()
 {
     // Create events
     readingChangedEvent = new ObservableEvent <ITemperatureSensor, ITemperatureReading>(firstAdded: OnFirstAdded, lastRemoved: OnLastRemoved);
 }
Example #16
0
 protected void Notify(ObservableEvent eventType)
 {
     observers.ForEach(observer => observer.OnNotify(eventType, this));
 }