ofs-ws-extended v1
Status: draft.
ofs-ws-extended is the OpenFunscripter (OFS) WebSocket API plus device
state. Many apps already send their media and scripts to a device player such as
RustyFunPlayer through the OpenFunscripter (OFS) WebSocket API. This extension
lets the device player tell the app about its devices on the same socket, and
lets the app adjust their travel ranges. An app can then show “Handy connected,
stroke 10–90 %” in its own interface without speaking any device protocol.
Players and apps that do not know the extension keep the plain OFS behavior.
Terms
- App: the program that serves the OFS WebSocket API, for example FapLand.
- Player: the program that connects to it and drives devices, for example RustyFunPlayer.
The key words MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119.
The OFS WebSocket API in short
The app serves a WebSocket, by convention at ws://127.0.0.1:<port>/ofs, and
the player connects to it. Each message is one JSON text frame:
{ "type": "event", "name": "time_change", "data": { "time": 12.3 } }
The app sends events:
name | data |
|---|---|
media_change | { "path": "/videos/round.mp4" }, or null path when nothing plays |
play_change | { "playing": true } |
time_change | { "time": 12.3 } in seconds |
duration_change | { "duration": 60.0 } in seconds |
playbackspeed_change | { "speed": 1.0 } |
funscript_change | { "name": "round.funscript", "funscript": { ... } } with the whole script |
funscript_remove | { "name": "round.funscript" } |
project_change | {}: forget all scripts |
The player may send the commands change_play, change_time and
change_playbackspeed with the same data shapes. An app MAY ignore them.
Port
Apps choose their own port once, derived from their Funlink id, so each app keeps the same port on every machine and two apps rarely collide:
h = 0x811C9DC5 // FNV-1a, 32 bit
for each byte b of the id in UTF-8:
h = (h XOR b) * 0x01000193 mod 2^32
port = 20000 + (h mod 10000)
If the port is taken, the app tries the next one, wrapping from 29999 to 20000, up to 100 times. Example: the id my-game gives port 21976. Apps SHOULD use this rule and SHOULD only offer a fixed port as an advanced setting. Players never rely on the number: they take the endpoint from the Funlink announcement.
Discovery
An app that implements this extension announces its socket over
Funlink twice, as ofs-ws-extended and as ofs-ws, with the same
endpoint:
"services": [
{ "protocol": "ofs-ws-extended", "endpoint": "ws://127.0.0.1:8080/ofs" },
{ "protocol": "ofs-ws", "endpoint": "ws://127.0.0.1:8080/ofs" }
]
Hubs that know the extension use the ofs-ws-extended service and MUST NOT
offer the ofs-ws service with the same endpoint separately. Other hubs ignore
the unknown protocol and connect with plain OFS. An app that serves only plain
OFS announces only ofs-ws.
ofs-ws-fapland is an alias of ofs-ws-extended that FapLand announces
instead, so hubs can present it as FapLand. It means exactly the same, and a
hub that supports one of the two names MUST support both. Other apps use
ofs-ws-extended.
Handshake
Right after connecting, a player that implements the extension sends:
{ "type": "command", "name": "device_hello", "data": { "protocol": 1, "application": "RustyFunPlayer", "version": "0.1.0" } }
An app that implements it answers:
{ "type": "event", "name": "device_hello", "data": { "protocol": 1, "application": "FapLand", "version": "0.6.32" } }
| Field | Type | Rules |
|---|---|---|
protocol | integer | The highest version of this extension the sender speaks. Both sides use the lower of the two values. |
application | string | Display name, up to 200 characters. |
version | string or null | Display version, up to 100 characters. |
features | array of strings, optional | Optional capabilities the sender supports, such as funscript_append. Unknown values are ignored. |
An app that does not know the extension ignores the command, and the session stays plain OFS. The extension is active once the player has the app’s answer.
State
While the extension is active, the player sends device_state at once when an
output, axis or playback value changes, and at least every second so the app
can follow the media position.
{
"type": "command",
"name": "device_state",
"data": {
"outputs": [
{
"id": "serial:0",
"kind": "Serial",
"detail": "/dev/ttyUSB0",
"status": "connected",
"error": null,
"rate": 60,
"axes": [{ "axis": "L0", "enabled": true, "minimum": 0.0, "maximum": 1.0 }]
}
],
"axes": [
{ "axis": "L0", "name": "Up/Down", "script": "round.funscript", "motionProvider": null, "link": null, "syncing": false }
],
"playback": { "media": "round.mp4", "playing": true, "position": 12.3, "duration": 60.0, "speed": 1.0 }
}
}
Each message carries the complete state.
| Field | Rules |
|---|---|
outputs[].id | Stable for the session, up to 100 characters. |
outputs[].kind, detail | Display text for the device type and its address. |
outputs[].status | connected, connecting, disconnecting, disconnected or failed. |
outputs[].error | Display text while failed, otherwise null. |
outputs[].rate | Update rate in Hz, or null. |
outputs[].axes[] | TCode axis (L0, R1, …), whether the output drives it, and its travel range as fractions from 0 to 1. |
axes[] | Every axis the player knows: display name, the script that drives it, a motion provider name, the axis it follows (link), and syncing while it blends back to its script after a seek or media change. |
playback | What the player plays, in seconds. |
At most 64 outputs and 64 axes per message. Receivers MUST ignore unknown
fields and unknown status values.
Live scripts
Scripts that an app generates while it runs, for example from game state, exist only in memory and grow over time. Resending the whole script with funscript_change makes a player treat it as a new script, which can restart its motion. A player that lists funscript_append in its device_hello features accepts appends instead:
{ "type": "event", "name": "funscript_append", "data": { "name": "live.funscript", "actions": [{ "at": 12500, "pos": 80 }, { "at": 12750, "pos": 20 }] } }
| Field | Rules |
|---|---|
name | Script name, as in funscript_change. If the player has no script of that name, it starts one with these actions. |
actions | 1 to 1000 actions in media time: at in milliseconds, pos from 0 to 100. Each at must be later than the script’s last action; earlier ones are ignored. |
The player extends the script in place: it MUST NOT resynchronize, restart or blend the motion because of an append. It MAY drop actions that lie well behind the playback position to bound memory.
Send actions a little ahead of the media time, about 100 to 250 ms, so the player can interpolate towards them. Apps MUST NOT send funscript_append to players that did not list the feature; they send the whole script with funscript_change instead, at most a few times a second. funscript_change and funscript_remove for the same name replace or remove the live script as usual.
Range edits
While the extension is active, the app may move both travel bounds of one output axis:
{ "type": "event", "name": "device_set_range", "data": { "output": "serial:0", "axis": "L0", "minimum": 0.1, "maximum": 0.9 } }
minimum and maximum are fractions from 0 to 1 with minimum < maximum.
The player applies the change like its own range slider and reports it in the
next device_state. It ignores edits for unknown outputs or axes.
Rules
- Messages are at most 256 KiB.
- Apps SHOULD listen on
127.0.0.1only. Where the operating system names the owner of a loopback socket, as Linux does, apps SHOULD refuse players of other users. - New fields may be added within version 1. Incompatible changes raise
protocol.