Commit 8387baf1 authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

working DirectCommunication

parent bbfe2820
var DirectCommunication = {
$dc: {
response: null
responseHandler: null,
},
Reply: function(string) {
if (dc.response != null)
Init: function() {
dc.responseHandler = window.DLUHandler;
},
Reply: function(string_ptr, string_length) {
var string = Pointer_stringify(string_ptr).substring(0, string_length);
if (dc.responseHandler != null)
{
dc.response(JSON.parse(Pointer_stringify(string)));
dc.responseHandler(JSON.parse(string));
}
else
else
{
console.error("No response handler");
console.error(JSON.parse(Pointer_stringify(string)));
console.error(string);
}
},
};
......
......@@ -12,15 +12,19 @@ namespace dlu
{
public class DirectCommunication : Communication
{
{
[DllImport("__Internal")]
public static extern void Init();
[DllImport("__Internal")]
public static extern void Reply(byte[] response, int response_length);
protected override void StartServer()
{
// nothing to do here
Init();
}
[DllImport("__Internal")]
public static extern void Reply(byte[] response);
public void PerformRequest(string request) {
Debug.Log($"[DirectCommunication] Received message:\n{request}");
JSONObject requestObject = JSON.Parse(request) as JSONObject;
......@@ -29,7 +33,8 @@ public class DirectCommunication : Communication
public override IEnumerator ReplyToRequest(string response)
{
Reply(Encoding.UTF8.GetBytes(response));
byte[] responseArray = Encoding.UTF8.GetBytes(response);
Reply(responseArray, response.Length);
yield return null;
}
......@@ -37,7 +42,6 @@ public class DirectCommunication : Communication
{
Debug.Log($"Got a message: {tolog}");
}
}
}
\ No newline at end of file
......@@ -108,7 +108,7 @@ public class JSONHandler
}
JSONObject metaObject = new JSONObject();
// metaObject.Add("image", screenShotPath);
metaObject.Add("image", screenShotPath);
JSONObject contextObject = new JSONObject();
contextObject.Add("meta", metaObject);
contextObject.Add("context", sceneArray);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment