Skip to content

Commit

Permalink
patch: added missing keywords and fixed incomplete interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmaimon committed Feb 25, 2019
1 parent daa2530 commit dce8973
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ Esp32TcpClient KEYWORD1

connect KEYWORD2
send KEYWORD2
sendBinary KEYWORD2
onMessage KEYWORD2
onEvent KEYWORD2
available KEYWORD2
poll KEYWORD2
ping KEYWORD2
pong KEYWORD2
close KEYWORD2
readBlocking KEYWORD2

WebsocketsMessage KEYWORD1
data KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ArduinoWebsockets
version=0.2.0
version=0.2.1
author=Gil Maimon <[email protected]>
maintainer=Gil Maimon <[email protected]>
sentence=A library for writing modern Websockets applications with Arduino.
Expand Down
12 changes: 6 additions & 6 deletions src/tiny_websockets/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ namespace websockets {
public:
WebsocketsClient();

bool connect(WSString url);
bool connect(WSString host, int port, WSString path);
bool connect(WSInterfaceString url);
bool connect(WSInterfaceString host, int port, WSInterfaceString path);

void onMessage(MessageCallback callback);
void onEvent(EventCallback callback);

bool poll();
bool available(bool activeTest = false);

bool send(WSString data);
bool send(WSInterfaceString data);
bool send(char* data, size_t len);
bool sendBinary(WSString data);
bool sendBinary(WSInterfaceString data);
bool sendBinary(uint8_t* data, size_t len);

WebsocketsMessage readBlocking();

bool ping(WSString data = "");
bool pong(WSString data = "");
bool ping(WSInterfaceString data = "");
bool pong(WSInterfaceString data = "");

void close();

Expand Down
31 changes: 18 additions & 13 deletions src/websockets_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ namespace websockets {
return true;
}

bool WebsocketsClient::connect(WSString url) {
bool WebsocketsClient::connect(WSInterfaceString _url) {
WSString url = internals::fromInterfaceString(_url);
WSString protocol = "";
if(doestStartsWith(url, "http://")) {
protocol = "http";
Expand Down Expand Up @@ -122,14 +123,18 @@ namespace websockets {
host = onlyHost;
}

return connect(host, port, uri);
return this->connect(
internals::fromInternalString(host),
port,
internals::fromInternalString(uri)
);
}

bool WebsocketsClient::connect(WSString host, int port, WSString path) {
this->_connectionOpen = this->_client.connect(host, port);
bool WebsocketsClient::connect(WSInterfaceString host, int port, WSInterfaceString path) {
this->_connectionOpen = this->_client.connect(internals::fromInterfaceString(host), port);
if (!this->_connectionOpen) return false;

auto handshake = generateHandshake(host, path);
auto handshake = generateHandshake(internals::fromInterfaceString(host), internals::fromInterfaceString(path));
this->_client.send(handshake.requestStr);

auto head = this->_client.readLine();
Expand Down Expand Up @@ -193,9 +198,9 @@ namespace websockets {
return WebsocketsEndpoint::recv();
}

bool WebsocketsClient::send(WSString data) {
bool WebsocketsClient::send(WSInterfaceString data) {
if(available()) {
return WebsocketsEndpoint::send(data, MessageType::Text);
return WebsocketsEndpoint::send(internals::fromInterfaceString(data), MessageType::Text);
}
return false;
}
Expand All @@ -207,9 +212,9 @@ namespace websockets {
return false;
}

bool WebsocketsClient::sendBinary(WSString data) {
bool WebsocketsClient::sendBinary(WSInterfaceString data) {
if(available()) {
return WebsocketsEndpoint::send(data, MessageType::Binary);
return WebsocketsEndpoint::send(internals::fromInterfaceString(data), MessageType::Binary);
}
return false;
}
Expand All @@ -229,12 +234,12 @@ namespace websockets {
return _connectionOpen;
}

bool WebsocketsClient::ping(WSString data) {
return WebsocketsEndpoint::ping(data);
bool WebsocketsClient::ping(WSInterfaceString data) {
return WebsocketsEndpoint::ping(internals::fromInterfaceString(data));
}

bool WebsocketsClient::pong(WSString data) {
return WebsocketsEndpoint::pong(data);
bool WebsocketsClient::pong(WSInterfaceString data) {
return WebsocketsEndpoint::pong(internals::fromInterfaceString(data));
}

void WebsocketsClient::close() {
Expand Down

0 comments on commit dce8973

Please sign in to comment.