summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNobuaki Sukegawa <nsukeg@gmail.com>2015-09-15 06:21:47 +0900
committerNobuaki Sukegawa <nsukeg@gmail.com>2016-03-05 08:29:48 +0000
commit9b804c270d11d34d37c08a5145dba083a6b0c1a7 (patch)
treea8b8be98b6db51806493921bcfb6592c75a863d8 /src
parentb021c367e3796d7046797d5b93af2606d30b1ff2 (diff)
downloadqtwebsockets-9b804c270d11d34d37c08a5145dba083a6b0c1a7.tar.gz
Add binary message support to QML WebSocket type
Change-Id: I4472e899606d261420141e7b382717cbe12943c8 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/qmlwebsockets/plugins.qmltypes17
-rw-r--r--src/imports/qmlwebsockets/qmlwebsockets.pro2
-rw-r--r--src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp1
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.cpp24
-rw-r--r--src/imports/qmlwebsockets/qqmlwebsocket.h3
5 files changed, 42 insertions, 5 deletions
diff --git a/src/imports/qmlwebsockets/plugins.qmltypes b/src/imports/qmlwebsockets/plugins.qmltypes
index b79da44..cbbb628 100644
--- a/src/imports/qmlwebsockets/plugins.qmltypes
+++ b/src/imports/qmlwebsockets/plugins.qmltypes
@@ -4,15 +4,15 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable QtWebSockets 1.0'
+// 'qmlplugindump -nonrelocatable QtWebSockets 1.1'
Module {
dependencies: []
Component {
name: "QQmlWebSocket"
prototype: "QObject"
- exports: ["QtWebSockets/WebSocket 1.0"]
- exportMetaObjectRevisions: [0]
+ exports: ["QtWebSockets/WebSocket 1.0", "QtWebSockets/WebSocket 1.1"]
+ exportMetaObjectRevisions: [0, 1]
Enum {
name: "Status"
values: {
@@ -32,6 +32,11 @@ Module {
Parameter { name: "message"; type: "string" }
}
Signal {
+ name: "binaryMessageReceived"
+ revision: 1
+ Parameter { name: "message"; type: "QByteArray" }
+ }
+ Signal {
name: "statusChanged"
Parameter { name: "status"; type: "Status" }
}
@@ -48,6 +53,12 @@ Module {
type: "qlonglong"
Parameter { name: "message"; type: "string" }
}
+ Method {
+ name: "sendBinaryMessage"
+ revision: 1
+ type: "qlonglong"
+ Parameter { name: "message"; type: "QByteArray" }
+ }
}
Component {
name: "QQmlWebSocketServer"
diff --git a/src/imports/qmlwebsockets/qmlwebsockets.pro b/src/imports/qmlwebsockets/qmlwebsockets.pro
index dea84a8..fef47f4 100644
--- a/src/imports/qmlwebsockets/qmlwebsockets.pro
+++ b/src/imports/qmlwebsockets/qmlwebsockets.pro
@@ -1,4 +1,4 @@
-QT = core websockets qml
+QT = core websockets qml qml-private core-private
TARGETPATH = QtWebSockets
diff --git a/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp b/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
index 11c9dec..24fe34a 100644
--- a/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
+++ b/src/imports/qmlwebsockets/qmlwebsockets_plugin.cpp
@@ -53,6 +53,7 @@ void QtWebSocketsDeclarativeModule::registerTypes(const char *uri)
// @uri QtWebSockets
qmlRegisterType<QQmlWebSocket>(uri, 1 /*major*/, 0 /*minor*/, "WebSocket");
+ qmlRegisterType<QQmlWebSocket, 1>(uri, 1 /*major*/, 1 /*minor*/, "WebSocket");
qmlRegisterType<QQmlWebSocketServer>(uri, 1 /*major*/, 0 /*minor*/, "WebSocketServer");
}
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.cpp b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
index a5c7aeb..13b986e 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.cpp
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.cpp
@@ -91,6 +91,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 {WebSocket::status}{status} argument provides the current status.
@@ -103,6 +109,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>
@@ -145,6 +157,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;
@@ -199,6 +221,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);
diff --git a/src/imports/qmlwebsockets/qqmlwebsocket.h b/src/imports/qmlwebsockets/qqmlwebsocket.h
index c5682ed..c3a808f 100644
--- a/src/imports/qmlwebsockets/qqmlwebsocket.h
+++ b/src/imports/qmlwebsockets/qqmlwebsocket.h
@@ -83,10 +83,11 @@ public:
bool isActive() const;
Q_INVOKABLE qint64 sendTextMessage(const QString &message);
-
+ Q_REVISION(1) Q_INVOKABLE qint64 sendBinaryMessage(const QByteArray &message);
Q_SIGNALS:
void textMessageReceived(QString message);
+ Q_REVISION(1) void binaryMessageReceived(QByteArray message);
void statusChanged(Status status);
void activeChanged(bool isActive);
void errorStringChanged(QString errorString);