diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/standalone/index.html | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/examples/standalone/index.html b/examples/standalone/index.html index e1a74fb..3cce3ec 100644 --- a/examples/standalone/index.html +++ b/examples/standalone/index.html @@ -10,30 +10,47 @@ var output = document.getElementById("output"); output.innerHTML = output.innerHTML + message + "\n"; } - var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]); - new QWebChannel(baseUrl, function(channel) { - // make dialog object accessible globally - window.dialog = channel.objects.dialog; + window.onload = function() { + var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]); + output("Connecting to WebSocket server at " + baseUrl + "."); + var socket = new WebSocket(baseUrl); - document.getElementById("send").onclick = function() { - var input = document.getElementById("input"); - var text = input.value; - if (!text) { - return; - } + socket.onclose = function() + { + console.error("web channel closed"); + }; + socket.onerror = function(error) + { + console.error("web channel error: " + error); + }; + socket.onopen = function() + { + output("WebSocket connected, setting up QWebChannel."); + new QWebChannel(socket, function(channel) { + // make dialog object accessible globally + window.dialog = channel.objects.dialog; - output("Sent message: " + text); - input.value = ""; - dialog.receiveText(text); - } + document.getElementById("send").onclick = function() { + var input = document.getElementById("input"); + var text = input.value; + if (!text) { + return; + } + + output("Sent message: " + text); + input.value = ""; + dialog.receiveText(text); + } - dialog.sendText.connect(function(message) { - output("Received message: " + message); - }); + dialog.sendText.connect(function(message) { + output("Received message: " + message); + }); - dialog.receiveText("Client connected, ready to send/receive messages!"); - output("Connected to WebChannel, ready to send/receive messages!"); - }); + dialog.receiveText("Client connected, ready to send/receive messages!"); + output("Connected to WebChannel, ready to send/receive messages!"); + }); + } + } //END SETUP </script> <style type="text/css"> |