44[ Solid specification] ( README.md ) ; the parent spec and all its components are
55versioned as a whole.
66
7- ## Subscribing
7+ ## Status
8+ This is a _ draft_ protocol.
9+ This specific version is identified by the string ` solid/0.1.0-alpha ` .
10+
11+ ## Protocol description
812
913Live updates are currently only supported through WebSockets. This describes a
1014subscription mechanism through which clients can be notified in real time of
1115changes affecting a given resource.
1216
13- The PubSub system is very basic. Clients only need to open a WebSocket
14- connection and * sub * (scribe) to a given resource URI. If any change occurs in
15- that resource , a * pub * (lish) event will be sent to all the subscribed clients .
16-
17- The WebSocket server URI is the same for any resource located on a given data
18- space (same hostname). To discover the URI of the WebSocket server, clients can
19- send an HTTP OPTIONS request. The server will then include an ` Updates-Via ` header in
20- the response:
17+ ### Discovery
18+ The PubSub system is very basic.
19+ First , a client needs to obtain the URI of the WebSocket .
20+ The WebSocket server URI is the same for any resource
21+ located on a given data space (same hostname).
22+ To discover the URI of the WebSocket server,
23+ clients can send an HTTP ` OPTIONS ` request.
24+ The server will then include an ` Updates-Via ` header in the response:
2125
2226REQUEST:
2327
@@ -31,8 +35,50 @@ RESPONSE:
3135``` http
3236HTTP/1.1 200 OK
3337...
34- Updates-Via: wss://example.org/
38+ Updates-Via: wss://example.org
39+ ```
40+
41+ ### Connection
42+ Then, the client needs to open a WebSocket connection
43+ to that URI.
44+ The client _ SHOULD_ include the protocol version ` solid/0.1.0-alpha `
45+ in the ` Sec-WebSocket-Protocol ` header.
46+
47+ For example, in JavaScript, this could be done as follows:
48+
49+ ```
50+ const socket = new WebSocket('wss://example.org', ['solid/0.1.0-alpha']);
51+ ```
52+
53+ Upon connection,
54+ the server SHOULD indicate the protocol version as follows:
55+
3556```
57+ protocol solid/0.1.0-alpha
58+ warning Unstandardized protocol version, proceed with care
59+ ```
60+
61+ If the client did not specify a ` Sec-WebSocket-Protocol ` header,
62+ the server SHOULD warn the client as follows:
63+
64+ ```
65+ warning Missing Sec-WebSocket-Protocol header, expected value 'solid/0.1.0-alpha'
66+ ```
67+
68+ Otherwise, if the set of values obtained
69+ from parsing the ` Sec-WebSocket-Protocol ` header
70+ does not contain ` solid/0.1.0-alpha ` ,
71+ then the server SHOULD emit a warning
72+ and SHOULD close the connection:
73+
74+ ```
75+ error Client does not support protocol solid/0.1.0-alpha
76+ ```
77+
78+ ### Subscription
79+ Then, the client needs to * sub* (scribe) to a given resource URI.
80+ If any change occurs in that resource,
81+ a * pub* (lish) event will be sent to all the subscribed clients.
3682
3783To subscribe to a resource, clients will need to send the keyword ` sub ` followed
3884by an empty space and then the URI of the resource:
@@ -77,11 +123,12 @@ Then the following notification message will be sent:
77123pub https://example.org/data/
78124```
79125
126+ ### Example
80127Here is a Javascript example on how to subscribe to live updates for a ` test `
81128resource at ` https://example.org/data/test ` :
82129
83130``` js
84- var socket = new WebSocket (' wss://example.org/' );
131+ var socket = new WebSocket (' wss://example.org/' , [ ' solid/0.1.0-alpha ' ] );
85132socket .onopen = function () {
86133 this .send (' sub https://example.org/data/test' );
87134};
0 commit comments