sabresaurus / Remote-Actions

Call custom code snippets in deployed Unity builds
MIT License
7 stars 2 forks source link

Migrate to RESTful #2

Open sabresaurus opened 5 years ago

sabresaurus commented 5 years ago

Following up from sabresaurus/Sidekick#42 it would be great to support a RESTful interface, for example:

GET 192.168.0.5/hierarchy could return the hierarchy GET 192.168.0.5/73e6cf69-f18b-4fc7-bdbc-60bd246c3b53 could return data for that object PATCH 192.168.0.5/73e6cf69-f18b-4fc7-bdbc-60bd246c3b53 could update an object's field with the updates embedded in the message body

sabresaurus commented 5 years ago

This looks like it should be straightforward using a mixture of .NET's HttpListener on device and Unity's UnityWebRequest in Editor.

sabresaurus commented 5 years ago

Got this working with a test project, it also works with a browser (as expected from its HTTP nature). The browser support is less useful for Sidekick given it's heavily binary, but could be useful to other projects that want to pass plain text/json around for example.

sabresaurus commented 5 years ago

Looked into this further and it looks like Http's Keep Alive would need to be used to ensure the connection doesn't shut down with every request as there is a noticeable lag in creating new connections as you drag sliders in Unity when a socket isn't kept open.

I believe .NET's HttpListener supports KeepAlive but I don't think UnityWebRequest does meaning we'd need an alternative class for the editor to use (there are some in .NET, HttpWebRequest perhaps). I was hoping that this might make it into 1.0.0, but I'll descope in favour of 1.1.0 at the earliest