ID:2610872
 
Applies to:Dream Seeker
Status: Open

Issue hasn't been assigned a status value.
While CEF integration is in heavy development, it might be a good opportunity to rethink some of the browser APIs for BYOND stuff. I have no doubt `location.href` hook is going to stay because a lot of games depend on it, and it's actually very good for "href" links in static and semi-static html, but it gets really ugly in complex apps, especially with winget.

I've developed a relatively thick BYOND API wrapper while developing tgui, which I've grown to like a lot over time, and I think it would be a good fit for CEF natively. This is how it looks:

Byond.winset(id, { ...properties })
Byond.winset(id, name, value)
await Byond.winget(id)
await Byond.winget(id, [...names])
await Byond.winexists(id)
Byond.topic({ ...params })
Byond.command(command)
Byond.output(id, payload)
Byond.parseJson(str)

Latest implementation: https://p.smx.lt/Bz0OtVO

It uses promises for async calls, which could be natively supported in Chromium, and it makes the code look clean in comparison to global window callbacks.

Another non-obvious benefit of this API, is that it would be possible to detect whether the script is running in BYOND just by checking whether this Byond object exists on window. This is useful for debugging the page in an external browser and/or E2E tests. Currently, there is no good way to check whether the page runs in Byond.

This kind of API would also be a huge win for the web client, because href hooks in the browser are basically impossible to do without going insane. You'd need a proxy for window.location, rewrite all anchors in html, extend the document object model... The list goes on.

And another thing which I would like to see, is the ability to subscribe to outside events, like keyboard presses or mouse movement/clicks within the byond skin. It's doable via topic calls, but that adds latency to interactions. This would be useful for custom keybinds in javascript code (it is already sort of doable with byond macros), and smart contextual tooltips on the panel based on what is currently hovered with the mouse. There is also no way to get raw mouse wheel events in embedded IE, which is a real bummer because we wanted to use mousewheel to rotate paper stamps in html UI, or implement zoom on interactive html maps, and there is no real alternative.

I'd like to hear if you have comments (my discord handle is stylemistake#1991). No pressure!