Skip to content
Snippets Groups Projects
Commit 9d13fce0 authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Implementation of the subscription for websockets.

Bug fix for the issue with the HTTP header (token).
parent b1996331
No related branches found
No related tags found
1 merge request!2Finalisation of REST and websocket client functions and subscription methodics.
Showing
with 755 additions and 265 deletions
fileFormatVersion: 2
guid: 953b8657509a139449794a24f2147730
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4af05175caa96bb43844e080f1d8701b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File added
fileFormatVersion: 2
guid: 1494d109bc218c346ab7622ed734ea86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9d5dbed810c34cc4db0fe224cda88d0b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bddbf4bf9ff11da4885638979b82efb2
labels:
- NuGetForUnity
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>websocket-sharp-latest</id>
<version>1.0.2</version>
<authors>websocket-sharp-latest</authors>
<license type="expression">MIT</license>
<licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
<icon>websocket-sharp_icon.png</icon>
<description>Package Description</description>
<releaseNotes>https://github.com/garbles-labs/websocket-sharp/releases</releaseNotes>
<repository type="git" />
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
\ No newline at end of file
fileFormatVersion: 2
guid: a9d61c123a66f5b4a8d236c2972a3609
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Runtime/Packages/websocket-sharp-latest.1.0.2/websocket-sharp_icon.png

911 B

