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

Draft implementation of the websockets logic

parent 53394218
No related branches found
No related tags found
2 merge requests!2Some trst implementation for REST.,!1Some trst implementation for REST.
......@@ -53,27 +53,17 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult GetCapabilities([FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// Get all capabilities from all anchors/trackables
// test
EncodingInformationStructure enc = new EncodingInformationStructure();
enc.DataFormat = EncodingInformationStructure.DataFormatEnum.OTHEREnum;
enc.VarVersion = "12345";
// todo: compare token and sessionID
Capability capability = new Capability();
capability.TrackableType = TrackableType.FIDUCIALMARKEREnum;
capability.EncodingInformation = enc;
capability.Accuracy = 1;
capability.Framerate = 24;
capability.Latency = 0;
// Get all capabilities from all anchors/trackables
// Create list
List<Capability> capabilities = new List<Capability>();
//capabilities.Add(capability);
capabilities.AddRange(WorldAnalysisModules.Singleton.GetCapabilities());
List<Capability> capabilitiesList = new List<Capability>();
capabilitiesList.AddRange(WorldAnalysisModules.Singleton.GetCapabilities());
// Create repsonse object
// Create response object
GetCapabilities200Response response = new GetCapabilities200Response();
response.Capabilities = capabilities;
response.Capabilities = capabilitiesList;
return new ObjectResult(response);
//return StatusCode(405, "Not supported yet!");
}
......@@ -83,11 +73,16 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult GetSupport([FromRoute (Name = "trackableOrAnchorUUID")][Required]Guid trackableOrAnchorUUID, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
Capability capability = new Capability();
capability.Framerate = 24;
capability.Latency = 0;
capability.TrackableType = TrackableType.FIDUCIALMARKEREnum;
return (null != capability) ? new ObjectResult(capability) : StatusCode(404, "Not found, could not find capability for UUID: " + trackableOrAnchorUUID);
// todo: compare token and sessionID
// Create list
List<Capability> capabilitiesList = new List<Capability>();
capabilitiesList.AddRange(WorldAnalysisModules.Singleton.GetCapabilitiesFromUuid(trackableOrAnchorUUID));
// Create response object
GetSupport200Response response = new GetSupport200Response();
response.Capabilities = capabilitiesList;
return new ObjectResult(response);
//return StatusCode(405, "Not supported yet!");
}
}
......
......@@ -53,6 +53,8 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult ConfigureFramerate([FromBody]PoseConfiguration poseConfiguration, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
return StatusCode(405, "Not supported yet!");
}
......@@ -61,6 +63,8 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult GetPose([FromRoute (Name = "trackableOrAnchorUUID")][Required]Guid trackableOrAnchorUUID, [FromQuery (Name = "mode")][Required()]ModeWorldAnalysis mode, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
return StatusCode(405, "Not supported yet!");
}
......@@ -72,11 +76,33 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
return StatusCode(405, "Not supported yet!");
}
#pragma warning disable CS1591 // Fehlendes XML-Kommentar fr ffentlich sichtbaren Typ oder Element
//
// Management of subscriptions
//
/// <summary>
/// Dictionnary of susbscription informations for poses, for each item, stored using the UUID of the item (anchor/trackable)
/// </summary>
private Dictionary<Guid, SubscriptionInfo> m_subscriptionsPoses = new Dictionary<Guid, SubscriptionInfo>();
public struct SubscriptionInfo
{
public Guid uuid; // id of subscription (id is defined by the WA server)
public Guid uuidTarget; // id trackable or anchor
public DateTime timeValidity; //The duration of the validity of the subscription
public Pose pose;
//public PoseCallback callback;
}
#pragma warning restore CS1591 // Fehlendes XML-Kommentar fr ffentlich sichtbaren Typ oder Element
/// <summary>
/// Get information about a subscription
/// </summary>
public override IActionResult GetSubscription([FromRoute (Name = "subscriptionUUID")][Required]Guid subscriptionUUID, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
return StatusCode(405, "Not supported yet!");
}
......@@ -85,12 +111,37 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult SubscribeToPose([FromBody]SubscribeToPoseRequest subscribeToPoseRequest, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
int validity = subscribeToPoseRequest.Validity; // todo: is to handle here or by the client?
// We add the subscription
SubscriptionInfo sub = new SubscriptionInfo();
sub.uuid = new Guid();
sub.timeValidity = DateTime.Now.AddMilliseconds(validity / 1000.0f);
sub.pose = new Pose();
sub.pose.Mode = subscribeToPoseRequest.Mode[0];
sub.uuidTarget = subscribeToPoseRequest.Target;
m_subscriptionsPoses.Add(sub.uuid, sub);
SubscribeToPose200Response response = new SubscribeToPose200Response();
response.Target = subscribeToPoseRequest.Target;
response.Mode = subscribeToPoseRequest.Mode[0];
response.WebhookUrl = "";
response.WebsocketUrl = Request.Host.ToString(); ;
response.Uuid = sub.uuid;
response.Validity = validity;
response.Target = sub.uuidTarget;
response.Mode = sub.pose.Mode;
if (string.IsNullOrEmpty(subscribeToPoseRequest.WebhookUrl))
{
response.WebhookUrl = "";
response.WebsocketUrl = Request.Host.ToString();
// Notice: starting websocket server is done autom. by the client, when calling "URL:/ws"
// todo: register the client, so the websocket will send to it pose updates
}
else
{
response.WebhookUrl = subscribeToPoseRequest.WebhookUrl;
response.WebsocketUrl = null;
}
return new ObjectResult(response);
//return StatusCode(405, "Not supported yet!");
}
......@@ -100,6 +151,8 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult UnsubscribeFromPose([FromRoute (Name = "subscriptionUUID")][Required]Guid subscriptionUUID, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
return StatusCode(405, "Not supported yet!");
}
......@@ -108,6 +161,8 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
/// </summary>
public override IActionResult UpdateSubscription([FromRoute (Name = "subscriptionUUID")][Required]Guid subscriptionUUID, [FromBody]UpdateSubscriptionRequest updateSubscriptionRequest, [FromHeader (Name = "token")]string token, [FromHeader (Name = "sessionID")]string sessionID)
{
// todo: compare token and sessionID
return StatusCode(405, "Not supported yet!");
}
}
......
......@@ -166,7 +166,7 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
if (firstTime)
{
// Register the client/module
if (msg.StartsWith("Module:"))
if (msg.StartsWith("RegisterModule:"))
{
registered = true;
firstTime = false;
......@@ -179,7 +179,7 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
await SendText(webSocket, "ARF World Analysis Server: You are now registered as a module: " + currentName);
}
}
else if (msg.StartsWith("Client:"))
else if (msg.StartsWith("RegisterClient:"))
{
registered = true;
firstTime = false;
......@@ -200,13 +200,13 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis.Controllers
}
else if (registered)
{
if (msg.StartsWith("StartSendingPose"))
if (msg.StartsWith("PoseStart"))
{
if (msg.Contains(':')) timeCnt = int.Parse(msg.Split(':')[1]);
else timeCnt = 3;
await SendPose(webSocket);
}
else if (msg.StartsWith("Time"))
else if (msg.StartsWith("TimeStart"))
{
if (msg.Contains(':')) timeCnt = int.Parse(msg.Split(':')[1]);
else timeCnt = 3;
......
......@@ -41,6 +41,19 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis
}
return list;
}
public List<Capability> GetCapabilitiesFromUuid(Guid trackableOrAnchorUUID)
{
List<Capability> list = new List<Capability>();
foreach (var item in modules)
{
// todo: Check if uuid has the capability?
// Get the world object from the storage via the module?
list.AddRange(item.capabilities);
}
return list;
}
}
}
#pragma warning restore CS1591 // Fehlendes XML-Kommentar für öffentlich sichtbaren Typ oder Element
......@@ -27,7 +27,7 @@ namespace ETSI.ARF.OpenAPI.WorldAnalysis
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080/");
.UseUrls("http://0.0.0.0:44301/"); // SylR: Wichtig!!!
});
}
}
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