Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/WebSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <assert.h>

#include <utility>

// DO NOT change magic bytes
#define WSL_MAGIC_BYTE_1 0xAB
#define WSL_MAGIC_BYTE_2 0xCD
Expand Down Expand Up @@ -38,9 +40,9 @@ static const size_t WSL_HEAD_LEN = sizeof(WSL_HEAD) / sizeof(WSL_HEAD[0]);

static const size_t WSL_MSG_SIZE_LEN = sizeof(uint16_t);

void WebSerialClass::setAuthentication(const String& username, const String& password){
_username = username;
_password = password;
void WebSerialClass::setAuthentication(String username, String password){
_username = std::move(username);
_password = std::move(password);
_authenticate = !_username.isEmpty() && !_password.isEmpty();
if (_ws != nullptr) {
_ws->setAuthentication(_username.c_str(), _password.c_str());
Expand Down Expand Up @@ -99,11 +101,11 @@ void WebSerialClass::begin(AsyncWebServer *server, const char* url) {

// onMessage Callback Handler
void WebSerialClass::onMessage(WSLMessageHandler recv) {
_recv = recv;
_recv = std::move(recv);
}

void WebSerialClass::onMessage(WSLStringMessageHandler callback) {
_recvString = callback;
_recvString = std::move(callback);
_recv = [&](uint8_t *data, size_t len) {
if(data && len) {
String msg;
Expand Down
3 changes: 1 addition & 2 deletions src/WebSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ typedef std::function<void(const String& msg)> WSLStringMessageHandler;
class WebSerialClass : public Print {
public:
void begin(AsyncWebServer *server, const char* url = "/webserial");
inline void setAuthentication(const char* username, const char* password) { setAuthentication(String(username), String(password)); }
void setAuthentication(const String& username, const String& password);
void setAuthentication(String username, String password);
void onMessage(WSLMessageHandler recv);
void onMessage(WSLStringMessageHandler recv);
bool getConnectionCount();
Expand Down
Loading