Showing the changes to libraries/script-engine/src/WebSocketClass.cpp (1 of 3 files). Show all
Unified · Split
| @@ -68,6 +68,18 @@ void WebSocketClass::close(QWebSocketProtocol::CloseCode closeCode, QString reas · 67 unmodified lines | |||
| 68 | _webSocket->close(closeCode, reason); | 68 | _webSocket->close(closeCode, reason); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | /**jsdoc | ||
| 72 | * Called when the connection closes. | ||
| 73 | * @callback WebSocket~onCloseCallback | ||
| 74 | * @param {WebSocket.CloseData} data - Information on the connection closure. | ||
| 75 | */ | ||
| 76 | /**jsdoc | ||
| 77 | * Information on a connection being closed. | ||
| 78 | * @typedef {object} WebSocket.CloseData | ||
| 79 | * @property {WebSocket.CloseCode} code - The reason why the connection was closed. | ||
| 80 | * @property {string} reason - Description of the reason why the connection was closed. | ||
| 81 | * @property {boolean} wasClean - <code>true</code> if the connection closed cleanly, <code>false</code> if it didn't. | ||
| 82 | */ | ||
| 71 | void WebSocketClass::handleOnClose() { | 83 | void WebSocketClass::handleOnClose() { |
| 72 | bool hasError = (_webSocket->error() != QAbstractSocket::UnknownSocketError); | 84 | bool hasError = (_webSocket->error() != QAbstractSocket::UnknownSocketError); |
| 73 | if (_onCloseEvent.isFunction()) { | 85 | if (_onCloseEvent.isFunction()) { |
| @@ -81,12 +93,26 @@ void WebSocketClass::handleOnClose() { · 7 unmodified lines | |||
| 81 | } | 93 | } |
| 82 | } | 94 | } |
| 83 | 95 | ||
| 96 | /**jsdoc | ||
| 97 | * Called when an error occurs. | ||
| 98 | * @callback WebSocket~onErrorCallback | ||
| 99 | */ | ||
| 84 | void WebSocketClass::handleOnError(QAbstractSocket::SocketError error) { | 100 | void WebSocketClass::handleOnError(QAbstractSocket::SocketError error) { |
| 85 | if (_onErrorEvent.isFunction()) { | 101 | if (_onErrorEvent.isFunction()) { |
| 86 | _onErrorEvent.call(); | 102 | _onErrorEvent.call(); |
| 87 | } | 103 | } |
| 88 | } | 104 | } |
| 89 | 105 | ||
| 106 | /**jsdoc | ||
| 107 | * Triggered when a message is received. | ||
| 108 | * @callback WebSocket~onMessageCallback | ||
| 109 | * @param {WebSocket.MessageData} message - The message received. | ||
| 110 | */ | ||
| 111 | /**jsdoc | ||
| 112 | * A message received on a WebSocket connection. | ||
| 113 | * @typedef {object} WebSocket.MessageData | ||
| 114 | * @property {string} data - The message content. | ||
| 115 | */ | ||
| 90 | void WebSocketClass::handleOnMessage(const QString& message) { | 116 | void WebSocketClass::handleOnMessage(const QString& message) { |
| 91 | if (_onMessageEvent.isFunction()) { | 117 | if (_onMessageEvent.isFunction()) { |
| 92 | QScriptValueList args; | 118 | QScriptValueList args; |
| @@ -97,6 +123,10 @@ void WebSocketClass::handleOnMessage(const QString& message) { · 4 unmodified lines | |||
| 97 | } | 123 | } |
| 98 | } | 124 | } |
| 99 | 125 | ||
| 126 | /**jsdoc | ||
| 127 | * Called when the connection opens. | ||
| 128 | * @callback WebSocket~onOpenCallback | ||
| 129 | */ | ||
| 100 | void WebSocketClass::handleOnOpen() { | 130 | void WebSocketClass::handleOnOpen() { |
| 101 | if (_onOpenEvent.isFunction()) { | 131 | if (_onOpenEvent.isFunction()) { |
| 102 | _onOpenEvent.call(); | 132 | _onOpenEvent.call(); |