summaryrefslogtreecommitdiff
path: root/src/imports/qmlwebsockets/qqmlwebsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/qmlwebsockets/qqmlwebsocket.cpp')
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.cpp b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
index aea2c82..9ff88d5 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.cpp
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
@@ -90,6 +90,12 @@
*/
/*!
+ \qmlsignal WebSocket::binaryMessageReceived(QString message)
+ \since 5.8
+ This signal is emitted when a binary message is received.
+ */
+
+/*!
\qmlsignal WebSocket::statusChanged(Status status)
This signal is emitted when the status of the WebSocket changes.
the \l [QML]{WebSocket::status}{status} argument provides the current status.
@@ -102,6 +108,12 @@
Sends \c message to the server.
*/
+/*!
+ \qmlmethod void WebSocket::sendBinaryMessage(ArrayBuffer message)
+ \since 5.8
+ Sends \c message to the server.
+ */
+
#include "qqmlwebsocket.h"
#include <QtWebSockets/QWebSocket>
@@ -144,6 +156,16 @@ qint64 QQmlWebSocket::sendTextMessage(const QString &message)
return m_webSocket->sendTextMessage(message);
}
+qint64 QQmlWebSocket::sendBinaryMessage(const QByteArray &message)
+{
+ if (m_status != Open) {
+ setErrorString(tr("Messages can only be sent when the socket is open."));
+ setStatus(Error);
+ return 0;
+ }
+ return m_webSocket->sendBinaryMessage(message);
+}
+
QUrl QQmlWebSocket::url() const
{
return m_url;
@@ -198,6 +220,8 @@ void QQmlWebSocket::setSocket(QWebSocket *socket)
m_webSocket->setParent(Q_NULLPTR);
connect(m_webSocket.data(), &QWebSocket::textMessageReceived,
this, &QQmlWebSocket::textMessageReceived);
+ connect(m_webSocket.data(), &QWebSocket::binaryMessageReceived,
+ this, &QQmlWebSocket::binaryMessageReceived);
typedef void (QWebSocket::* ErrorSignal)(QAbstractSocket::SocketError);
connect(m_webSocket.data(), static_cast<ErrorSignal>(&QWebSocket::error),
this, &QQmlWebSocket::onError);