RacketScript Universe
(require racketscript-universe) | |
package: racketscript-universe |
Experimental implementation of Racket’s 2htdp/universe library for RacketScript. Used to create distributed programs where both the server and the clients run in the browser.
1 Getting Started
Since this library is just an implementation of 2htdp/universe, use those docs as your main reference. These docs will contain info about how racketscript-universe works and how it differs from the original, but won’t contain an in-depth API description.
See this example on github for one way of setting up your project.
To use the library, you need to be running a separate server (universe) and client (big-bang) instance at the same time, both in separate browser windows. You then need to pass the server’s peer id (which is currently "server" by default but will be changed) to the client’s big-bang call, and a connection will be established.
2 How does it work?
We use PeerJS under the hood to mimic client-server behavior where both the client and server run in browser tabs. In reality everything is done with peer connections.
PeerJS’s PeerServer Cloud Serrvice handles all of the traffic behind the scenes so that you don’t have to worry about it.
3 Differences from 2htdp/universe
In practice, this library only differs from 2htdp/universe when setting up connections (plus some slight differences in dependencies). Here’s everything you need to know on top of the original docs.
3.1 Differences for big-bang Function
Original big-bang docs.
big-bang takes and optional #:dom-root keyword argument to specify a root element for the canvas that big-bang draws to.
register takes a peer-id argument instead of an ip-expr.
No on-pad clause (as of now).
No record? clause.
No close-on-stop clause (yet).
No display-mode clause.
No state caluse.
No port clause.
Because our peer connections are handled by one server in the cloud, clients can connect to servers on different networks as long as they know the server id.
3.2 Differences for universe Function
Original universe docs.
The server-id clause can be used with universe to specify its peer id (which gets passed into the register clause of a big-bang call). Note that two servers should not have the same peer id, or problems will occur.
universe takes and optional #:dom-root keyword argument to specify a root element to insert the logging gui into.
No port clause.
No state clause (yet).
No to-string clause (yet).
No check-with clause (yet).
syntax
peer-id : string?