private void GetNewPictureFromServer(object sender, EventArgs e) { // if there is no user if (CurrentUserPresenceState != gazeStream.IsUserPresent) { CurrentUserPresenceState = gazeStream.IsUserPresent; UserPresenceChanged?.Invoke(gazeStream, CurrentUserPresenceState); } if (!gazeStream.IsUserPresent) { if (EmptyImage != null) { Image = EmptyImage; } // stop the robot // set current state as paSSIVE LastState = MoveGoalRectangles.Passive; CurrentGoalArea = MoveGoalRectangles.Passive; CurrentGazePoint = new Point(0, 0); return; } try { CurrentGazePoint = PointToClient(gazeStream.GazePoint); CurrentGoalRectangle = GazeRectangle.TestGazePoint(CurrentGazePoint); // change state only if gaze point was moved to new control area if (CurrentGoalRectangle != LastState) { if (CurrentGoalRectangle != MoveGoalRectangles.Passive) { LastState = CurrentGoalRectangle; MovementDirectionChanged?.Invoke(this, new MotionDirectionChangedArgs( GazeRectangle.TestGazePoint(CurrentGazePoint), CurrentGazePoint)); //Debug.WriteLine($"MovementDirectionChanged fired at {DateTime.Now.ToLongTimeString()} !!!"); } } DownloadRawPicture(); DecorateRawPicture(); OutputProcessedPicture(); } catch { return; } }
private void Socket_DataReceived(object sender, dynamic data) { var type = data.Value <string>("type"); switch (type)//todo more from https://api.slack.com/rtm { case "message": case "message.channels": case "message.groups": case "message.im": case "message.mpim": MessageReceived?.Invoke(this, new MessageReceivedEventArgs(MakeMessageFromData(data))); break; case "reaction_added": ReactionAdded?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "reaction_removed": ReactionRemoved?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "star_added": StarAdded?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "star_removed": StarRemoved?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "pin_added": PinAdded?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "pin_removed": PinRemoved?.Invoke(this, GetReactionAddedEventArgs(data)); break; case "team_join": UserJoined?.Invoke(this, new UserDataReceivedEventArgs(Team.Users.FirstOrDefault(x => x.Id == data.Value <string>("user")), null, Team)); break; case "user_typing": UserTyping?.Invoke(this, new UserDataReceivedEventArgs(Team.Users.FirstOrDefault(x => x.Id == data.Value <string>("user")), Team.Channels.FirstOrDefault(x => x.Id == data.Value <string>("channel")), Team)); break; case "presence_change": UserPresenceChanged?.Invoke(this, new UserPresenceChangeEventArgs(data.Value <string>("presence"), Team.Users.FirstOrDefault(x => x.Id == data.Value <string>("user")))); break; } }
private async Task OnPublish(MessageWebSocket ws, Packet packet) { var outStream = ws.OutputStream; var publishPacket = (PublishPacket)packet; if (publishPacket.Payload == null) { throw new Exception($"{nameof(SyncClient)}: Publish packet received but payload is null"); } var payload = Encoding.UTF8.GetString(publishPacket.Payload.ToArray()); this.Log($"Publish to {publishPacket.TopicName} with payload: {payload}"); switch (publishPacket.TopicName) { case "/ig_message_sync": var messageSyncPayload = JsonConvert.DeserializeObject <List <MessageSyncEventArgs> >(payload); var latest = messageSyncPayload.Last(); if (latest.SeqId > _seqId && latest.Data.Count > 0) { _seqId = latest.SeqId; if (latest.Data[0].Op != "remove") { _snapshotAt = latest.Data[0].Item.Timestamp; } } MessageReceived?.Invoke(this, messageSyncPayload); break; case "/pubsub": payload = payload.Substring(payload.IndexOf('{')); // pubsub is weird. It has a few non string bytes before the actual data. var pubsub = JsonConvert.DeserializeObject <PubsubEventArgs>(payload); if (pubsub.Data[0].Path.Contains("activity_indicator_id")) { ActivityIndicatorChanged?.Invoke(this, pubsub); } break; case "/ig_realtime_sub": payload = payload.Substring(payload.IndexOf('{')); var container = JsonConvert.DeserializeObject <JObject>(payload); var presenceEvent = container["presence_event"].ToObject <UserPresenceEventArgs>(); UserPresenceChanged?.Invoke(this, presenceEvent); break; } if (publishPacket.QualityOfService == QualityOfService.AtLeastOnce) { await WriteAndFlushPacketAsync(PubAckPacket.InResponseTo(publishPacket), outStream); } }