MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / connected

Function connected

tools/testmc/main.js:156–182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

154
155globalThis.$NETWORK = {
156 get connected() {
157 const WiFi = Modules.importNow("embedded:network/interface/wifi");
158
159 assert(!!config.ssid, "Wi-Fi SSID missing");
160 return new Promise((resolve, reject) => {
161 const w = new WiFi({
162 onChanged(property) {
163 if (this.address) {
164 Timer.clear(this.timer);
165 this.close();
166 resolve();
167 }
168 }
169 });
170 if (w.address) {
171 resolve();
172 return void w.close();
173 }
174
175 trace(`Connecting to Wi-Fi SSID "${config.ssid}"...\n`);
176 w.connect(config.password ? {SSID: config.ssid, password: config.password, secure: true} : {SSID: config.ssid});
177 w.timer = Timer.set(() => {
178 w.close();
179 $DONE("Wi-Fi connection attempt timed out");
180 }, $TESTMC.wifiConnectionTimeout);
181 });
182 },
183 async wifi(options) {
184 // could be async to allow time to bring up an AP
185 return {ssid: config.ssid, password: config.password};

Callers

nothing calls this directly

Calls 6

closeMethod · 0.95
connectMethod · 0.95
importNowMethod · 0.80
assertFunction · 0.70
resolveFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected