Skip to content

Commit

Permalink
com.utilities.rest 3.0.1 (#78)
Browse files Browse the repository at this point in the history
- fix SSE eventData payload serialization
  • Loading branch information
StephenHodgson committed Jun 6, 2024
1 parent 747ca01 commit 9ea2af5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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

0 comments on commit 9ea2af5

Please sign in to comment.