4
4
[ Solid specification] ( README.md ) ; the parent spec and all its components are
5
5
versioned as a whole.
6
6
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
8
12
9
13
Live updates are currently only supported through WebSockets. This describes a
10
14
subscription mechanism through which clients can be notified in real time of
11
15
changes affecting a given resource.
12
16
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:
21
25
22
26
REQUEST:
23
27
@@ -31,8 +35,50 @@ RESPONSE:
31
35
``` http
32
36
HTTP/1.1 200 OK
33
37
...
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
+
35
56
```
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.
36
82
37
83
To subscribe to a resource, clients will need to send the keyword ` sub ` followed
38
84
by an empty space and then the URI of the resource:
@@ -77,11 +123,12 @@ Then the following notification message will be sent:
77
123
pub https://example.org/data/
78
124
```
79
125
126
+ ### Example
80
127
Here is a Javascript example on how to subscribe to live updates for a ` test `
81
128
resource at ` https://example.org/data/test ` :
82
129
83
130
``` js
84
- var socket = new WebSocket (' wss://example.org/' );
131
+ var socket = new WebSocket (' wss://example.org/' , [ ' solid/0.1.0-alpha ' ] );
85
132
socket .onopen = function () {
86
133
this .send (' sub https://example.org/data/test' );
87
134
};
0 commit comments