cleanup / use a websocket instead of raw websockettransport

This commit is contained in:
Benjamin Sergeant
2018-12-30 22:00:49 -08:00
parent 266cf93584
commit 379a845166
6 changed files with 116 additions and 97 deletions

View File

@ -35,6 +35,15 @@ namespace ix
_stop(false),
_automaticReconnection(true)
{
_ws.setOnCloseCallback(
[this](uint16_t code, const std::string& reason, size_t wireSize)
{
_onMessageCallback(WebSocket_MessageType_Close, "", wireSize,
WebSocketErrorInfo(),
WebSocketCloseInfo(code, reason),
WebSocketHttpHeaders());
}
);
}
WebSocket::~WebSocket()
@ -99,16 +108,6 @@ namespace ix
_ws.configure(_url, _perMessageDeflateOptions);
}
_ws.setOnCloseCallback(
[this](uint16_t code, const std::string& reason, size_t wireSize)
{
_onMessageCallback(WebSocket_MessageType_Close, "", wireSize,
WebSocketErrorInfo(),
WebSocketCloseInfo(code, reason),
WebSocketHttpHeaders());
}
);
WebSocketInitResult status = _ws.init();
if (!status.success)
{
@ -121,6 +120,11 @@ namespace ix
return status;
}
void WebSocket::setSocketFileDescriptor(int fd)
{
_ws.initFromSocket(fd);
}
bool WebSocket::isConnected() const
{
return getReadyState() == WebSocket_ReadyState_Open;