Showing the changes to libraries/script-engine/src/WebSocketClass.cpp (1 of 2 files). Show all
Unified · Split
| @@ -34,6 +34,8 @@ void WebSocketClass::initialize() { · 33 unmodified lines | |||
| 34 | connect(_webSocket, &QWebSocket::disconnected, this, &WebSocketClass::handleOnClose); | 34 | connect(_webSocket, &QWebSocket::disconnected, this, &WebSocketClass::handleOnClose); |
| 35 | connect(_webSocket, &QWebSocket::textMessageReceived, this, &WebSocketClass::handleOnMessage); | 35 | connect(_webSocket, &QWebSocket::textMessageReceived, this, &WebSocketClass::handleOnMessage); |
| 36 | connect(_webSocket, &QWebSocket::connected, this, &WebSocketClass::handleOnOpen); | 36 | connect(_webSocket, &QWebSocket::connected, this, &WebSocketClass::handleOnOpen); |
| 37 | connect(_webSocket, static_cast<void(QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), this, | ||
| 38 | &WebSocketClass::handleOnError); | ||
| 37 | _binaryType = QStringLiteral("blob"); | 39 | _binaryType = QStringLiteral("blob"); |
| 38 | } | 40 | } |
| 39 | 41 | ||
| @@ -66,13 +68,7 @@ void WebSocketClass::close(QWebSocketProtocol::CloseCode closeCode, QString reas · 26 unmodified lines | |||
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | void WebSocketClass::handleOnClose() { | 70 | void WebSocketClass::handleOnClose() { |
| 69 | bool hasError = false; | 71 | bool hasError = (_webSocket->error() != QAbstractSocket::UnknownSocketError); |
| 70 | if (_webSocket->error() != QAbstractSocket::UnknownSocketError) { | ||
| 71 | hasError = true; | ||
| 72 | if (_onErrorEvent.isFunction()) { | ||
| 73 | _onErrorEvent.call(); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | if (_onCloseEvent.isFunction()) { | 72 | if (_onCloseEvent.isFunction()) { |
| 77 | QScriptValueList args; | 73 | QScriptValueList args; |
| 78 | QScriptValue arg = _engine->newObject(); | 74 | QScriptValue arg = _engine->newObject(); |
| @@ -84,6 +80,12 @@ void WebSocketClass::handleOnClose() { · 5 unmodified lines | |||
| 84 | } | 80 | } |
| 85 | } | 81 | } |
| 86 | 82 | ||
| 83 | void WebSocketClass::handleOnError(QAbstractSocket::SocketError error) { | ||
| 84 | if (_onErrorEvent.isFunction()) { | ||
| 85 | _onErrorEvent.call(); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 87 | void WebSocketClass::handleOnMessage(const QString& message) { | 89 | void WebSocketClass::handleOnMessage(const QString& message) { |
| 88 | if (_onMessageEvent.isFunction()) { | 90 | if (_onMessageEvent.isFunction()) { |
| 89 | QScriptValueList args; | 91 | QScriptValueList args; |