SurfaceHandle
public sealed class SurfaceHandleNamespace Sideload.Api
Added in 1.13.0
Handle to a mounted surface: the same call and event channel an app has, minus everything that only makes sense on a phone.
Properties
Section titled “Properties”public string Id { get; }Added in 1.13.0
The id this surface was mounted under.
Methods
Section titled “Methods”OnCall
Section titled “OnCall”public SurfaceHandle OnCall(string name, Func<string, string> handler)Added in 1.13.0
Answer s1.call(name, arg) from this surface’s page. Same rules as an app’s handler: it runs on the Unity main thread in the same frame, and returns a string.
| Parameter | |
|---|---|
name | The name the page passes to s1.call, e.g. “chat.send”. Compared case-insensitively. Null or blank registers nothing. The same name again replaces the handler. |
handler | Gets the page’s argument, or an empty string when it passed none. Its return value is what s1.call returns; null returns an empty string. An exception is logged and the page gets an empty string. |
public SurfaceHandle Emit(string name, string payload = "")Added in 1.13.0
Push an event at this surface’s page - s1.on(name, fn). Nothing happens when the surface is not mounted; the page picks the state up when it next builds.
| Parameter | |
|---|---|
name | The name the page listens on with s1.on, e.g. “chat.message”. Compared case-insensitively. Null or blank sends nothing. |
payload | The string the page’s listener receives, e.g. JSON. Null sends an empty string. |
AllowHost
Section titled “AllowHost”public SurfaceHandle AllowHost(string host)Added in 1.13.0
Let this surface’s page reach one host with fetch. The allowlist starts empty.
| Parameter | |
|---|---|
host | A bare host name such as “api.example.com”, or *.example.com for any single label under it. A full URL is accepted and only its host is kept. A port is ignored. |
public SurfaceHandle Image(string name, byte[] png)Added in 1.32.0
Publish a picture this surface’s page can draw with <img src="s1://<name>">, exactly as an app does. Null or empty bytes remove it.
It was missing, and the store never cared: pictures are held by (id, name) and nothing asks whether the id belongs to an app or a surface. So a surface could always have them - it just had no supported way to say so, and the one mod that needed it reached past this file into the internals because it compiles the shim in as source. A mod that references the DLL could not have done that at all.
PNG bytes rather than a texture, for the reason the whole file gives: nothing here references a Unity type and nothing here is going to start.
surface.Image("icon/" + itemId, pngBytes);| Parameter | |
|---|---|
name | The name after s1:// in the page, e.g. “avatar/76561198”. Trimmed. Null or blank does nothing. |
png | PNG file bytes. Null or empty removes the picture. |
Unmount
Section titled “Unmount”public void Unmount()Added in 1.13.0
Take this surface down.