aboutsummaryrefslogtreecommitdiffstats
path: root/examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-02 19:47:36 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-02 19:47:36 +0200
commit64ffd7a9f9604805c01f8bb2fd32616c3adf3ec0 (patch)
tree264e2743e509b8d7993bc5550ce6140dfc4b151f /examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml
parent6d75b83627114cecd7992bb460f6908268a57967 (diff)
Initial commit
Change-Id: I536251add63ef100b42a67e39a02fef117f2b414 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml')
-rw-r--r--examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml87
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml b/examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml
new file mode 100644
index 0000000..eded2d0
--- /dev/null
+++ b/examples/hybrid-qml/xxxxxx-hybrid-qml-app.qml
@@ -0,0 +1,87 @@
+import QtQuick 2.0
+import QtQuick.Window 2.0
+import QtQuick.Controls 1.4
+import QtWebSockets 1.0
+
+Window {
+ // VARIABLES
+
+ property string port_str: Qt.application.arguments[1]
+ property string token_str: Qt.application.arguments[2]
+ property string address_str: "ws://localhost:"+port_str+"/api?token="+token_str
+ property string request_str: ""
+ property string status_str: "waiting..."
+ property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 }
+
+ // WINDOW PROPERTIES
+
+ visible: true
+ width: 340
+ height: 160
+
+ // WEBSOCKET WIDGET (MAIN LOGIC)
+
+ WebSocket {
+ id: websocket
+ url: address_str
+ onTextMessageReceived: {
+ // VERB RESPONSE VALIDATION
+ var message_json = JSON.parse (message)
+ var request_json = message_json[2].request
+ if (message_json[0] != msgid_enu.retok) {
+ console.log ("Return value is not ok !")
+ status_str = "Bad return value, binding probably not installed"
+ return
+ }
+ // VERB RESPONSE PARSING AND LOGIC
+ status_str = request_json.info
+ }
+ onStatusChanged: {
+ if (websocket.status == WebSocket.Error)
+ status_str = "WebSocket error: " + websocket.errorString
+ }
+ active: true
+ }
+
+ // OTHER WIDGETS
+
+ Rectangle {
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.margins: 20
+
+ // TITLE SECTION
+ Label {
+ text: "QML Websocket Sample Application"
+ font.pixelSize: 18
+ font.bold: true
+ anchors.centerIn: parent
+ y: 0
+ }
+ Text {
+ id: url_notifier
+ text: "<b>URL:</b> " + websocket.url
+ y: 20
+ }
+
+ // PING BUTTON
+ Button {
+ text: "Ping!"
+ onClicked: {
+ request_str = '[' + msgid_enu.call + ',"99999","xxxxxx/ping", null ]';
+ websocket.sendTextMessage (request_str)
+ }
+ anchors.horizontalCenter: parent.horizontalCenter
+ y: 60
+ }
+
+ // STATUS SECTION
+ Text {
+ id: status_notifier
+ text: "<b>Status</b>: " + status_str
+ y: 100
+ }
+ }
+
+}