-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
402 lines (391 loc) · 16.8 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Device Access Sample App</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="application/javascript" src="api.js"></script>
<script type="application/javascript" src="app.js"></script>
<script type="application/javascript" src="auth.js"></script>
<script type="application/javascript" src="events.js"></script>
<script type="application/javascript" src="logger.js"></script>
<script type="application/javascript" src="ui.js"></script>
<script type="application/javascript" src="webrtc.js"></script>
<script type="application/javascript" src="third_party/kjur.min.js"></script>
</head>
<body>
<div class="grid-container">
<!-- App Header Panel -->
<div class="grid-item item-app-header">
<h1 style="margin: auto">Device Access - Sample App</h1>
<div class="h-help tip">
<img src="images/help.png" alt="Help">
<span id="tipSampleApp" class="tip-text">
Hover over each tip to learn more!
</span>
</div>
</div>
<!-- Account Linking Panel -->
<div class="grid-item item-account-linking">
<div class="box-container">
<div class="box-header">
<h2 id="hdrAccountLinking" class="hdr">Account Linking</h2>
<div class="hdr-help tip">
<img src="images/1.png" alt="?">
<span id="tipAccountLinking" class="tip-text">
1 - Account Linking is the first step for Device Access integration.
The app will follow <a href="https://developers.google.com/identity/protocols/oauth2">OAuth flow</a>
to retrieve user consent.
<br><br>
Client Id and Client Secret can be obtained from
<a href="https://console.cloud.google.com/apis/credentials">Google Cloud Platform</a>.
<br><br>
Project Id is the identifier of the project created in
<a href="https://console.nest.google.com/device-access/project-list">Device Access Console</a>.
<br><br>
The dropdown controls the target API, which will determine the endpoints
used for account linking and execution.
<br><br>
Completing OAuth flow and correctly signing in will enable the other controls.
</span>
</div>
</div>
<div class="box-content">
<input id="txtClientId" placeholder="< Client Id >" onkeyup="typeClientId()">
<br/><br/>
<input id="txtClientSecret" placeholder="< Client Secret >" onkeyup="typeClientSecret()">
<br/><br/>
<input id="txtProjectId" placeholder="< Project Id >" onkeyup="typeProjectId()">
</div>
<div class="box-buttons">
<button id="btnSignIn" onclick="clickSignIn();">Sign In</button>
</div>
</div>
<!-- Auth Token Panel -->
<div class="grid-item item-auth-tokens">
<table style="width:100%; text-align: center;">
<tr>
<td style="width:33%;"><img id="imgOAuthCode" src="images/empty.png" alt="Pending..." width="48" height="48"></td>
<td style="width:34%;"><img id="imgAccessToken" src="images/empty.png" alt="Pending..." width="48" height="48"></td>
<td style="width:33%;"><img id="imgRefreshToken" src="images/empty.png" alt="Pending..." width="48" height="48"></td>
</tr>
<tr>
<td id="hdrOAuthCode">OAuth Code</td>
<td id="hdrAccessToken">Access Token</td>
<td id="hdrRefreshToken">Refresh Token</td>
</tr>
<tr>
<td><button id="btnViewOAuthCode" onclick="clickViewOAuthCode();" style="margin-top: 5px;">View</button></td>
<td><button id="btnViewAccessToken" onclick="clickViewAccessToken();" style="margin-top: 5px;">View</button></td>
<td><button id="btnViewRefreshToken" onclick="clickViewRefreshToken();" style="margin-top: 5px;">View</button></td>
</tr>
</table>
</div>
</div>
<!-- Device Access Panel -->
<div class="grid-item item-device-access">
<div class="box-container">
<div class="box-header">
<h2 id="hdrDeviceAccess" class="hdr">Device Access</h2>
<div class="hdr-help tip">
<img src="images/2.png" alt="?">
<span id="tipDeviceAccess" class="tip-text">
2 - Device Access panel provides controls for subscribing to events,
accessing Resource Picker, as well as calling
<a href="https://developers.google.com/nest/device-access/reference/rest/v1/enterprises.devices/list">
ListDevices</a> and
<a href="https://developers.google.com/nest/device-access/reference/rest/v1/enterprises.structures/list">
ListStructures</a> methods.
<br><br>
Each time the page page is refreshed, the app will issue a ListDevices automatically.
</span>
</div>
</div>
<div class="box-buttons">
<button id="btnListDevices" onclick="clickListDevices();" style="margin-right: 10px;">List Devices</button>
<button id="btnListStructures" onclick="clickListStructures();" style="margin-right: 10px;">List Structures</button>
<button id="btnResourcePicker" onclick="clickResourcePicker();">Resource Picker</button>
</div>
</div>
<!-- Device Events Panel -->
<div class="grid-item item-device-events">
<div class="box-container">
<div class="box-header">
<h2 id="hdrDeviceEvents" class="hdr">Device Events</h2>
<div class="hdr-help tip">
<img src="images/3.png" alt="?">
<span id="tipDeviceEvents" class="tip-text">
3 - Events (Optional) allow you to receive asynchronous activity associated with
target devices. To subscribe to events, you need to provide a
<a href="https://cloud.google.com/iam/docs/creating-managing-service-account-keys">Service Account Key</a>
and a <a href="https://cloud.google.com/pubsub/docs/admin">Subscription Id</a>.
<br><br>
Your Service Account Key is used locally to sign the pub-sub requests. It does not leave the browser.
</span>
</div>
</div>
<div class="box-content">
<input id="txtSubscriptionId" type="string" placeholder="< Subscription Id >" onkeyup="typeSubscriptionId()">
<br/><br/>
<textarea id="txtServiceAccountKey" placeholder="< Service Account Key >" onkeyup="typeServiceAccountKey()"
rows="6"></textarea>
<br/><br/>
<div>
<button id="btnSubscribe" onclick="clickSubscribe();" style="margin-right: 6px;">Subscribe</button>
<button id="btnGetEvents" onclick="clickGetEvents();">Get Events</button>
</div>
</div>
</div>
</div>
</div>
<!-- Device Control Panel -->
<div class="grid-item item-device-control">
<div class="box-container">
<div id="deviceControlDiv" class="box-header">
<h2 id="hdrDeviceControl" class="hdr">Device Control</h2>
<div class="hdr-help tip">
<img src="images/4.png" alt="?">
<span id="tipDeviceControl" class="tip-text">
4 - Device Control panel provides controls for devices linked to the user.
You can chose the device from the dropdown.
<br><br>
Currently devices supported are Nest
<a href="https://developers.google.com/nest/device-access/api/thermostat">Thermostat</a>,
<a href="https://developers.google.com/nest/device-access/api/camera">Camera</a> and
<a href="https://developers.google.com/nest/device-access/api/doorbell">Doorbell</a>.
</span>
</div>
</div>
<div class="box-content">
<!-- Device Selector -->
<select id="sctDeviceList" onchange="selectDevice()">
<option value="" disabled selected hidden>< No Devices ></option>
</select>
<br>
<br>
<!-- Thermostat Control -->
<div id="thermostat-control" class="thermostat-control" hidden>
<img id="imgThermostat" src="images/thermostat.png" alt="Thermostat" width="96" height="96">
<br>
<br>
<table style="margin: auto;">
<td style="width: 125px; vertical-align: top; text-align: center">
<button id="btnFanMode" onclick="clickFanMode();">Activate Fan</button>
<br><br>
<select id="sctThermostatMode" style="height: 27px; width: 98px;">
<option value="OFF">Off</option>
<option value="HEAT">Heat</option>
<option value="COOL">Cool</option>
<option value="HEATCOOL">HeatCool</option>
</select>
<br><br>
<button id="btnThermostatMode" onclick="clickThermostatMode();">Change Mode</button>
</td>
<td style="text-align: center">
<div id="heatDiv">
<input id="txtHeatTemperature" class="text-temp" placeholder="< Heat >">
<div id="heatUnit" class="text-unit">°C</div>
</div>
<br>
<div id="coolDiv">
<input id="txtCoolTemperature" class="text-temp" placeholder="< Cool >">
<div id="coolUnit" class="text-unit">°C</div>
</div>
<br>
<button id="btnTemperatureSetpoint" onclick="clickTemperatureSetpoint();">Set Temperature</button>
</td>
</table>
</div>
<!-- Camera Control -->
<div id="camera-control" class="camera-control" hidden>
<img id="imgCamera" src="images/camera.png" alt="Camera" width="96" height="96">
<br>
<br>
<table style="margin: auto;">
<td style="width: 125px;">
<button onclick="clickGenerateStream();">Camera Stream</button>
<br><br>
<button onclick="clickExtendStream();">Refresh Stream</button>
<br><br>
<button onclick="clickStopStream();">Stop Stream</button>
</td>
<td>
<textarea id="txtExtensionToken1" class="text-area" placeholder="< Extension Token >" rows="8" readonly></textarea>
</td>
</table>
</div>
<!-- Doorbell Control -->
<div id="doorbell-control" class="camera-control" hidden>
<img id="imgDoorbell" src="images/doorbell.png" alt="Doorbell" width="96" height="96">
<br>
<br>
<table style="margin: auto;">
<td style="width: 125px;">
<button onclick="clickGenerateStream();">Camera Stream</button>
<br><br>
<button onclick="clickExtendStream();">Refresh Stream</button>
<br><br>
<button onclick="clickStopStream();">Stop Stream</button>
</td>
<td>
<div style="text-align: center;">Extension Token</div>
<br>
<textarea id="txtExtensionToken2" class="text-area" placeholder="< Extension Token >" rows="8" readonly></textarea>
</td>
</table>
</div>
<!-- Camera Control (WebRTC) -->
<div id="camera-webrtc-control" class="camera-control" hidden>
<img id="imgCameraWebRTC" src="images/camera-webrtc.png" alt="Camera" width="96" height="96">
<br>
<br>
<table style="margin: auto;">
<td style="width: 125px;">
<button onclick="clickGenerateStream_WebRTC();">Camera Stream</button>
<br><br>
<button onclick="clickExtendStream_WebRTC();">Refresh Stream</button>
<br><br>
<button onclick="clickStopStream_WebRTC();">Stop Stream</button>
</td>
<td>
<textarea id="txtExtensionToken3" class="text-area" style="height: 28px;" placeholder="< Media Session ID >" rows="2" readonly></textarea>
<br><br>
<textarea id="txtOfferSDPCamera" style="width: 100%; height: 28px;" placeholder="< Offer SDP >" rows="1" readonly></textarea>
</td>
</table>
</div>
<!-- Doorbell Control (WebRTC) -->
<div id="doorbell-webrtc-control" class="camera-control" hidden>
<img id="imgDoorbellWebRTC" src="images/doorbell-webrtc.png" alt="Doorbell" width="96" height="96">
<br>
<br>
<table style="margin: auto;">
<td style="width: 125px;">
<button onclick="clickGenerateStream_WebRTC();">Camera Stream</button>
<br><br>
<button onclick="clickExtendStream_WebRTC();">Refresh Stream</button>
<br><br>
<button onclick="clickStopStream_WebRTC();">Stop Stream</button>
</td>
<td>
<textarea id="txtExtensionToken4" class="text-area" style="height: 28px;" placeholder="< Media Session ID >" rows="2" readonly></textarea>
<br><br>
<textarea id="txtOfferSDPDoorbell" style="width: 100%; height: 28px;" placeholder="< Offer SDP >" rows="1" readonly></textarea>
</td>
</table>
</div>
</div>
</div>
</div>
<!-- Analytics Panel -->
<div class="grid-item item-analytics">
<div class="box-container">
<div class="box-header">
<h2 id="hdrAnalytics" class="hdr">Analytics</h2>
</div>
<table id="analyticsTable">
<tr>
<td>
<div class="analytics-row-label">
<p>Initialize WebRTC =><br>
setLocalDescription</p>
</div>
</td>
<td>
<div class="analytics-row-label">
<p>Send SDP Offer =><br>
Receive SDP Answer</p>
</div>
</td>
<td>
<div class="analytics-row-label">
<p>Receive SDP Answer =><br>
Connected</p>
</div>
</td>
<td>
<div class="analytics-row-label">
<p>Connected =><br>
Playback started</p>
</div>
</td>
</tr>
<tr>
<td>
<div class="analytics-row-value">
<p id="analyticsInitialized">-</p>
</div>
</td>
<td>
<div class="analytics-row-value">
<p id="analyticsAnswerReceived">-</p>
</div>
</td>
<td>
<div class="analytics-row-value">
<p id="analyticsConnected">-</p>
</div>
</td>
<td>
<div class="analytics-row-value">
<p id="analyticsPlaybackStarted">-</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<!-- Application Logs Panel -->
<div class="grid-item item-log-list">
<div class="box-container">
<div class="box-header">
<h2 id="hdrApplicationLogs" class="hdr">Application Logs</h2>
<div class="hdr-help tip">
<img src="images/5.png" alt="?">
<span id="tipApplicationLogs" class="tip-text">
5 - Application Logs provide logs for each interaction captured by this application.
<br><br>
Logs are categorized into three groups: actions happened within the app,
HTTP requests and pub-sub events.
</span>
</div>
</div>
<div class="box-content">
<div id="log-filters" class="log-filters">
<button id="btnFilterAction" class="button-filter filter-action" onclick="onFilterAction();">Action</button>
<button id="btnFilterHTTP" class="button-filter filter-http" onclick="onFilterHTTP();">HTTP</button>
<button id="btnFilterEvent" class="button-filter filter-event" onclick="onFilterEvent();">Event</button>
</div>
<div id="log-container" class="log-container">
<!-- Log entries generated dynamically from the template. -->
</div>
</div>
<div class="box-buttons">
<button onclick="clickClearLogs();">Clear</button>
</div>
</div>
</div>
<!-- Log Descriptions Panel -->
<div class="grid-item item-log-description">
<div id="log-header" class="log-header">
<h3 id="log-title" class="log-title"></h3>
<div id="empty-space"></div>
<h5 id="log-time" class="log-time"></h5>
<h5 id="log-type" class="log-type"></h5>
</div>
<div id="log-text" class="log-text">
</div>
<div id="log-video" class="log-video" hidden>
<video id="video-stream" autoplay playsinline hidden></video>
</div>
</div>
</div>
</body>
<!-- Log Entry Template -->
<template>
<div class="log-entry"></div>
</template>
<!-- Initializing JavaScript -->
<script type="application/javascript">
init();
</script>
</html>