-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
268 lines (249 loc) · 12.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Web Thing Protocol</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" defer></script>
<script class="remove">
// All config options at https://respec.org/docs/
var respecConfig = {
specStatus: "CG-DRAFT",
editors: [{
name: "Ben Francis",
company: "Krellian",
mailto: "[email protected]",
companyURL: "https://krellian.com",
w3cid: "51527"
}],
github: "w3c/web-thing-protocol",
shortName: "web-thing-protocol",
xref: true,
group: "web-thing-protocol",
wgPublicList: "public-web-thing-protocol",
edDraftURI: "https://w3c.github.io/web-thing-protocol/",
latestVersion: "https://w3c.github.io/web-thing-protocol/"
};
</script>
</head>
<body>
<h1 id="title">Web Thing Protocol</h1>
<h2 id="subtitle">WebSocket Sub-protocol</h2>
<section id="abstract">
<p>This document defines a WebSocket sub-protocol called the Web Thing
Protocol, for monitoring and controlling connected devices over the
World Wide Web. The Web Thing Protocol is intended as a dedicated
real-time protocol for the <a href="https://www.w3.org/WoT/">Web of
Things</a>, to enable a WoT
<a href="https://www.w3.org/TR/wot-architecture/#dfn-consumer">Consumer</a>
to communicate with one or more WoT
<a href="https://www.w3.org/TR/wot-architecture/#dfn-web-thing">Things</a>
over a WebSocket connection.
</p>
</section>
<section id="sotd">
<aside class="ed-note" title="Empty Sections">
Please note that this document is a work in progress and contains empty
sections. For an indication of what these sections may eventually contain,
please see this
<a href="https://docs.google.com/document/d/1KWv-aQfMgsqBFg0v4rVqzcVvzzisC7y4X4CMUYGc8rE/edit?usp=sharing">strawman
proposal</a>.
</aside>
</section>
<section id="introduction" class="informative">
<h2>Introduction</h2>
<p>This document defines a WebSocket [[WEBSOCKETS-PROTOCOL]] sub-protocol for
monitoring and controlling connected devices over the Web.
</p>
<p>The <a href="https://www.w3.org/WoT/">Web of Things</a> (WoT) is a
collection of standardised technology building blocks that help provide
interoperability on the
<a href="https://en.wikipedia.org/wiki/Internet_of_things">Internet of
Things</a> (IoT). The WoT Thing Description specification
[[wot-thing-description11]] defines a metadata format for
<em>describing</em> the capabilities of "Things" (connected
devices) on the Web. The WoT Discovery specification [[wot-discovery]]
defines mechanisms for <em>discovering</em> Things on the Web. This
specification complements those building blocks by
defining a dedicated real-time protocol for <em>communicating</em> with Things over the
Web.
</p>
<p>WebSockets [[WEBSOCKETS-PROTOCOL]] provide a way to upgrade a
standard HTTP [[HTTP11]] request to a full-duplex, persistent, real-time
communication channel over a single TCP connection. This can be used to
create a versatile and efficient two-way channel with which a WoT
<a href="https://www.w3.org/TR/wot-architecture/#dfn-consumer">Consumer</a>
can communicate with one or more
<a href="https://www.w3.org/TR/wot-architecture/#dfn-web-thing">Things</a>
[[wot-architecture11]] to carry out the full set of WoT
<a href="https://www.w3.org/TR/wot-thing-description/#table-well-known-operation-types">operations</a>.
However, since a WebSocket is essentially just a raw TCP socket with no
semantics of its own, a sub-protocol needs to be defined in order for a
Consumer and Thing to communicate.
</p>
<p>Whilst many other <a href="https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name">WebSocket
sub-protocols</a> exist, what makes the Web Thing Protocol unique
is that it is specifically designed around the Web of Things
<a href="https://www.w3.org/TR/wot-thing-description11/#sec-vocabulary-definition">information
model</a> and
<a href="https://www.w3.org/TR/wot-thing-description11/#table-well-known-operation-types">set
of operations</a> [[wot-thing-description11]], as well as being
targeted specifically at Web of Things use cases [[wot-usecases]]. It
can therefore be thought of as being native to the Web of Things.
</p>
<p>
The sub-protocol defines message payload formats for each of the
well-known
<a href="https://www.w3.org/TR/wot-thing-description11/#table-well-known-operation-types">
operation types</a> defined in the WoT
<a href="https://www.w3.org/TR/wot-architecture/#sec-interaction-model">
interaction model</a> [[wot-architecture11]], and other messages needed for
WebSocket communication.
</p>
<p>
This specification is intended to complement deliverables of the
<a href="https://www.w3.org/WoT/wg/">WoT Working Group</a>, including WoT
Architecture [[wot-architecture11]], WoT Thing Description
[[wot-thing-description11]], WoT Discovery [[wot-discovery]],
WoT Binding Templates [[wot-binding-templates]] and WoT Profile
[[wot-profile]]. It is intended to implement use cases and requirements
defined in the
<a
href="https://www.w3.org/community/reports/web-thing-protocol/CG-FINAL-web-thing-protocol-requirements-20231101/">Web
Thing Protocol Use Cases & Requirements</a> community report.
</p>
<p>Whilst this document is not on a standards track, the Web Thing Protocol
is intended to eventually join a standards track at the W3C or another
standards body such as the IETF.
</p>
</section>
<section id="conformance">
</section>
<section id="terminology">
<h2>Terminology</h2>
<p>Fundamental WoT terminology such as <dfn>Thing</dfn> or <dfn>Web Thing</dfn>, <dfn>Consumer</dfn> or <dfn>WoT
Consumer</dfn>, WoT Thing Description or <dfn>Thing Description</dfn>, Interaction Model,
<dfn>Interaction Affordance</dfn>, Property, Action and Event are defined in
the
<a href="https://www.w3.org/TR/wot-architecture/#terminology">Terminology</a>
section of the WoT Architecture specification [[wot-architecture11]].
</p>
</section>
<section id="websocket-connection">
<h2>WebSocket Connection</h2>
<section id="protocol-handshake">
<h3>Protocol Handshake</h3>
<p>In order to communicate with a <a>Web Thing</a>,
a WoT <a>Consumer</a> [[wot-architecture11]] MUST
locate one or more WebSocket [[WEBSOCKETS-PROTOCOL]] endpoints provided by the <a>Thing</a> for a given set of
<a>Interaction Affordances</a>
[[wot-thing-description11]].
</p>
<p>The URL of a WebSocket endpoint to be used for a given interaction MUST be obtained from a <a>Thing
Description</a>
[[wot-architecture11]] by locating a <a href="https://www.w3.org/TR/wot-thing-description/#form">Form</a> inside
the corresponding <a>Interaction Affordance</a> for which:
<ul>
<li>After being resolved against a <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-base--Thing"><code>base</code></a> URL
[[wot-thing-description11]] where applicable, the URI scheme [[RFC3986]] of the value of its <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-href--Form"><code>href</code></a> member
[[wot-thing-description11]] is <code>"ws"</code> or &<code>"wss"</code></li>
<li>Its <a
href="https://www.w3.org/TR/wot-thing-description/#td-vocab-subprotocol--Form"><code>subprotocol</code></a>
member has a value of <code>"webthingprotocol"</code></li>
</ul>
</p>
<p>To open a WebSocket on a Thing, an HTTP <a
href="https://httpwg.org/specs/rfc9110.html#GET"><code>GET</code></a> request [[RFC9110]] MUST be upgraded to
a WebSocket connection using a standard WebSocket <a
href="https://www.rfc-editor.org/rfc/rfc6455#page-6">protocol handshake</a> [[WEBSOCKETS-PROTOCOL]],
specifying the "webthingprotocol" sub-protocol.
</p>
<pre class="example" title="WebSocket Protocol Handshake HTTP Request">
GET wss://mythingserver.com/things/robot
Host: mythingserver.com
Origin: https://mythingserver.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: webthingprotocol
Sec-WebSocket-Version: 13
</pre>
<pre class="example" title="WebSocket Protocol Handshake HTTP Response">
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: webthingprotocol
</pre>
<p class="ednote" title="Sub-protocol Name">
Sub-protocol name to be confirmed, see <a href="#iana-considerations">IANA Considerations</a>.
</p>
<p class="note">A WebSocket can be opened from a web page using the JavaScript WebSocket API [[WEBSOCKETS-API]]
which will take care of the handshake detailed above and allow messages to be sent and received.
</p>
<pre class="example" title="WebSocket Instantiation in JavaScript">
const socket = new WebSocket('wss://mywebthingserver/things/robot', 'webthingprotocol');
</pre>
</section>
<section id="websocket-reuse">
<h3>WebSocket Re-use</h3>
<p>A single WebSocket [[WEBSOCKETS-PROTOCOL]] connection from a <a>WoT Consumer</a> MAY be shared between multiple
<a>Interaction
Affordances</a> of a <a>Thing</a>. A single WebSocket connection from a <a>WoT Consumer</a> MAY also be shared
between multiple <a>Things</a>.</p>
<p>Before opening a new WebSocket connection, a <a>WoT Consumer</a> SHOULD check whether it already has an open
connection to the same WebSocket endpoint URL.</p>
<p>If an existing connection to the same WebSocket endpoint URL exists, then that connection SHOULD be re-used
rather than opening an additional socket.</p>
<p>If an existing connection to the same WebSocket endpoint URL exists but is using a different set of credentials
for its given <a
href="https://www.w3.org/TR/wot-thing-description11/#securityscheme"><code>SecurityScheme</code></a>
[[wot-thing-description11]] (e.g. a different Bearer Token), then the <a>WoT Consumer</a> MUST NOT re-use the
connection.</p>
</section>
</section>
<section id="websocket-messages">
<h2>WebSocket Messages</h2>
<section id="properties">
<h3>Properties</h3>
</section>
<section id="actions">
<h3>Actions</h3>
</section>
<section id="events">
<h3>Events</h3>
</section>
<section id="events">
<h3>Other Messages</h3>
</section>
</section>
<section id="example-thing-descriptions">
<h2>Example Thing Descriptions</h2>
</section>
<section id="privacy-considerations">
<h2>Privacy Considerations</h2>
</section>
<section id="security-considerations">
<h2>Security Considerations</h2>
</section>
<section id="accessibility-considerations">
<h2>Accessibility Considerations</h2>
</section>
<section id="iana-considerations">
<h2>IANA Considerations</h2>
<p>This specification proposes the registration of a sub-protocol in the IANA "<a
href="https://www.iana.org/assignments/websocket/websocket.xml">WebSocket Subprotocol Name Registry</a>".
The name of the sub-protocol and the published URL of its definition are to be confirmed, but currently the name
"webthingprotocol" and this document are used as a placeholder and draft proposal.</p>
<dl>
<dt>Subprotocol Identifier</dt>
<dd>webthingprotocol</dd>
<dt>Subprotocol Common Name</dt>
<dd>Web Thing Protocol</dd>
<dt>Subprotocol Definition</dt>
<dd>This document.</dd>
</dl>
</section>
</body>
</html>