Skip to content

Commit

Permalink
feat: Adds reponse type on message
Browse files Browse the repository at this point in the history
  • Loading branch information
Marconi Gomes committed Sep 13, 2023
1 parent d957df1 commit aa2c829
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions AMRPC WatchDog Desktop/Messenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ internal class Sender : WebSocketBehavior

protected override void OnMessage(MessageEventArgs e)
{
Send(JsonConvert.SerializeObject(Payload));
AnswerAsType(Payload.ResponseTypes.Response);
}

public void OnPayloadChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Send(JsonConvert.SerializeObject(Payload));
AnswerAsType(Payload.ResponseTypes.Event);
}

protected override void OnClose(CloseEventArgs e)
{
Messenger.Reconfigure();
}

private void AnswerAsType(string answerType)
{
var original = Payload.type;
Payload.type = answerType;
Send(JsonConvert.SerializeObject(Payload));
Payload.type = original;
}
}
}
8 changes: 8 additions & 0 deletions AMRPC WatchDog Desktop/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class Payload

public event PropertyChangedEventHandler PropertyChanged;

public static class ResponseTypes
{
public const string Response = "res";
public const string Event = "event";
}

public static class PlayingStatuses
{
public const string Playing = "playing";
Expand All @@ -23,6 +29,7 @@ public static class PlayingStatuses
public string album { get; set; }
public string artist { get; set; }
public string thumbnailPath { get; set; }
public string type { get; set; }

public string playerState
{
Expand Down Expand Up @@ -71,6 +78,7 @@ public void ResetToInitialState()
playerState = PlayingStatuses.NotStarted;
endTime = -1;
duration = -1;
type = ResponseTypes.Event;
}
}
}
2 changes: 1 addition & 1 deletion AMRPC WatchDog Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AMRPC_WatchDog_Desktop
internal static class Program
{

private const string AppVersion = "v0.3.4";
private const string AppVersion = "v0.4.0";

[STAThread]
private static void Main()
Expand Down

0 comments on commit aa2c829

Please sign in to comment.