mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 17:26:24 +02:00
hook up the WebSocket error event directly
This commit is contained in:
parent
0e255f4f3e
commit
d84cf1859c
2 changed files with 10 additions and 7 deletions
|
@ -34,6 +34,8 @@ void WebSocketClass::initialize() {
|
|||
connect(_webSocket, &QWebSocket::disconnected, this, &WebSocketClass::handleOnClose);
|
||||
connect(_webSocket, &QWebSocket::textMessageReceived, this, &WebSocketClass::handleOnMessage);
|
||||
connect(_webSocket, &QWebSocket::connected, this, &WebSocketClass::handleOnOpen);
|
||||
connect(_webSocket, static_cast<void(QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), this,
|
||||
&WebSocketClass::handleOnError);
|
||||
_binaryType = QStringLiteral("blob");
|
||||
}
|
||||
|
||||
|
@ -66,13 +68,7 @@ void WebSocketClass::close(QWebSocketProtocol::CloseCode closeCode, QString reas
|
|||
}
|
||||
|
||||
void WebSocketClass::handleOnClose() {
|
||||
bool hasError = false;
|
||||
if (_webSocket->error() != QAbstractSocket::UnknownSocketError) {
|
||||
hasError = true;
|
||||
if (_onErrorEvent.isFunction()) {
|
||||
_onErrorEvent.call();
|
||||
}
|
||||
}
|
||||
bool hasError = (_webSocket->error() != QAbstractSocket::UnknownSocketError);
|
||||
if (_onCloseEvent.isFunction()) {
|
||||
QScriptValueList args;
|
||||
QScriptValue arg = _engine->newObject();
|
||||
|
@ -84,6 +80,12 @@ void WebSocketClass::handleOnClose() {
|
|||
}
|
||||
}
|
||||
|
||||
void WebSocketClass::handleOnError(QAbstractSocket::SocketError error) {
|
||||
if (_onErrorEvent.isFunction()) {
|
||||
_onErrorEvent.call();
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocketClass::handleOnMessage(const QString& message) {
|
||||
if (_onMessageEvent.isFunction()) {
|
||||
QScriptValueList args;
|
||||
|
|
|
@ -119,6 +119,7 @@ private:
|
|||
|
||||
private slots:
|
||||
void handleOnClose();
|
||||
void handleOnError(QAbstractSocket::SocketError error);
|
||||
void handleOnMessage(const QString& message);
|
||||
void handleOnOpen();
|
||||
|
||||
|
|
Loading…
Reference in a new issue