Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

719 lines
20 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. /*
  2. WEBSOCKET MODULE
  3. Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include "ws.h"
  6. #if WEB_SUPPORT
  7. #include <vector>
  8. #include "system.h"
  9. #include "web.h"
  10. #include "ntp.h"
  11. #include "utils.h"
  12. #include "ws_internal.h"
  13. #include "libs/WebSocketIncommingBuffer.h"
  14. AsyncWebSocket _ws("/ws");
  15. Ticker _ws_defer;
  16. uint32_t _ws_last_update = 0;
  17. // -----------------------------------------------------------------------------
  18. // WS callbacks
  19. // -----------------------------------------------------------------------------
  20. std::queue<WsPostponedCallbacks> _ws_queue;
  21. ws_callbacks_t _ws_callbacks;
  22. void wsPost(uint32_t client_id, ws_on_send_callback_f&& cb) {
  23. _ws_queue.emplace(client_id, std::move(cb));
  24. }
  25. void wsPost(ws_on_send_callback_f&& cb) {
  26. wsPost(0, std::move(cb));
  27. }
  28. void wsPost(uint32_t client_id, const ws_on_send_callback_f& cb) {
  29. _ws_queue.emplace(client_id, cb);
  30. }
  31. void wsPost(const ws_on_send_callback_f& cb) {
  32. wsPost(0, cb);
  33. }
  34. template <typename T>
  35. void _wsPostCallbacks(uint32_t client_id, T&& cbs, WsPostponedCallbacks::Mode mode) {
  36. _ws_queue.emplace(client_id, std::forward<T>(cbs), mode);
  37. }
  38. void wsPostAll(uint32_t client_id, ws_on_send_callback_list_t&& cbs) {
  39. _wsPostCallbacks(client_id, std::move(cbs), WsPostponedCallbacks::Mode::All);
  40. }
  41. void wsPostAll(ws_on_send_callback_list_t&& cbs) {
  42. wsPostAll(0, std::move(cbs));
  43. }
  44. void wsPostAll(uint32_t client_id, const ws_on_send_callback_list_t& cbs) {
  45. _wsPostCallbacks(client_id, cbs, WsPostponedCallbacks::Mode::All);
  46. }
  47. void wsPostAll(const ws_on_send_callback_list_t& cbs) {
  48. wsPostAll(0, cbs);
  49. }
  50. void wsPostSequence(uint32_t client_id, ws_on_send_callback_list_t&& cbs) {
  51. _wsPostCallbacks(client_id, std::move(cbs), WsPostponedCallbacks::Mode::Sequence);
  52. }
  53. void wsPostSequence(ws_on_send_callback_list_t&& cbs) {
  54. wsPostSequence(0, std::move(cbs));
  55. }
  56. void wsPostSequence(uint32_t client_id, const ws_on_send_callback_list_t& cbs) {
  57. _wsPostCallbacks(client_id, cbs, WsPostponedCallbacks::Mode::Sequence);
  58. }
  59. void wsPostSequence(const ws_on_send_callback_list_t& cbs) {
  60. wsPostSequence(0, cbs);
  61. }
  62. // -----------------------------------------------------------------------------
  63. ws_callbacks_t& ws_callbacks_t::onVisible(ws_on_send_callback_f cb) {
  64. on_visible.push_back(cb);
  65. return *this;
  66. }
  67. ws_callbacks_t& ws_callbacks_t::onConnected(ws_on_send_callback_f cb) {
  68. on_connected.push_back(cb);
  69. return *this;
  70. }
  71. ws_callbacks_t& ws_callbacks_t::onData(ws_on_send_callback_f cb) {
  72. on_data.push_back(cb);
  73. return *this;
  74. }
  75. ws_callbacks_t& ws_callbacks_t::onAction(ws_on_action_callback_f cb) {
  76. on_action.push_back(cb);
  77. return *this;
  78. }
  79. ws_callbacks_t& ws_callbacks_t::onKeyCheck(ws_on_keycheck_callback_f cb) {
  80. on_keycheck.push_back(cb);
  81. return *this;
  82. }
  83. // -----------------------------------------------------------------------------
  84. // WS authentication
  85. // -----------------------------------------------------------------------------
  86. WsTicket _ws_tickets[WS_BUFFER_SIZE];
  87. void _onAuth(AsyncWebServerRequest *request) {
  88. webLog(request);
  89. if (!webAuthenticate(request)) return request->requestAuthentication();
  90. IPAddress ip = request->client()->remoteIP();
  91. unsigned long now = millis();
  92. unsigned short index;
  93. for (index = 0; index < WS_BUFFER_SIZE; index++) {
  94. if (_ws_tickets[index].ip == ip) break;
  95. if (_ws_tickets[index].timestamp == 0) break;
  96. if (now - _ws_tickets[index].timestamp > WS_TIMEOUT) break;
  97. }
  98. if (index == WS_BUFFER_SIZE) {
  99. request->send(429);
  100. } else {
  101. _ws_tickets[index].ip = ip;
  102. _ws_tickets[index].timestamp = now;
  103. request->send(200, "text/plain", "OK");
  104. }
  105. }
  106. bool _wsAuth(AsyncWebSocketClient * client) {
  107. IPAddress ip = client->remoteIP();
  108. unsigned long now = millis();
  109. unsigned short index = 0;
  110. for (index = 0; index < WS_BUFFER_SIZE; index++) {
  111. if ((_ws_tickets[index].ip == ip) && (now - _ws_tickets[index].timestamp < WS_TIMEOUT)) break;
  112. }
  113. if (index == WS_BUFFER_SIZE) {
  114. return false;
  115. }
  116. return true;
  117. }
  118. // -----------------------------------------------------------------------------
  119. // Debug
  120. // -----------------------------------------------------------------------------
  121. #if DEBUG_WEB_SUPPORT
  122. constexpr size_t WsDebugMessagesMax = 8;
  123. WsDebug _ws_debug(WsDebugMessagesMax);
  124. void WsDebug::send(bool connected) {
  125. if (!connected && _flush) {
  126. clear();
  127. return;
  128. }
  129. if (!_flush) return;
  130. // ref: http://arduinojson.org/v5/assistant/
  131. // {"weblog": {"msg":[...],"pre":[...]}}
  132. DynamicJsonBuffer jsonBuffer(2*JSON_ARRAY_SIZE(_messages.size()) + JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2));
  133. JsonObject& root = jsonBuffer.createObject();
  134. JsonObject& weblog = root.createNestedObject("weblog");
  135. JsonArray& msg_array = weblog.createNestedArray("msg");
  136. JsonArray& pre_array = weblog.createNestedArray("pre");
  137. for (auto& msg : _messages) {
  138. pre_array.add(msg.first.c_str());
  139. msg_array.add(msg.second.c_str());
  140. }
  141. wsSend(root);
  142. clear();
  143. }
  144. bool wsDebugSend(const char* prefix, const char* message) {
  145. if (!wsConnected()) return false;
  146. _ws_debug.add(prefix, message);
  147. return true;
  148. }
  149. #endif
  150. // Check the existing setting before saving it
  151. // TODO: this should know of the default values, somehow?
  152. // TODO: move webPort handling somewhere else?
  153. bool _wsStore(const String& key, const String& value) {
  154. if (key == "webPort") {
  155. if ((value.toInt() == 0) || (value.toInt() == 80)) {
  156. return delSetting(key);
  157. }
  158. }
  159. if (!hasSetting(key) || value != getSetting(key)) {
  160. return setSetting(key, value);
  161. }
  162. return false;
  163. }
  164. // -----------------------------------------------------------------------------
  165. // Store indexed key (key0, key1, etc.) from array
  166. // -----------------------------------------------------------------------------
  167. bool _wsStore(const String& key, JsonArray& values) {
  168. bool changed = false;
  169. unsigned char index = 0;
  170. for (auto& element : values) {
  171. const auto value = element.as<String>();
  172. const auto keyobj = settings_key_t {key, index};
  173. if (!hasSetting(keyobj) || value != getSetting(keyobj)) {
  174. setSetting(keyobj, value);
  175. changed = true;
  176. }
  177. ++index;
  178. }
  179. // Delete further values
  180. for (unsigned char next_index=index; next_index < SETTINGS_MAX_LIST_COUNT; ++next_index) {
  181. if (!delSetting({key, next_index})) break;
  182. changed = true;
  183. }
  184. return changed;
  185. }
  186. bool _wsCheckKey(const String& key, JsonVariant& value) {
  187. for (auto& callback : _ws_callbacks.on_keycheck) {
  188. if (callback(key.c_str(), value)) return true;
  189. // TODO: remove this to call all OnKeyCheckCallbacks with the
  190. // current key/value
  191. }
  192. return false;
  193. }
  194. void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
  195. //DEBUG_MSG_P(PSTR("[WEBSOCKET] Parsing: %s\n"), length ? (char*) payload : "");
  196. // Get client ID
  197. uint32_t client_id = client->id();
  198. // Check early for empty object / nothing
  199. if ((length == 0) || (length == 1)) {
  200. return;
  201. }
  202. if ((length == 3) && (strcmp((char*) payload, "{}") == 0)) {
  203. return;
  204. }
  205. // Parse JSON input
  206. // TODO: json buffer should be pretty efficient with the non-const payload,
  207. // most of the space is taken by the object key references
  208. DynamicJsonBuffer jsonBuffer(512);
  209. JsonObject& root = jsonBuffer.parseObject((char *) payload);
  210. if (!root.success()) {
  211. DEBUG_MSG_P(PSTR("[WEBSOCKET] JSON parsing error\n"));
  212. wsSend_P(client_id, PSTR("{\"message\": 3}"));
  213. return;
  214. }
  215. // Check actions -----------------------------------------------------------
  216. const char* action = root["action"];
  217. if (action) {
  218. if (strcmp(action, "ping") == 0) {
  219. wsSend_P(client_id, PSTR("{\"pong\": 1}"));
  220. return;
  221. }
  222. DEBUG_MSG_P(PSTR("[WEBSOCKET] Requested action: %s\n"), action);
  223. if (strcmp(action, "reboot") == 0) {
  224. deferredReset(100, CUSTOM_RESET_WEB);
  225. return;
  226. }
  227. if (strcmp(action, "reconnect") == 0) {
  228. _ws_defer.once_ms(100, wifiDisconnect);
  229. return;
  230. }
  231. if (strcmp(action, "factory_reset") == 0) {
  232. DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n"));
  233. resetSettings();
  234. deferredReset(100, CUSTOM_RESET_FACTORY);
  235. return;
  236. }
  237. JsonObject& data = root["data"];
  238. if (data.success()) {
  239. // Callbacks
  240. for (auto& callback : _ws_callbacks.on_action) {
  241. callback(client_id, action, data);
  242. }
  243. // Restore configuration via websockets
  244. if (strcmp(action, "restore") == 0) {
  245. if (settingsRestoreJson(data)) {
  246. wsSend_P(client_id, PSTR("{\"message\": 5}"));
  247. } else {
  248. wsSend_P(client_id, PSTR("{\"message\": 4}"));
  249. }
  250. }
  251. return;
  252. }
  253. };
  254. // Check configuration -----------------------------------------------------
  255. JsonObject& config = root["config"];
  256. if (config.success()) {
  257. DEBUG_MSG_P(PSTR("[WEBSOCKET] Parsing configuration data\n"));
  258. String adminPass;
  259. bool save = false;
  260. for (auto kv: config) {
  261. bool changed = false;
  262. String key = kv.key;
  263. JsonVariant& value = kv.value;
  264. // Check password
  265. if (key == "adminPass") {
  266. if (!value.is<JsonArray&>()) continue;
  267. JsonArray& values = value.as<JsonArray&>();
  268. if (values.size() != 2) continue;
  269. if (values[0].as<String>().equals(values[1].as<String>())) {
  270. String password = values[0].as<String>();
  271. if (password.length() > 0) {
  272. setSetting(key, password);
  273. save = true;
  274. wsSend_P(client_id, PSTR("{\"action\": \"reload\"}"));
  275. }
  276. } else {
  277. wsSend_P(client_id, PSTR("{\"message\": 7}"));
  278. }
  279. continue;
  280. }
  281. if (!_wsCheckKey(key, value)) {
  282. delSetting(key);
  283. continue;
  284. }
  285. // Store values
  286. if (value.is<JsonArray&>()) {
  287. if (_wsStore(key, value.as<JsonArray&>())) changed = true;
  288. } else {
  289. if (_wsStore(key, value.as<String>())) changed = true;
  290. }
  291. // Update flags if value has changed
  292. if (changed) {
  293. save = true;
  294. }
  295. }
  296. // Save settings
  297. if (save) {
  298. // Callbacks
  299. espurnaReload();
  300. // Persist settings
  301. saveSettings();
  302. wsSend_P(client_id, PSTR("{\"message\": 8}"));
  303. } else {
  304. wsSend_P(client_id, PSTR("{\"message\": 9}"));
  305. }
  306. }
  307. }
  308. void _wsUpdate(JsonObject& root) {
  309. root["heap"] = getFreeHeap();
  310. root["uptime"] = getUptime();
  311. root["rssi"] = WiFi.RSSI();
  312. root["loadaverage"] = systemLoadAverage();
  313. if (ADC_MODE_VALUE == ADC_VCC) {
  314. root["vcc"] = ESP.getVcc();
  315. } else {
  316. root["vcc"] = "N/A (TOUT) ";
  317. }
  318. #if NTP_SUPPORT
  319. if (ntpSynced()) root["now"] = now();
  320. #endif
  321. }
  322. void _wsResetUpdateTimer() {
  323. _ws_last_update = millis() + WS_UPDATE_INTERVAL;
  324. }
  325. void _wsDoUpdate(const bool connected) {
  326. if (!connected) return;
  327. if (millis() - _ws_last_update > WS_UPDATE_INTERVAL) {
  328. _ws_last_update = millis();
  329. wsSend(_wsUpdate);
  330. }
  331. }
  332. bool _wsOnKeyCheck(const char * key, JsonVariant& value) {
  333. if (strncmp(key, "ws", 2) == 0) return true;
  334. if (strncmp(key, "admin", 5) == 0) return true;
  335. if (strncmp(key, "hostname", 8) == 0) return true;
  336. if (strncmp(key, "desc", 4) == 0) return true;
  337. if (strncmp(key, "webPort", 7) == 0) return true;
  338. return false;
  339. }
  340. void _wsOnConnected(JsonObject& root) {
  341. root["webMode"] = WEB_MODE_NORMAL;
  342. root["app_name"] = APP_NAME;
  343. root["app_version"] = APP_VERSION;
  344. root["app_build"] = buildTime();
  345. #if defined(APP_REVISION)
  346. root["app_revision"] = APP_REVISION;
  347. #endif
  348. root["device"] = getDevice().c_str();
  349. root["manufacturer"] = getManufacturer().c_str();
  350. root["chipid"] = getChipId().c_str();
  351. root["mac"] = WiFi.macAddress();
  352. root["bssid"] = WiFi.BSSIDstr();
  353. root["channel"] = WiFi.channel();
  354. root["hostname"] = getSetting("hostname");
  355. root["desc"] = getSetting("desc");
  356. root["network"] = getNetwork();
  357. root["deviceip"] = getIP();
  358. root["sketch_size"] = ESP.getSketchSize();
  359. root["free_size"] = ESP.getFreeSketchSpace();
  360. root["sdk"] = ESP.getSdkVersion();
  361. root["core"] = getCoreVersion();
  362. root["webPort"] = getSetting("webPort", WEB_PORT);
  363. root["wsAuth"] = getSetting("wsAuth", 1 == WS_AUTHENTICATION);
  364. root["hbMode"] = getSetting("hbMode", HEARTBEAT_MODE);
  365. root["hbInterval"] = getSetting("hbInterval", HEARTBEAT_INTERVAL);
  366. }
  367. void _wsConnected(uint32_t client_id) {
  368. const bool changePassword = (USE_PASSWORD && WEB_FORCE_PASS_CHANGE)
  369. ? getAdminPass().equals(ADMIN_PASS)
  370. : false;
  371. if (changePassword) {
  372. StaticJsonBuffer<JSON_OBJECT_SIZE(1)> jsonBuffer;
  373. JsonObject& root = jsonBuffer.createObject();
  374. root["webMode"] = WEB_MODE_PASSWORD;
  375. wsSend(client_id, root);
  376. return;
  377. }
  378. wsPostAll(client_id, _ws_callbacks.on_visible);
  379. wsPostSequence(client_id, _ws_callbacks.on_connected);
  380. wsPostSequence(client_id, _ws_callbacks.on_data);
  381. }
  382. void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
  383. if (type == WS_EVT_CONNECT) {
  384. client->_tempObject = nullptr;
  385. #ifndef NOWSAUTH
  386. if (!_wsAuth(client)) {
  387. wsSend_P(client->id(), PSTR("{\"message\": 10}"));
  388. DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n"));
  389. client->close();
  390. return;
  391. }
  392. #endif
  393. IPAddress ip = client->remoteIP();
  394. DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u connected, ip: %d.%d.%d.%d, url: %s\n"), client->id(), ip[0], ip[1], ip[2], ip[3], server->url());
  395. _wsConnected(client->id());
  396. _wsResetUpdateTimer();
  397. wifiReconnectCheck();
  398. client->_tempObject = new WebSocketIncommingBuffer(_wsParse, true);
  399. } else if(type == WS_EVT_DISCONNECT) {
  400. DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u disconnected\n"), client->id());
  401. if (client->_tempObject) {
  402. delete (WebSocketIncommingBuffer *) client->_tempObject;
  403. }
  404. wifiReconnectCheck();
  405. } else if(type == WS_EVT_ERROR) {
  406. DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u error(%u): %s\n"), client->id(), *((uint16_t*)arg), (char*)data);
  407. } else if(type == WS_EVT_PONG) {
  408. DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u pong(%u): %s\n"), client->id(), len, len ? (char*) data : "");
  409. } else if(type == WS_EVT_DATA) {
  410. //DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u data(%u): %s\n"), client->id(), len, len ? (char*) data : "");
  411. if (!client->_tempObject) return;
  412. WebSocketIncommingBuffer *buffer = (WebSocketIncommingBuffer *)client->_tempObject;
  413. AwsFrameInfo * info = (AwsFrameInfo*)arg;
  414. buffer->data_event(client, info, data, len);
  415. }
  416. }
  417. // TODO: make this generic loop method to queue important ws messages?
  418. // or, if something uses ticker / async ctx to send messages,
  419. // it needs a retry mechanism built into the callback object
  420. void _wsHandlePostponedCallbacks(bool connected) {
  421. if (!connected && !_ws_queue.empty()) {
  422. _ws_queue.pop();
  423. return;
  424. }
  425. if (_ws_queue.empty()) return;
  426. auto& callbacks = _ws_queue.front();
  427. // avoid stalling forever when can't send anything
  428. constexpr decltype(ESP.getCycleCount()) WsQueueTimeoutClockCycles = microsecondsToClockCycles(10 * 1000 * 1000); // 10s
  429. if (ESP.getCycleCount() - callbacks.timestamp > WsQueueTimeoutClockCycles) {
  430. _ws_queue.pop();
  431. return;
  432. }
  433. // client_id == 0 means we need to send the message to every client
  434. if (callbacks.client_id) {
  435. AsyncWebSocketClient* ws_client = _ws.client(callbacks.client_id);
  436. // ...but, we need to check if client is still connected
  437. if (!ws_client) {
  438. _ws_queue.pop();
  439. return;
  440. }
  441. // wait until we can send the next batch of messages
  442. // XXX: enforce that callbacks send only one message per iteration
  443. if (ws_client->queueIsFull()) {
  444. return;
  445. }
  446. }
  447. // XXX: block allocation will try to create *2 next time,
  448. // likely failing and causing wsSend to reference empty objects
  449. // XXX: arduinojson6 will not do this, but we may need to use per-callback buffers
  450. constexpr size_t WsQueueJsonBufferSize = 3192;
  451. DynamicJsonBuffer jsonBuffer(WsQueueJsonBufferSize);
  452. JsonObject& root = jsonBuffer.createObject();
  453. callbacks.send(root);
  454. if (callbacks.client_id) {
  455. wsSend(callbacks.client_id, root);
  456. } else {
  457. wsSend(root);
  458. }
  459. yield();
  460. if (callbacks.done()) {
  461. _ws_queue.pop();
  462. }
  463. }
  464. void _wsLoop() {
  465. const bool connected = wsConnected();
  466. _wsDoUpdate(connected);
  467. _wsHandlePostponedCallbacks(connected);
  468. #if DEBUG_WEB_SUPPORT
  469. _ws_debug.send(connected);
  470. #endif
  471. }
  472. // -----------------------------------------------------------------------------
  473. // Public API
  474. // -----------------------------------------------------------------------------
  475. bool wsConnected() {
  476. return (_ws.count() > 0);
  477. }
  478. bool wsConnected(uint32_t client_id) {
  479. return _ws.hasClient(client_id);
  480. }
  481. ws_callbacks_t& wsRegister() {
  482. return _ws_callbacks;
  483. }
  484. void wsSend(JsonObject& root) {
  485. // Note: 'measurement' tries to serialize json contents byte-by-byte,
  486. // which is somewhat costly, but likely unavoidable for us.
  487. size_t len = root.measureLength();
  488. AsyncWebSocketMessageBuffer* buffer = _ws.makeBuffer(len);
  489. if (buffer) {
  490. root.printTo(reinterpret_cast<char*>(buffer->get()), len + 1);
  491. _ws.textAll(buffer);
  492. }
  493. }
  494. void wsSend(uint32_t client_id, JsonObject& root) {
  495. AsyncWebSocketClient* client = _ws.client(client_id);
  496. if (client == nullptr) return;
  497. size_t len = root.measureLength();
  498. AsyncWebSocketMessageBuffer* buffer = _ws.makeBuffer(len);
  499. if (buffer) {
  500. root.printTo(reinterpret_cast<char*>(buffer->get()), len + 1);
  501. client->text(buffer);
  502. }
  503. }
  504. void wsSend(ws_on_send_callback_f callback) {
  505. if (_ws.count() > 0) {
  506. DynamicJsonBuffer jsonBuffer(512);
  507. JsonObject& root = jsonBuffer.createObject();
  508. callback(root);
  509. wsSend(root);
  510. }
  511. }
  512. void wsSend(const char * payload) {
  513. if (_ws.count() > 0) {
  514. _ws.textAll(payload);
  515. }
  516. }
  517. void wsSend_P(PGM_P payload) {
  518. if (_ws.count() > 0) {
  519. char buffer[strlen_P(payload)];
  520. strcpy_P(buffer, payload);
  521. _ws.textAll(buffer);
  522. }
  523. }
  524. void wsSend(uint32_t client_id, ws_on_send_callback_f callback) {
  525. AsyncWebSocketClient* client = _ws.client(client_id);
  526. if (client == nullptr) return;
  527. DynamicJsonBuffer jsonBuffer(512);
  528. JsonObject& root = jsonBuffer.createObject();
  529. callback(root);
  530. wsSend(client_id, root);
  531. }
  532. void wsSend(uint32_t client_id, const char * payload) {
  533. _ws.text(client_id, payload);
  534. }
  535. void wsSend_P(uint32_t client_id, PGM_P payload) {
  536. char buffer[strlen_P(payload)];
  537. strcpy_P(buffer, payload);
  538. _ws.text(client_id, buffer);
  539. }
  540. void wsSetup() {
  541. _ws.onEvent(_wsEvent);
  542. webServer()->addHandler(&_ws);
  543. // CORS
  544. const String webDomain = getSetting("webDomain", WEB_REMOTE_DOMAIN);
  545. DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", webDomain);
  546. if (!webDomain.equals("*")) {
  547. DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
  548. }
  549. webServer()->on("/auth", HTTP_GET, _onAuth);
  550. wsRegister()
  551. .onConnected(_wsOnConnected)
  552. .onKeyCheck(_wsOnKeyCheck);
  553. espurnaRegisterLoop(_wsLoop);
  554. }
  555. #endif // WEB_SUPPORT