Skip to content

Commit

Permalink
chore: update clientEvent and program topic-v5
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Oct 17, 2024
1 parent c4e757d commit f020906
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Runtime/Components/ArenaClickListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ internal void PublishMouseEvent(string eventType)

ArenaEventJson data = new ArenaEventJson
{
ClickPos = ArenaUnity.ToArenaPosition(camPosition),
Position = ArenaUnity.ToArenaPosition(hit.point),
Source = camName,
OriginPosition = ArenaUnity.ToArenaPosition(camPosition),
TargetPosition = ArenaUnity.ToArenaPosition(hit.point),
Target = camName,
};
string payload = JsonConvert.SerializeObject(data);
if (ArenaClientScene.Instance)
Expand Down
42 changes: 33 additions & 9 deletions Runtime/Schemas/ArenaArenaProgramJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ArenaArenaProgramJson

private static string defName = null;
[JsonProperty(PropertyName = "name")]
[Tooltip("Name of the program in the format namespace/program-name.")]
[Tooltip("Name of the program.")]
public string Name = defName;
public bool ShouldSerializeName()
{
Expand Down Expand Up @@ -72,11 +72,29 @@ public bool ShouldSerializeInstantiate()
return true; // required in json schema
}

private static string defFile = null;
[JsonProperty(PropertyName = "file")]
[Tooltip("The path to a `.wasm` file (e.g. `counter.wasm`, `user1/counter.wasm`) in the ARENA filestore, starting from the location field indicated below. See location. Example: user1/py/counter/counter.py should have file: `counter.py` and location: `user1/py/counter`. Note that the runtime will download all files in parent folder (e.g. you can add a requirements.txt)")]
public string File = defFile;
public bool ShouldSerializeFile()
{
return true; // required in json schema
}

private static string defFilename = null;
[JsonProperty(PropertyName = "filename")]
[Tooltip("Filename of the entry binary.")]
public string Filename = defFilename;
[Obsolete("DEPRECATED: data.filename is deprecated for type: program, use data.file and data.location instead.")]
public string Filename { get; protected set; } = defFilename;
public bool ShouldSerializeFilename()
{
return false; // deprecated in json schema
}

private static string defLocation = null;
[JsonProperty(PropertyName = "location")]
[Tooltip("Filestore path starting at user home; Example: `user1/hello` for a program inside folder `hello` of user1. Should, at least be the user filesore home folder.")]
public string Location = defLocation;
public bool ShouldSerializeLocation()
{
return true; // required in json schema
}
Expand All @@ -98,18 +116,24 @@ public bool ShouldSerializeFiletype()
return true; // required in json schema
}

private static string defParent = "pytest";
public enum ParentType
{
[EnumMember(Value = "arena-rt1")]
ArenaRt1,
}
private static ParentType defParent = ParentType.ArenaRt1;
[JsonConverter(typeof(StringEnumConverter))]
[JsonProperty(PropertyName = "parent")]
[Tooltip("Request the orchestrator to deploy to this runtime (can be a runtime name or UUID); usually left blank.")]
public string Parent = defParent;
[Tooltip("Request the orchestrator to deploy to this runtime (can be a runtime name or UUID); Temporarily must be arena-rt1.")]
public ParentType Parent = defParent;
public bool ShouldSerializeParent()
{
return true; // required in json schema
}

