@improv-wifi/serial-sdk 0.0.0-stage → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +114 -2
- package/dist/const.d.ts +56 -0
- package/dist/const.js +37 -0
- package/dist/provision.d.ts +2 -0
- package/dist/provision.js +26 -0
- package/dist/serial-launch-button.d.ts +7 -0
- package/dist/serial-launch-button.js +79 -0
- package/dist/serial-provision-dialog.d.ts +53 -0
- package/dist/serial-provision-dialog.js +691 -0
- package/dist/serial.d.ts +143 -0
- package/dist/serial.js +626 -0
- package/dist/util/fire-event.d.ts +5 -0
- package/dist/util/fire-event.js +12 -0
- package/dist/util/hex-formatter.d.ts +1 -0
- package/dist/util/hex-formatter.js +2 -0
- package/dist/util/to-hex.d.ts +1 -0
- package/dist/util/to-hex.js +9 -0
- package/dist/web/serial-launch-button.js +1 -0
- package/dist/web/serial-provision-dialog-DR-raZEr.js +803 -0
- package/package.json +36 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# JavaScript SDK for Improv Wi-Fi over Serial
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
If you are using a bundler and JavaScript package manager, you can install the SDK via NPM:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install --save @improv-wifi/serial-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
And then import it in your code:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
import '@improv-wifi/serial-sdk';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add the following to your website to show a button to start the provisioning process:
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<improv-wifi-serial-launch-button></improv-wifi-serial-launch-button>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
A warning message will be rendered if the browser does not support WebSerial.
|
|
26
|
+
|
|
27
|
+
The SDK will render an error when the connected device does not support Improv. If it is opt-in for your software, you can set a link as the `learnMoreUrl` attribute to include this link in the error message.
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<improv-wifi-serial-launch-button
|
|
31
|
+
learnMoreUrl="https://www.esphome.io/components/improv_serial.html"
|
|
32
|
+
></improv-wifi-serial-launch-button>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Attributes
|
|
36
|
+
|
|
37
|
+
The following attributes are automatically added to `<improv-wifi-serial-launch-button>` and can be used for styling:
|
|
38
|
+
|
|
39
|
+
| Attribute | Description |
|
|
40
|
+
| -- | -- |
|
|
41
|
+
| `supported` | Added if this browser is supported
|
|
42
|
+
| `unsupported` | Added if this browser is not supported
|
|
43
|
+
|
|
44
|
+
### Slots
|
|
45
|
+
|
|
46
|
+
It is possible to customize the button and the message. You do this by putting your elements inside the `<improv-wifi-serial-launch-button>` element and adding the appropriate `slot` attribute. Use `activate` to replace the activation button and `unsupported` to replace the unsupported message:
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<improv-wifi-serial-launch-button>
|
|
50
|
+
<button slot='activate'>Start provisioning!</button>
|
|
51
|
+
<span slot='unsupported'>Your browser does not support provisioning.</span>
|
|
52
|
+
</improv-wifi-serial-launch-button>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Events
|
|
56
|
+
|
|
57
|
+
When the dialog is closed, a `closed` event will be fired on both `<improv-wifi-serial-launch-button>` and `<improv-wifi-serial-provision-dialog>`. This event will have a `detail` property with the following properties:
|
|
58
|
+
|
|
59
|
+
- `improv`: Boolean indicating if we connected to a device running Improv.
|
|
60
|
+
- `provisioned`: Boolean indicating if the device is connected to Wi-Fi.
|
|
61
|
+
|
|
62
|
+
## Browser Support
|
|
63
|
+
|
|
64
|
+
This SDK requires a browser with support for WebSerial. Currently this is supported by Google Chrome, Microsoft Edge and other browsers based on the Blink engine.
|
|
65
|
+
|
|
66
|
+
No iOS devices are supported.
|
|
67
|
+
|
|
68
|
+
## Standalone usage
|
|
69
|
+
|
|
70
|
+
The serial SDK can also be used standalone without the UI.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { ImprovSerial } from "@improv-wifi/serial-sdk/dist/serial.ts";
|
|
74
|
+
|
|
75
|
+
const port = await navigator.serial.requestPort();
|
|
76
|
+
await port.open({ baudRate: 115200 });
|
|
77
|
+
const improv = new ImprovSerial(port, console);
|
|
78
|
+
|
|
79
|
+
improv.addEventListener("state-changed", console.log);
|
|
80
|
+
improv.addEventListener("error-changed", console.log);
|
|
81
|
+
improv.addEventListener("network-state-changed", console.log);
|
|
82
|
+
|
|
83
|
+
await improv.initialize();
|
|
84
|
+
|
|
85
|
+
improv.addEventListener("disconnect", console.log);
|
|
86
|
+
|
|
87
|
+
// Optional: keeps `improv.networkState` fresh (e.g. an Ethernet link coming up).
|
|
88
|
+
improv.startNetworkStatePolling();
|
|
89
|
+
|
|
90
|
+
console.log({
|
|
91
|
+
info: improv.info,
|
|
92
|
+
nextUrl: improv.nextUrl,
|
|
93
|
+
networkState: improv.networkState,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await improv.provision(
|
|
97
|
+
"My Wifi",
|
|
98
|
+
"My password",
|
|
99
|
+
30000 // Optional: Timeout in ms
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The hostname and device name can be read and written while the device is authorized. Each method takes an optional timeout in ms as its last argument, and the setters return the value as it was applied by the device.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const hostname = await improv.getHostname();
|
|
107
|
+
await improv.setHostname("my-device");
|
|
108
|
+
|
|
109
|
+
const deviceName = await improv.getDeviceName();
|
|
110
|
+
await improv.setDeviceName("My Device");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Hostnames need to conform to [RFC 1123](https://datatracker.ietf.org/doc/html/rfc1123): letters, numbers and hyphens, up to 255 characters. `setHostname` rejects with `BAD_HOSTNAME` if the device does not accept the hostname.
|
|
114
|
+
|
|
115
|
+
If you set both, set the device name first, as it can change the default hostname.
|
package/dist/const.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
log(msg: string, ...args: any[]): void;
|
|
3
|
+
error(msg: string, ...args: any[]): void;
|
|
4
|
+
debug(msg: string, ...args: any[]): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const SERIAL_PACKET_HEADER: number[];
|
|
7
|
+
export type State = "CONNECTING" | "IMPROV-STATE" | "ERROR";
|
|
8
|
+
export declare enum ImprovSerialMessageType {
|
|
9
|
+
CURRENT_STATE = 1,// Device to client
|
|
10
|
+
ERROR_STATE = 2,// Device to client
|
|
11
|
+
RPC = 3,// Client to device
|
|
12
|
+
RPC_RESULT = 4
|
|
13
|
+
}
|
|
14
|
+
export declare enum ImprovSerialCurrentState {
|
|
15
|
+
STOPPED = 0,// Provisioning unavailable (e.g. Wi-Fi disabled on the device)
|
|
16
|
+
READY = 2,// Authorized
|
|
17
|
+
PROVISIONING = 3,
|
|
18
|
+
PROVISIONED = 4
|
|
19
|
+
}
|
|
20
|
+
export declare const enum ImprovSerialErrorState {
|
|
21
|
+
NO_ERROR = 0,
|
|
22
|
+
INVALID_RPC_PACKET = 1,
|
|
23
|
+
UNKNOWN_RPC_COMMAND = 2,
|
|
24
|
+
UNABLE_TO_CONNECT = 3,
|
|
25
|
+
BAD_HOSTNAME = 5,// provided hostname is not acceptable
|
|
26
|
+
TIMEOUT = 254,
|
|
27
|
+
UNKNOWN_ERROR = 255
|
|
28
|
+
}
|
|
29
|
+
export declare const ERROR_MSGS: {
|
|
30
|
+
0: string;
|
|
31
|
+
1: string;
|
|
32
|
+
2: string;
|
|
33
|
+
3: string;
|
|
34
|
+
5: string;
|
|
35
|
+
254: string;
|
|
36
|
+
255: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const enum ImprovSerialRPCCommand {
|
|
39
|
+
SEND_WIFI_SETTINGS = 1,
|
|
40
|
+
REQUEST_CURRENT_STATE = 2,
|
|
41
|
+
REQUEST_INFO = 3,
|
|
42
|
+
REQUEST_WIFI_NETWORKS = 4,
|
|
43
|
+
HOSTNAME = 5,
|
|
44
|
+
DEVICE_NAME = 6,
|
|
45
|
+
REQUEST_NETWORK_STATE = 7
|
|
46
|
+
}
|
|
47
|
+
export declare const enum ImprovNetworkFlag {
|
|
48
|
+
IS_ONLINE = 1,// online via any interface
|
|
49
|
+
SUPPORTS_WIFI = 2,// present, possibly disabled
|
|
50
|
+
SUPPORTS_ETHERNET = 4,
|
|
51
|
+
SUPPORTS_THREAD = 8,
|
|
52
|
+
SUPPORTS_MODEM = 16
|
|
53
|
+
}
|
|
54
|
+
export declare class PortNotReady extends Error {
|
|
55
|
+
constructor();
|
|
56
|
+
}
|
package/dist/const.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const SERIAL_PACKET_HEADER = [
|
|
2
|
+
"I".charCodeAt(0),
|
|
3
|
+
"M".charCodeAt(0),
|
|
4
|
+
"P".charCodeAt(0),
|
|
5
|
+
"R".charCodeAt(0),
|
|
6
|
+
"O".charCodeAt(0),
|
|
7
|
+
"V".charCodeAt(0),
|
|
8
|
+
1, // protocol version
|
|
9
|
+
];
|
|
10
|
+
export var ImprovSerialMessageType;
|
|
11
|
+
(function (ImprovSerialMessageType) {
|
|
12
|
+
ImprovSerialMessageType[ImprovSerialMessageType["CURRENT_STATE"] = 1] = "CURRENT_STATE";
|
|
13
|
+
ImprovSerialMessageType[ImprovSerialMessageType["ERROR_STATE"] = 2] = "ERROR_STATE";
|
|
14
|
+
ImprovSerialMessageType[ImprovSerialMessageType["RPC"] = 3] = "RPC";
|
|
15
|
+
ImprovSerialMessageType[ImprovSerialMessageType["RPC_RESULT"] = 4] = "RPC_RESULT";
|
|
16
|
+
})(ImprovSerialMessageType || (ImprovSerialMessageType = {}));
|
|
17
|
+
export var ImprovSerialCurrentState;
|
|
18
|
+
(function (ImprovSerialCurrentState) {
|
|
19
|
+
ImprovSerialCurrentState[ImprovSerialCurrentState["STOPPED"] = 0] = "STOPPED";
|
|
20
|
+
ImprovSerialCurrentState[ImprovSerialCurrentState["READY"] = 2] = "READY";
|
|
21
|
+
ImprovSerialCurrentState[ImprovSerialCurrentState["PROVISIONING"] = 3] = "PROVISIONING";
|
|
22
|
+
ImprovSerialCurrentState[ImprovSerialCurrentState["PROVISIONED"] = 4] = "PROVISIONED";
|
|
23
|
+
})(ImprovSerialCurrentState || (ImprovSerialCurrentState = {}));
|
|
24
|
+
export const ERROR_MSGS = {
|
|
25
|
+
0x00: "NO_ERROR",
|
|
26
|
+
0x01: "INVALID_RPC_PACKET",
|
|
27
|
+
0x02: "UNKNOWN_RPC_COMMAND",
|
|
28
|
+
0x03: "UNABLE_TO_CONNECT",
|
|
29
|
+
0x05: "BAD_HOSTNAME",
|
|
30
|
+
0xfe: "TIMEOUT",
|
|
31
|
+
0xff: "UNKNOWN_ERROR",
|
|
32
|
+
};
|
|
33
|
+
export class PortNotReady extends Error {
|
|
34
|
+
constructor() {
|
|
35
|
+
super("Port is not ready");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { fireEvent } from "./util/fire-event.js";
|
|
2
|
+
export const startProvisioning = async (button) => {
|
|
3
|
+
import("./serial-provision-dialog.js");
|
|
4
|
+
let port;
|
|
5
|
+
try {
|
|
6
|
+
port = await navigator.serial.requestPort();
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
if (err.name === "NotFoundError") {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
alert(`Error: ${err.message}`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!port) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
await port.open({ baudRate: 115200 });
|
|
19
|
+
const el = document.createElement("improv-wifi-serial-provision-dialog");
|
|
20
|
+
el.port = port;
|
|
21
|
+
el.addEventListener("closed", async (ev) => {
|
|
22
|
+
await port.close();
|
|
23
|
+
fireEvent(button, "closed", ev.detail);
|
|
24
|
+
}, { once: true });
|
|
25
|
+
document.body.appendChild(el);
|
|
26
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { startProvisioning } from "./provision";
|
|
2
|
+
export class SerialLaunchButton extends HTMLElement {
|
|
3
|
+
connectedCallback() {
|
|
4
|
+
if (this.renderRoot) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
this.renderRoot = this.attachShadow({ mode: "open" });
|
|
8
|
+
if (!SerialLaunchButton.isSupported || !SerialLaunchButton.isAllowed) {
|
|
9
|
+
this.toggleAttribute("not-supported", true);
|
|
10
|
+
this.renderRoot.innerHTML = !SerialLaunchButton.isAllowed
|
|
11
|
+
? "<slot name='not-allowed'>You can only use Improv on HTTPS sites or localhost.</slot>"
|
|
12
|
+
: "<slot name='unsupported'>Your browser does not support serial provisioning. Use Google Chrome or Microsoft Edge.</slot>";
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.toggleAttribute("supported", true);
|
|
16
|
+
const slot = document.createElement("slot");
|
|
17
|
+
slot.name = "activate";
|
|
18
|
+
const button = document.createElement("button");
|
|
19
|
+
button.innerText = "Connect device to Wi-Fi";
|
|
20
|
+
slot.append(button);
|
|
21
|
+
slot.addEventListener("click", async (ev) => {
|
|
22
|
+
ev.preventDefault();
|
|
23
|
+
startProvisioning(this);
|
|
24
|
+
});
|
|
25
|
+
if ("adoptedStyleSheets" in Document.prototype &&
|
|
26
|
+
"replaceSync" in CSSStyleSheet.prototype) {
|
|
27
|
+
const sheet = new CSSStyleSheet();
|
|
28
|
+
sheet.replaceSync(SerialLaunchButton.style);
|
|
29
|
+
this.renderRoot.adoptedStyleSheets = [sheet];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const styleSheet = document.createElement("style");
|
|
33
|
+
styleSheet.innerText = SerialLaunchButton.style;
|
|
34
|
+
this.renderRoot.append(styleSheet);
|
|
35
|
+
}
|
|
36
|
+
this.renderRoot.append(slot);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
SerialLaunchButton.isSupported = "serial" in navigator;
|
|
40
|
+
SerialLaunchButton.isAllowed = window.isSecureContext;
|
|
41
|
+
SerialLaunchButton.style = `
|
|
42
|
+
button {
|
|
43
|
+
position: relative;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
font-size: 14px;
|
|
46
|
+
padding: 8px 28px;
|
|
47
|
+
color: var(--improv-on-primary-color, #fff);
|
|
48
|
+
background-color: var(--improv-primary-color, #03a9f4);
|
|
49
|
+
border: none;
|
|
50
|
+
border-radius: 4px;
|
|
51
|
+
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12), 0 1px 5px 0 rgba(0,0,0,.2);
|
|
52
|
+
}
|
|
53
|
+
button::before {
|
|
54
|
+
content: " ";
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 0;
|
|
57
|
+
bottom: 0;
|
|
58
|
+
left: 0;
|
|
59
|
+
right: 0;
|
|
60
|
+
opacity: 0.2;
|
|
61
|
+
border-radius: 4px;
|
|
62
|
+
}
|
|
63
|
+
button:hover {
|
|
64
|
+
box-shadow: 0 4px 8px 0 rgba(0,0,0,.14), 0 1px 7px 0 rgba(0,0,0,.12), 0 3px 1px -1px rgba(0,0,0,.2);
|
|
65
|
+
}
|
|
66
|
+
button:hover::before {
|
|
67
|
+
background-color: rgba(255,255,255,.8);
|
|
68
|
+
}
|
|
69
|
+
button:focus {
|
|
70
|
+
outline: none;
|
|
71
|
+
}
|
|
72
|
+
button:focus::before {
|
|
73
|
+
background-color: white;
|
|
74
|
+
}
|
|
75
|
+
button:active::before {
|
|
76
|
+
background-color: grey;
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
customElements.define("improv-wifi-serial-launch-button", SerialLaunchButton);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { LitElement, PropertyValues, TemplateResult } from "lit";
|
|
2
|
+
import "@material/web/dialog/dialog.js";
|
|
3
|
+
import "@material/web/iconbutton/filled-tonal-icon-button.js";
|
|
4
|
+
import "@material/web/iconbutton/icon-button.js";
|
|
5
|
+
import "@material/web/textfield/outlined-text-field.js";
|
|
6
|
+
import "@material/web/button/outlined-button.js";
|
|
7
|
+
import "@material/web/button/filled-button.js";
|
|
8
|
+
import "@material/web/progress/circular-progress.js";
|
|
9
|
+
import "@material/web/select/outlined-select.js";
|
|
10
|
+
import "@material/web/select/select-option.js";
|
|
11
|
+
import "@material/web/list/list.js";
|
|
12
|
+
import "@material/web/list/list-item.js";
|
|
13
|
+
import { Logger } from "./const.js";
|
|
14
|
+
declare class SerialProvisionDialog extends LitElement {
|
|
15
|
+
port?: SerialPort;
|
|
16
|
+
logger: Logger;
|
|
17
|
+
learnMoreUrl?: TemplateResult;
|
|
18
|
+
private _state;
|
|
19
|
+
private _client?;
|
|
20
|
+
private _busy;
|
|
21
|
+
private _error?;
|
|
22
|
+
private _selectedSsid;
|
|
23
|
+
private _ssids?;
|
|
24
|
+
private _showPassword;
|
|
25
|
+
private _reprovision;
|
|
26
|
+
private _unsubSSIDs?;
|
|
27
|
+
private _selectSSID;
|
|
28
|
+
private _inputSSID;
|
|
29
|
+
private _inputPassword?;
|
|
30
|
+
protected render(): TemplateResult<1>;
|
|
31
|
+
_renderCloseAction(): TemplateResult<1>;
|
|
32
|
+
_renderProgress(label: string): TemplateResult<1>;
|
|
33
|
+
_renderMessage(icon: string, label: string): TemplateResult<1>;
|
|
34
|
+
_renderImprovReady(): TemplateResult<1>;
|
|
35
|
+
_renderDeviceInfo(): TemplateResult;
|
|
36
|
+
private _togglePasswordVisibility;
|
|
37
|
+
private get _showConfigureForm();
|
|
38
|
+
private _syncScanning;
|
|
39
|
+
private _stopScanning;
|
|
40
|
+
private _provision;
|
|
41
|
+
private _changeWifi;
|
|
42
|
+
protected updated(changedProps: PropertyValues): void;
|
|
43
|
+
private _connect;
|
|
44
|
+
private _handleClose;
|
|
45
|
+
disconnectedCallback(): void;
|
|
46
|
+
static styles: import("lit").CSSResult;
|
|
47
|
+
}
|
|
48
|
+
declare global {
|
|
49
|
+
interface HTMLElementTagNameMap {
|
|
50
|
+
"improv-wifi-serial-provision-dialog": SerialProvisionDialog;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {};
|