From b2eeff74bc4e0e003bc01bf108c9d90dd6794606 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 31 Oct 2013 16:27:55 +0100 Subject: Refactor QWebChannel to use a custom WebSocket server implementation. The code is much simpler in my opinion and much faster and far more stable. Especially the timer issues or multiple signal connects are now properly resolved. Also simplify the QML WebChannel API: - Rename slot to sendRawMessage and signal to rawMessageReceived - Add a QML helper that has a respond and sendMessage method that transforms the input to the expected JSON format. Change-Id: Ic3266329d1a2877bd46227e4ad70b88dc340d289 Reviewed-by: Pierre Rossi --- examples/hybridshell/qml/hybridshell/index.html | 62 +++++++++++++++++-------- examples/hybridshell/qml/hybridshell/main.qml | 18 ++++--- examples/qmlapp/index.html | 14 +++--- examples/qmlapp/qmlapp.qml | 47 +++++++++++-------- examples/qtobject/qml/qtobject/index.html | 26 +++++------ examples/qtobject/qml/qtobject/main.qml | 15 ++++-- 6 files changed, 110 insertions(+), 72 deletions(-) (limited to 'examples') diff --git a/examples/hybridshell/qml/hybridshell/index.html b/examples/hybridshell/qml/hybridshell/index.html index a76f047..b93daab 100644 --- a/examples/hybridshell/qml/hybridshell/index.html +++ b/examples/hybridshell/qml/hybridshell/index.html @@ -1,38 +1,48 @@ + - - - + - - - + +
+ + +
diff --git a/examples/hybridshell/qml/hybridshell/main.qml b/examples/hybridshell/qml/hybridshell/main.qml index c46aaa2..d6d598d 100644 --- a/examples/hybridshell/qml/hybridshell/main.qml +++ b/examples/hybridshell/qml/hybridshell/main.qml @@ -51,27 +51,33 @@ Rectangle { id: shell onStdoutData: { console.log(data); - webChannel.broadcast("stdout", data); + webChannel.sendMessage("stdout", data); } onStderrData: { - webChannel.broadcast("stderr", data); + console.error(data); + webChannel.sendMessage("stderr", data); } } WebChannel { id: webChannel - onExecute: { - shell.exec(requestData); + onRawMessageReceived: { + shell.exec(JSON.parse(rawMessage).data); } - onBaseUrlChanged: shell.start() + onInitialized: { + shell.start() + webView.url = "index.html?webChannelBaseUrl=" + webChannel.baseUrl; + } } width: 480 height: 800 WebView { + id: webView anchors.fill: parent - url: "index.html?webChannelBaseUrl=" + webChannel.baseUrl + url: "about:blank" + experimental.preferences.developerExtrasEnabled: true } } diff --git a/examples/qmlapp/index.html b/examples/qmlapp/index.html index f62a386..4f4593c 100644 --- a/examples/qmlapp/index.html +++ b/examples/qmlapp/index.html @@ -1,15 +1,15 @@ + - + - + diff --git a/examples/qtobject/qml/qtobject/main.qml b/examples/qtobject/qml/qtobject/main.qml index 2ca26ec..7a63cd2 100644 --- a/examples/qtobject/qml/qtobject/main.qml +++ b/examples/qtobject/qml/qtobject/main.qml @@ -68,14 +68,19 @@ Rectangle { WebChannel { id: webChannel - onExecute: { - var payload = JSON.parse(requestData); - if (!publisher.handleRequest(payload, webChannel, response)) { - console.log("unhandled request: ", requestData); + onRawMessageReceived: { + if (!publisher.handleRequest(rawMessage, webChannel)) { + console.log("unhandled request: ", rawMessage); } } - onInitialized: publisher.registerObjects({"testObject1": testObject1, "testObject2": testObject2, "testObject3":testObject3}); + onInitialized: { + publisher.registerObjects({ + "testObject1": testObject1, + "testObject2": testObject2, + "testObject3":testObject3 + }); + } } width: 480 -- cgit v1.2.1