Skip to content

Commit b03a731

Browse files
authored
Merge pull request #13 from neocortex-link/hotfix/web-request
Progress and WebRequest Cancellation
2 parents b88a6bd + 6b67373 commit b03a731

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [0.3.3] - 18 February 2024
7+
## [0.3.4] - 21 February 2025
8+
- Webrequest progress property and cancellation support
9+
10+
## [0.3.3] - 18 February 2025
811
- Various UI Elements fixes
912
- Web Request class decoupling
1013
- Writing Indicator for Chat Panel
1114

12-
## [0.3.2] - 12 February 2024
15+
## [0.3.2] - 12 February 2025
1316
- Right-to-Left language support in Chat Panel
1417

15-
## [0.3.1] - 3 February 2024
18+
## [0.3.1] - 3 February 2025
1619
- Microphone dropdown component
1720
- Component and sample updates
1821

19-
## [0.3.0] - 21 January 2024
22+
## [0.3.0] - 21 January 2025
2023
- WebGL audio support
2124

2225
## [0.2.0] - 6 December 2024

Runtime/API/V1/Services/WebRequest.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System;
2+
using System.Linq;
13
using UnityEngine;
24
using Neocortex.Data;
35
using Newtonsoft.Json;
6+
using System.Threading;
47
using System.Threading.Tasks;
58
using UnityEngine.Networking;
69
using System.Collections.Generic;
@@ -9,7 +12,9 @@ namespace Neocortex.API
912
{
1013
public class WebRequest
1114
{
12-
protected Dictionary<string, string> Headers = new ();
15+
public float Progress { get; private set; }
16+
protected Dictionary<string, string> Headers = new();
17+
protected CancellationTokenSource CtxSource = new();
1318

1419
protected async Task<UnityWebRequest> Send(ApiPayload payload)
1520
{
@@ -39,8 +44,18 @@ protected async Task<UnityWebRequest> Send(ApiPayload payload)
3944

4045
AsyncOperation asyncOperation = webRequest.SendWebRequest();
4146

42-
while (!asyncOperation.isDone) await Task.Yield();
43-
47+
while (!asyncOperation.isDone)
48+
{
49+
if (CtxSource != null && CtxSource.IsCancellationRequested)
50+
{
51+
webRequest.Abort();
52+
}
53+
54+
Progress = asyncOperation.progress;
55+
56+
await Task.Yield();
57+
}
58+
4459
if (webRequest.result == UnityWebRequest.Result.Success)
4560
{
4661
return webRequest;
@@ -50,6 +65,11 @@ protected async Task<UnityWebRequest> Send(ApiPayload payload)
5065
return null;
5166
}
5267

68+
public void Abort()
69+
{
70+
CtxSource.Cancel();
71+
}
72+
5373
protected byte[] GetBytes(object payload)
5474
{
5575
string json = JsonConvert.SerializeObject(payload);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "link.neocortex.sdk",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"displayName": "Neocortex Unity SDK",
55
"description": "Conversational AI for Games Simplified. With Neocortex SDK, create dynamic in-game conversations with AI-powered smart characters using our node-based editor and SDKs.",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)