private static string[] defArgs = null;
[JsonProperty(PropertyName = "args")]
[Tooltip("Command-line arguments (passed in argv). Supports variables: ${scene}, ${mqtth}, ${cameraid}, ${username}, ${runtimeid}, ${moduleid}, ${query-string-key}.")]
[Tooltip("Command-line arguments (passed in argv). Supports variables: ${scene}, ${mqtth}, ${userid}, ${username}, ${runtimeid}, ${moduleid}, ${query-string-key}.")]
public string[] Args = defArgs;
public bool ShouldSerializeArgs()
{
Expand All @@ -119,14 +143,14 @@ public bool ShouldSerializeArgs()

private static string[] defEnv = { "MID=${moduleid}", "SCENE=${scene}", "NAMESPACE=${namespace}", "MQTTH=${mqtth}", "REALM=realm" };
[JsonProperty(PropertyName = "env")]
[Tooltip("Environment variables. Supports variables: ${scene}, ${namespace}, ${mqtth}, ${cameraid}, ${username}, ${runtimeid}, ${moduleid}, ${query-string-key}.")]
[Tooltip("Environment variables. Supports variables: ${scene}, ${namespace}, ${mqtth}, ${userid}, ${username}, ${runtimeid}, ${moduleid}, ${query-string-key}.")]
public string[] Env = defEnv;
public bool ShouldSerializeEnv()
{
return true; // required in json schema
}

private static object[] defChannels = { JsonConvert.DeserializeObject("{'path': '/ch/${scene}', 'type': 'pubsub', 'mode': 'rw', 'params': {'topic': 'realm/s/${scene}'}}") };
private static object[] defChannels = { JsonConvert.DeserializeObject("{'path': '/ch/${scene}', 'type': 'pubsub', 'mode': 'rw', 'params': {'topic': 'realm/s/${scene}/${namespace}'}}") };
[JsonProperty(PropertyName = "channels")]
[Tooltip("Channels describe files representing access to IO from pubsub and client sockets (possibly more in the future; currently only supported for WASM programs).")]
public object[] Channels = defChannels;
Expand Down
51 changes: 39 additions & 12 deletions Runtime/Schemas/ArenaEventJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,59 @@ public class ArenaEventJson

// event member-fields

private static string defTarget = null;
[JsonProperty(PropertyName = "target")]
[Tooltip("The `object_id` of event destination.")]
public string Target = defTarget;
public bool ShouldSerializeTarget()
{
return true; // required in json schema
}

private static ArenaVector3Json defTargetPosition = null;
[JsonProperty(PropertyName = "targetPosition")]
[Tooltip("The event destination position in 3D.")]
public ArenaVector3Json TargetPosition = defTargetPosition;
public bool ShouldSerializeTargetPosition()
{
return true; // required in json schema
}

private static ArenaVector3Json defOriginPosition = JsonConvert.DeserializeObject<ArenaVector3Json>("{'x': 0, 'y': 1.6, 'z': 0}");
[JsonProperty(PropertyName = "originPosition")]
[Tooltip("The event origination position in 3D.")]
public ArenaVector3Json OriginPosition = defOriginPosition;
public bool ShouldSerializeOriginPosition()
{
// originPosition
return (OriginPosition != defOriginPosition);
}

private static string defSource = null;
[JsonProperty(PropertyName = "source")]
[Tooltip("The `object_id` of event origination. e.g camera or client program connection id.")]
public string Source = defSource;
[Obsolete("DEPRECATED: data.source is deprecated for clientEvent, use data.target instead.")]
public string Source { get; protected set; } = defSource;
public bool ShouldSerializeSource()
{
return true; // required in json schema
return false; // deprecated in json schema
}

private static ArenaVector3Json defPosition = null;
private static object defPosition = null;
[JsonProperty(PropertyName = "position")]
[Tooltip("The event destination position in 3D.")]
public ArenaVector3Json Position = defPosition;
[Obsolete("DEPRECATED: data.position is deprecated for clientEvent, use data.targetPosition instead.")]
public object Position { get; protected set; } = defPosition;
public bool ShouldSerializePosition()
{
return true; // required in json schema
return false; // deprecated in json schema
}

private static ArenaVector3Json defClickPos = JsonConvert.DeserializeObject<ArenaVector3Json>("{'x': 0, 'y': 1.6, 'z': 0}");
private static object defClickPos = null;
[JsonProperty(PropertyName = "clickPos")]
[Tooltip("The event origination position in 3D.")]
public ArenaVector3Json ClickPos = defClickPos;
[Obsolete("DEPRECATED: data.clickPos is deprecated for clientEvent, use data.originPosition instead.")]
public object ClickPos { get; protected set; } = defClickPos;
public bool ShouldSerializeClickPos()
{
// clickPos
return (ClickPos != defClickPos);
return false; // deprecated in json schema
}

// General json object management
Expand Down
4 changes: 2 additions & 2 deletions Samples~/LaserPointer/Assets/LaserPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private void MouseEventCallback(string event_type, string message)
ArenaObjectJson m = JsonConvert.DeserializeObject<ArenaObjectJson>(message);
ArenaEventJson evt = JsonConvert.DeserializeObject<ArenaEventJson>(m.data.ToString());

ArenaVector3Json start = evt.ClickPos;
ArenaVector3Json end = evt.Position;
ArenaVector3Json start = evt.OriginPosition;
ArenaVector3Json end = evt.TargetPosition;
start.Y = (float)start.Y - .1f; // lower position for visibility

// laser
Expand Down

0 comments on commit f020906

Please sign in to comment.