fossunited / falcon

A service that execute code in any programming language in a sandboxed environment.
MIT License
42 stars 6 forks source link

Live Code Protocol v0.2 #5

Open anandology opened 3 years ago

anandology commented 3 years ago

Currently the executing the code is done as part of the websocket connection. If the connection gets lost, there is no way to reconnect. This is an improvement over protocol v0.1 by adding the concept of sessions.

Protocol

The LiveCode manages sessions of execution. A new session is created by sending a POST request to /sessions and each session info can be get by sending a GET request to /sessions/session-id.

List all sessions of the current user

GET /sessions
--
200 OK

[
    {"id": "d953d41febcc"},
    {"id": "'0f55ee843aa5'"}
]

This will be implemented only after adding support for users.

Create a new session

POST /sessions
{
    "runtime": "python-canvas",
    "code": "circle(100, 100, 50)"
}
---
201 Created

Location: http://..../sessions/d953d41febcc

{
    "id": "d953d41febcc",
    "created": "2021-03-01T10:20:30",
    "elapsed": 5.3,
    "links": {
        "self": "http://.../sessions/d953d41febcc",
        "stream": "ws://.../sessions/d953d41febcc/stream"
    }
}

The stream link provides the websocket connection for receiving the output and events .

Delete a session

DELETE /sessions/d953d41febcc
---
204 No Content

Possible Error codes:

404 Not Found

Connection to the stream

GET /sessions/d953d41febcc/stream
Connection: Upgrade
Upgrade: websocket
---
101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: ...

If the connection to a websocket is lost, connection can be retried.

The behaviour of multiple websocket clients connecting at the same time is undefined.

The stream websocket protocol

The stream websocket protocol will be save as in the LiveCode protocol 0.1, except that there won't be any exec command.

anandology commented 3 years ago

It would be a good idea to generalize the stream concept further to support multiple streams. Regular executions will either have an io stream or no streams. Graphical applications like the ones that paint on canvas etc. can have additional stream to communicate the keyboard board and mouse events to the program and receive the commands to paint.