mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 17:38:39 +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::disconnected, this, &WebSocketClass::handleOnClose);
|
||||||
connect(_webSocket, &QWebSocket::textMessageReceived, this, &WebSocketClass::handleOnMessage);
|
connect(_webSocket, &QWebSocket::textMessageReceived, this, &WebSocketClass::handleOnMessage);
|
||||||
connect(_webSocket, &QWebSocket::connected, this, &WebSocketClass::handleOnOpen);
|
connect(_webSocket, &QWebSocket::connected, this, &WebSocketClass::handleOnOpen);
|
||||||
|
connect(_webSocket, static_cast<void(QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), this,
|
||||||
|
&WebSocketClass::handleOnError);
|
||||||
_binaryType = QStringLiteral("blob");
|
_binaryType = QStringLiteral("blob");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,13 +68,7 @@ void WebSocketClass::close(QWebSocketProtocol::CloseCode closeCode, QString reas
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketClass::handleOnClose() {
|
void WebSocketClass::handleOnClose() {
|
||||||
bool hasError = false;
|
bool hasError = (_webSocket->error() != QAbstractSocket::UnknownSocketError);
|
||||||
if (_webSocket->error() != QAbstractSocket::UnknownSocketError) {
|
|
||||||
hasError = true;
|
|
||||||
if (_onErrorEvent.isFunction()) {
|
|
||||||
_onErrorEvent.call();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_onCloseEvent.isFunction()) {
|
if (_onCloseEvent.isFunction()) {
|
||||||
QScriptValueList args;
|
QScriptValueList args;
|
||||||
QScriptValue arg = _engine->newObject();
|
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) {
|
void WebSocketClass::handleOnMessage(const QString& message) {
|
||||||
if (_onMessageEvent.isFunction()) {
|
if (_onMessageEvent.isFunction()) {
|
||||||
QScriptValueList args;
|
QScriptValueList args;
|
||||||
|
|
|
@ -119,6 +119,7 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleOnClose();
|
void handleOnClose();
|
||||||
|
void handleOnError(QAbstractSocket::SocketError error);
|
||||||
void handleOnMessage(const QString& message);
|
void handleOnMessage(const QString& message);
|
||||||
void handleOnOpen();
|
void handleOnOpen();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue