History

hook up the WebSocket error event directly

Thijs Wenker committed 11 years ago

Commit d84cf181 parent 0e255f42 files · +10 −7Browse files

Showing the changes to libraries/script-engine/src/WebSocketClass.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/WebSocketClass.cpp+9−7
@@ -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
68void WebSocketClass::handleOnClose() {70void 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
83void WebSocketClass::handleOnError(QAbstractSocket::SocketError error) {
84 if (_onErrorEvent.isFunction()) {
85 _onErrorEvent.call();
86 }
87}
88
87void WebSocketClass::handleOnMessage(const QString& message) {89void WebSocketClass::handleOnMessage(const QString& message) {
88 if (_onMessageEvent.isFunction()) {90 if (_onMessageEvent.isFunction()) {
89 QScriptValueList args;91 QScriptValueList args;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t