This project builds a client-side library to receive Parsegraph server events and update a local graph accordingly. It also allows for the client to callback the server based on graph interaction.
This module allows live updates from a Parsegraph server to multiple connected clients.
It also contains a server used to stream Parsegraph server events.
Parsegraph applications can be written solely on the client, with callbacks embedded in the application. However, it becomes challenging to add sharing of the Parsegraph environment to other users, because updates to the graph must be maintained.
Parsegraph stream inverts this problem by making all graph updates come from the server. It provides means to add callbacks to the graph, completing a round-trip of serving an initial graph, letting the user invoke graph actions, and sending graph updates back to the client once the callback is complete.
Run a server, either locally or within a container, and navigate to /. You should see a Parsegraph client. This will show the Parsegraph for the content root. The content root is set by the CONTENT_ROOT environment variable.
The container will run the demo server.
make build-container
docker run -d --net bridge --name parsegraph -e SITE_HOST=0.0.0.0 -e CONTENT_ROOT=/usr/src --expose 3000 -p=127.0.0.1:15000:3000/tcp localhost/parsegraph-stream:latest
A Parsegraph server manages a collection of proxy Parsegraph objects, and is able to stream changes to those Parsegraph objects to callbacks.
Sets the callback URL used by the server
Stream server events as arguments back to the given callback.
Send all saved server events back to the given callback.
Invokes the server callback
Returns the server state.
The Parsegraph server state contains the current state of the Parsegraph, and provides methods to update the state using Parsegraph proxy objects.
Sets the background color in RGBA space. Numbers are expected to be in range [0, 1].
Returns a Parsegraph caret, using the given type as the initial value of the caret root node.
Sets the root to the given Parsegraph node.
These are the two methods imported from script.js, used to create new ParsegraphServers.
Returns a Parsegraph server designed for streaming and callbacks.
A new Parsegraph streaming server is launched for the subPath if necessary.
- mainPath - the contentRoot.
- subPath - the URL part specific to the stream.
Returns a Parsegraph server designed for caching.
A new Parsegraph server is launched for the subPath if necessary.
- mainPath - the contentRoot.
- subPath - the URL part specific to the stream.
health check.
Responds 200 with "testroute from server" on success.
Connect to a Parsegraph streaming server named by the URL and stream Parsegraph events back to the client.
Content to a Parsegraph server named by the URL and stream Parsegraph events back to the client.
Connects to a Parsegraph server and writes all saved events back to the client, and close the connection.
Stream raw content from the given path, under the content root.
Finds a Parsegraph streaming server named by the URL, and calls callback by index, passing the request body as the argument.
The cb query parameter is the callback index.
- Responds 500 on server error
- Responds 200 on success
Takes a JSON request of the following form:
interface SpliceRequest {
offset: number;
len: number;
val: string;
}
And splices val in the file at the named subPath, under the content root. Both the Parsegraph servers and streaming server are replaced.
- Responds 200 if the splice is successful.
- Responds 500 on server error
- Responds 400 if the offset or len are NaN.