fileFormatVersion: 2
guid: b3235afb951bf0a4f9e21db48a0937f6
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
......@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: June 2024
// Last change: September 2024
//
// Depends on UniTask to support cancellation token and GetAwaiter: https://github.com/Cysharp/UniTask
......@@ -101,6 +101,21 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis
private readonly HttpClient _httpClient = new HttpClient();
private void AppendARFHeaders(HttpRequestMessage message, UnityWebRequest webRequest)
{
// Add some ARF headers
foreach (var item in message.Headers)
{
try
{
List<string> li = item.Value as List<string>;
if (item.Key == "token") webRequest.SetRequestHeader(item.Key, li[0].ToString()); // add it
if (item.Key == "sessionID") webRequest.SetRequestHeader(item.Key, li[0].ToString()); // add it
}
catch { } // ignore it
}
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage message, HttpCompletionOption option, CancellationToken token)
{
var content = await (message.Content?.ReadAsStringAsync() ?? Task.FromResult(""));
......@@ -108,6 +123,9 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis
AppendHeaders(webRequest);
// Add the ARF API headers
AppendARFHeaders(message, webRequest);
Debug.Log("[HTTP] Request " + webRequest.uri.ToString());
try
{
......
......@@ -183,9 +183,9 @@ public partial class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
}
PoseEstimationResult[] resul = new PoseEstimationResult[uuids.Length];
poses = new ETSI.ARF.OpenAPI.WorldAnalysis.Pose[uuids.Length];
List<Anonymous> uuidList = new List<Anonymous>();
Response poses_ = apiClient.GetPoses(token, sessionID, uuidList.ToArray());
List<ETSI.ARF.OpenAPI.WorldAnalysis.Pose> posesList = poses_.Poses as List<ETSI.ARF.OpenAPI.WorldAnalysis.Pose>;
List<UuidAndMode> uuidList = new List<UuidAndMode>();
Poses poses_ = apiClient.GetPoses(token, sessionID, uuidList.ToArray());
List<ETSI.ARF.OpenAPI.WorldAnalysis.Pose> posesList = poses_.Poses1 as List<ETSI.ARF.OpenAPI.WorldAnalysis.Pose>;
if (poses_ != null && posesList != null && posesList.Count > 0)
{
......@@ -398,16 +398,16 @@ public partial class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
public CapabilityResult GetCapabilities(string token, out Capability[] capabilities)
{
Response2 cap = apiClient.GetCapabilities(token, sessionID);
if (cap == null || cap.Capabilities == null || cap.Capabilities.Count == 0)
Capabilities cap = apiClient.GetCapabilities(token, sessionID);
if (cap == null || cap.Capabilities1 == null || cap.Capabilities1.Count == 0)
{
capabilities = null;
return CapabilityResult.FAIL;
}
else
{
capabilities = new Capability[cap.Capabilities.Count];
cap.Capabilities.CopyTo(capabilities, 0);
capabilities = new Capability[cap.Capabilities1.Count];
cap.Capabilities1.CopyTo(capabilities, 0);
return CapabilityResult.OK;
}
}
......@@ -418,7 +418,7 @@ public partial class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
type = TypeWorldStorage.UNKNOWN;
capability = null;
Response3 cap = apiClient.GetSupport(token, sessionID, uuid);
Supports cap = apiClient.GetSupport(token, sessionID, uuid);
if (cap == null || cap.Capabilities == null || cap.Capabilities.Count == 0)
{
isSupported = false;
......
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ETSI.ARF.OpenAPI.WorldAnalysis;
using WebSocketSharp;
using static WorldAnalysisInterface;
//Implementation of the WorldAnalysis interface
public partial class WorldAnalysisREST
{
//
// Inspector variables
//
public StringEvent webSocketMessage;
//
// Private members
//
private WebSocketSharp.WebSocket webSocket; // For WebSockets
private bool websocketConnected = false;
#region Communication system for WebSockets
public WebSocket WebSocketClient_Create(string url)
{
webSocket = new WebSocketSharp.WebSocket(url);
//
// Define standard callbacks
//
webSocket.OnOpen += (sender, e) =>
{
Debug.Log("[WS] Connected");
websocketConnected = true;
webSocket.Send("RegisterClient:UnitySceneManagement");
};
webSocket.OnClose += (sender, e) =>
{
Debug.Log("[WS] Disconnected");
websocketConnected = false;
};
webSocket.OnError += (sender, e) => Debug.Log("[WS] Error!");
webSocket.OnMessage += (sender, e) => WebSocketClient_OnReceive(e.Data);
webSocket.Connect();
return webSocket;
}
private void WebSocketClient_Close()
{
if (websocketConnected)
{
webSocket.Send("UnregisterClient");
webSocket.Close();
webSocket = null;
}
}
public void WebSocketClient_Send(string msg)
{
webSocket?.Send(msg);
}
bool isRegistered = false;
public void WebSocketClient_OnReceive(string data)
{
//Debug.Log("[WS] Receiving: " + data);
if (data.Contains("You are now registered"))
{
isRegistered = true;
if (isDebug)
{
webSocket.Send("TimeStart:3"); // test
}
}
else if (isRegistered)
{
if (data.StartsWith("Time="))
{
// test the communication
Debug.Log("[WS] Server time is: " + data.Split('=')[1]);
webSocketMessage?.Invoke(data);
}
else if (data == "TimeStop")
{
// Get some dummy poses?
//webSocket.Send("PoseStart:5"); // test
}
else if (data == "PoseStop")
{
//SetColor(Color.yellow);
}
else if (data.StartsWith("Pose=") && data.Contains("estimationState"))
{
// Handle the new pose
string json = data.Substring("Pose=".Length);
ETSI.ARF.OpenAPI.WorldAnalysis.Pose pose = JsonUtility.FromJson<ETSI.ARF.OpenAPI.WorldAnalysis.Pose>(json);
Debug.Log("[WS][Pose] State: " + pose.EstimationState.ToString());
// to check: p.Confidence
// to check: p.Mode, p.Value
PoseEstimationResult res = pose.EstimationState == PoseEstimationState.OK ? PoseEstimationResult.OK : PoseEstimationResult.FAILURE;
// Look for the corresponding callbacks
foreach (var item in m_subscriptionsPoses.Values)
{
if (pose.Uuid == item.uuidTarget)
{
item.callback(res, pose);
}
}
}
}
}
#endregion
}
\ No newline at end of file
fileFormatVersion: 2
guid: 7b7bcc535a949e24283db7e23c51dc46
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ETSI.ARF.OpenAPI.WorldAnalysis;
using ETSI.ARF.WorldAnalysis;
using ETSI.ARF.WorldAnalysis.REST;
//Implementation of the WorldAnalysis interface
public partial class WorldAnalysisREST
{
//
// Inspector variables
//
public StringEvent webhookMessage;
private bool webhookRunning = false;
#region Communication system for WebHooks
private void WebHookServer_Create(string url)
{
webhookRunning = true;
throw new Exception("[API] WebHookServer_Create(): Not implemented!");
}
private void WebHookServer_Close()
{
if (webhookRunning)
{
webhookRunning = false;
throw new Exception("[API] WebHookServer_Close(): Not implemented!");
}
}
private object WebHookServer_OnReceive()
{
throw new Exception("[API] WebHookServer_OnReceive(): Not implemented!");
}
private void WebHookServer_Send(object message)
{
throw new Exception("[API] WebHookServer_Send(): Not implemented!");
}
#endregion
}
\ No newline at end of file
fileFormatVersion: 2
guid: 67d4b99a5f7593e4a857b6c88249d564
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment