Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.utilities.rest 3.0.1 #78

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
com.utilities.rest 3.0.1
- fix SSE eventData payload serialization
  • Loading branch information
StephenHodgson committed Jun 6, 2024
commit 367dc7f449be13a80f02d43b5fa0dde4f74eac0f
26 changes: 20 additions & 6 deletions Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -1273,17 +1274,30 @@ void SendServerEventCallback(bool isEnd)
return;
}

var eventStringBuilder = new StringBuilder();
eventStringBuilder.Append("{");
eventStringBuilder.Append($"\"{type}\":\"{value}\"");
var eventObject = new Dictionary<string, object>();

try
{
eventObject[type] = JToken.Parse(value);
}
catch
{
eventObject[type] = value;
}

if (!string.IsNullOrWhiteSpace(data))
{
eventStringBuilder.Append($",\"{nameof(data)}\":\"{data}\"");
try
{
eventObject[nameof(data)] = JToken.Parse(data);
}
catch
{
eventObject[nameof(data)] = data;
}
}

eventStringBuilder.Append("}");
serverSentEventCallback.Invoke(eventStringBuilder.ToString());
serverSentEventCallback.Invoke(JsonConvert.SerializeObject(eventObject));
parameters.ServerSentEventCount++;
parameters.ServerSentEvents.Add(new Tuple<string, string, string>(type, value, data));
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities.Rest/Packages/com.utilities.rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Rest",
"description": "This package contains useful RESTful utilities for the Unity Game Engine.",
"keywords": [],
"version": "3.0.0",
"version": "3.0.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",
Expand Down