<div dir="ltr">I finally put all in the same patch with the Textdecoder part removed. Just added an utility function to do that in utils.js<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 26, 2016 at 1:02 PM, Oliver Gutierrez <span dir="ltr"><<a href="mailto:ogutierrez@redhat.com" target="_blank">ogutierrez@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
enums.js | 11 +++++++-<br>
main.js | 5 +++-<br>
port.js | 85 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++++++++++++<br>
spice.html | 50 +++++++++++++++++++-----------<wbr>---<br>
spice_auto.html | 12 +++++++-<br>
spicemsg.js | 24 ++++++++++++++--<br>
utils.js | 7 +++++<br>
7 files changed, 168 insertions(+), 26 deletions(-)<br>
create mode 100644 port.js<br>
<br>
diff --git a/enums.js b/enums.js<br>
index 3ef36dc..b6e013c 100644<br>
--- a/enums.js<br>
+++ b/enums.js<br>
@@ -166,6 +166,15 @@ var SPICE_MSG_PLAYBACK_VOLUME = 105;<br>
var SPICE_MSG_PLAYBACK_MUTE = 106;<br>
var SPICE_MSG_PLAYBACK_LATENCY = 107;<br>
<br>
+var SPICE_MSG_SPICEVMC_DATA = 101;<br>
+var SPICE_MSG_PORT_INIT = 201;<br>
+var SPICE_MSG_PORT_EVENT = 202;<br>
+var SPICE_MSG_END_PORT = 203;<br>
+<br>
+var SPICE_MSGC_SPICEVMC_DATA = 101;<br>
+var SPICE_MSGC_PORT_EVENT = 201;<br>
+var SPICE_MSGC_END_PORT = 202;<br>
+<br>
var SPICE_PLAYBACK_CAP_CELT_0_5_1 = 0;<br>
var SPICE_PLAYBACK_CAP_VOLUME = 1;<br>
var SPICE_PLAYBACK_CAP_LATENCY = 2;<br>
@@ -264,7 +273,7 @@ var SPICE_MOUSE_BUTTON_MASK_LEFT = (1 << 0),<br>
SPICE_MOUSE_BUTTON_MASK_MIDDLE = (1 << 1),<br>
SPICE_MOUSE_BUTTON_MASK_RIGHT = (1 << 2),<br>
SPICE_MOUSE_BUTTON_MASK_MASK = 0x7;<br>
-<br>
+<br>
var SPICE_MOUSE_BUTTON_INVALID = 0;<br>
var SPICE_MOUSE_BUTTON_LEFT = 1;<br>
var SPICE_MOUSE_BUTTON_MIDDLE = 2;<br>
diff --git a/main.js b/main.js<br>
index afe69bf..2d8a1ff 100644<br>
--- a/main.js<br>
+++ b/main.js<br>
@@ -22,7 +22,7 @@<br>
** SpiceMainConn<br>
** This is the master Javascript class for establishing and<br>
** managing a connection to a Spice Server.<br>
-**<br>
+**<br>
** Invocation: You must pass an object with properties as follows:<br>
** uri (required) Uri of a WebSocket listener that is<br>
** connected to a spice server.<br>
@@ -59,6 +59,7 @@ function SpiceMainConn()<br>
this.file_xfer_tasks = {};<br>
this.file_xfer_task_id = 0;<br>
this.file_xfer_read_queue = [];<br>
+ this.ports = [];<br>
}<br>
<br>
SpiceMainConn.prototype = Object.create(SpiceConn.<wbr>prototype);<br>
@@ -154,6 +155,8 @@ SpiceMainConn.prototype.<wbr>process_channel_message = function(msg)<br>
this.cursor = new SpiceCursorConn(conn);<br>
else if (chans.channels[i].type == SPICE_CHANNEL_PLAYBACK)<br>
this.cursor = new SpicePlaybackConn(conn);<br>
+ else if (chans.channels[i].type == SPICE_CHANNEL_PORT)<br>
+ this.ports.push(new SpicePortConn(conn));<br>
else<br>
{<br>
if (! ("extra_channels" in this))<br>
diff --git a/port.js b/port.js<br>
new file mode 100644<br>
index 0000000..ee22073<br>
--- /dev/null<br>
+++ b/port.js<br>
@@ -0,0 +1,85 @@<br>
+"use strict";<br>
+/*<br>
+ Copyright (C) 2016 by Oliver Gutierrez <<a href="mailto:ogutsua@gmail.com">ogutsua@gmail.com</a>><br>
+ Miroslav Chodil <<a href="mailto:mchodil@redhat.com">mchodil@redhat.com</a>><br>
+<br>
+ This file is part of spice-html5.<br>
+<br>
+ spice-html5 is free software: you can redistribute it and/or modify<br>
+ it under the terms of the GNU Lesser General Public License as published by<br>
+ the Free Software Foundation, either version 3 of the License, or<br>
+ (at your option) any later version.<br>
+<br>
+ spice-html5 is distributed in the hope that it will be useful,<br>
+ but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
+ GNU Lesser General Public License for more details.<br>
+<br>
+ You should have received a copy of the GNU Lesser General Public License<br>
+ along with spice-html5. If not, see <<a href="http://www.gnu.org/licenses/" rel="noreferrer" target="_blank">http://www.gnu.org/licenses/</a>><wbr>.<br>
+*/<br>
+<br>
+/*---------------------------<wbr>------------------------------<wbr>-------------------<br>
+** SpicePortConn<br>
+** Drive the Spice Port Channel<br>
+**---------------------------<wbr>------------------------------<wbr>-----------------*/<br>
+function SpicePortConn()<br>
+{<br>
+ DEBUG > 0 && console.log('SPICE port: created SPICE port channel. Args:', arguments);<br>
+ SpiceConn.apply(this, arguments);<br>
+ this.port_name = null;<br>
+}<br>
+<br>
+SpicePortConn.prototype = Object.create(SpiceConn.<wbr>prototype);<br>
+<br>
+SpicePortConn.prototype.<wbr>process_channel_message = function(msg)<br>
+{<br>
+ if (msg.type == SPICE_MSG_PORT_INIT)<br>
+ {<br>
+ if (this.port_name === null)<br>
+ {<br>
+ var m = new SpiceMsgPortInit(msg.data);<br>
+ this.portName = arraybuffer_to_str(new Uint8Array(<a href="http://m.name" rel="noreferrer" target="_blank">m.name</a>));<br>
+ this.portOpened = m.opened<br>
+ DEBUG > 0 && console.log('SPICE port: Port', this.portName, 'initialized');<br>
+ return true;<br>
+ }<br>
+<br>
+ DEBUG > 0 && console.log('SPICE port: Port', this.port_name, 'is already initialized.');<br>
+ }<br>
+ else if (msg.type == SPICE_MSG_PORT_EVENT)<br>
+ {<br>
+ DEBUG > 0 && console.log('SPICE port: Port event received for', this.portName, msg);<br>
+ var event = new CustomEvent('spice-port-event'<wbr>, {<br>
+ detail: {<br>
+ channel: this,<br>
+ spiceEvent: new Uint8Array(msg.data)<br>
+ },<br>
+ bubbles: true,<br>
+ cancelable: true<br>
+ });<br>
+<br>
+ window.dispatchEvent(event);<br>
+ return true;<br>
+ }<br>
+ else if (msg.type == SPICE_MSG_SPICEVMC_DATA)<br>
+ {<br>
+ DEBUG > 0 && console.log('SPICE port: Data received in port', this.portName, msg);<br>
+ var event = new CustomEvent('spice-port-data', {<br>
+ detail: {<br>
+ channel: this,<br>
+ data: msg.data<br>
+ },<br>
+ bubbles: true,<br>
+ cancelable: true<br>
+ });<br>
+ window.dispatchEvent(event);<br>
+ return true;<br>
+ }<br>
+ else<br>
+ {<br>
+ DEBUG > 0 && console.log('SPICE port: SPICE message type not recognized:', msg)<br>
+ }<br>
+<br>
+ return false;<br>
+};<br>
diff --git a/spice.html b/spice.html<br>
index f2f9ed0..f736c59 100644<br>
--- a/spice.html<br>
+++ b/spice.html<br>
@@ -28,26 +28,27 @@<br>
<head><br>
<br>
<title>Spice Javascript client</title><br>
- <script src="spicearraybuffer.js"></<wbr>script><br>
- <script src="enums.js"></script><br>
- <script src="atKeynames.js"></script><br>
- <script src="utils.js"></script><br>
- <script src="png.js"></script><br>
- <script src="lz.js"></script><br>
- <script src="quic.js"></script><br>
- <script src="bitmap.js"></script><br>
- <script src="spicedataview.js"></<wbr>script><br>
- <script src="spicetype.js"></script><br>
- <script src="spicemsg.js"></script><br>
- <script src="wire.js"></script><br>
- <script src="spiceconn.js"></script><br>
- <script src="display.js"></script><br>
- <script src="main.js"></script><br>
- <script src="inputs.js"></script><br>
+ <script src="spicearraybuffer.js"></<wbr>script><br>
+ <script src="enums.js"></script><br>
+ <script src="atKeynames.js"></script><br>
+ <script src="utils.js"></script><br>
+ <script src="png.js"></script><br>
+ <script src="lz.js"></script><br>
+ <script src="quic.js"></script><br>
+ <script src="bitmap.js"></script><br>
+ <script src="spicedataview.js"></<wbr>script><br>
+ <script src="spicetype.js"></script><br>
+ <script src="spicemsg.js"></script><br>
+ <script src="wire.js"></script><br>
+ <script src="spiceconn.js"></script><br>
+ <script src="display.js"></script><br>
+ <script src="port.js"></script><br>
+ <script src="main.js"></script><br>
+ <script src="inputs.js"></script><br>
<script src="webm.js"></script><br>
<script src="playback.js"></script><br>
<script src="simulatecursor.js"></<wbr>script><br>
- <script src="cursor.js"></script><br>
+ <script src="cursor.js"></script><br>
<script src="thirdparty/jsbn.js"></<wbr>script><br>
<script src="thirdparty/rsa.js"></<wbr>script><br>
<script src="thirdparty/prng4.js"></<wbr>script><br>
@@ -71,8 +72,8 @@<br>
{<br>
var host, port, password, scheme = "ws://", uri;<br>
<br>
- host = document.getElementById("host"<wbr>).value;<br>
- port = document.getElementById("port"<wbr>).value;<br>
+ host = document.getElementById("host"<wbr>).value;<br>
+ port = document.getElementById("port"<wbr>).value;<br>
password = document.getElementById("<wbr>password").value;<br>
<br>
<br>
@@ -92,7 +93,7 @@<br>
<br>
try<br>
{<br>
- sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",<br>
+ sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",<br>
message_id: "message-div", password: password, onerror: spice_error, onagent: agent_connected });<br>
}<br>
catch (e)<br>
@@ -142,6 +143,15 @@<br>
}<br>
}<br>
<br>
+ window.addEventListener('<wbr>spice-port-data', function(event) {<br>
+ var msg_text = arraybuffer_to_str(new Uint8Array(event.detail.data))<wbr>;<br>
+ console.log('SPICE port', event.detail.channel.portName, 'message text:', msg_text);<br>
+ });<br>
+<br>
+ window.addEventListener('<wbr>spice-port-event', function(event) {<br>
+ console.log('SPICE port', event.detail.channel.portName, 'event data:', event.detail.spiceEvent);<br>
+ });<br>
+<br>
</script><br>
<br>
</head><br>
diff --git a/spice_auto.html b/spice_auto.html<br>
index 9aae118..304655c 100644<br>
--- a/spice_auto.html<br>
+++ b/spice_auto.html<br>
@@ -28,7 +28,7 @@<br>
<head><br>
<br>
<title>Spice Javascript client</title><br>
- <script src="spicearraybuffer.js"></<wbr>script><br>
+ <script src="spicearraybuffer.js"></<wbr>script><br>
<script src="enums.js"></script><br>
<script src="atKeynames.js"></script><br>
<script src="utils.js"></script><br>
@@ -42,6 +42,7 @@<br>
<script src="wire.js"></script><br>
<script src="spiceconn.js"></script><br>
<script src="display.js"></script><br>
+ <script src="port.js"></script><br>
<script src="main.js"></script><br>
<script src="inputs.js"></script><br>
<script src="webm.js"></script><br>
@@ -182,6 +183,15 @@<br>
}<br>
}<br>
<br>
+ window.addEventListener('<wbr>spice-port-data', function(event) {<br>
+ var msg_text = arraybuffer_to_str(new Uint8Array(event.detail.data))<wbr>;<br>
+ console.log('SPICE port', event.detail.channel.portName, 'message text:', msg_text);<br>
+ });<br>
+<br>
+ window.addEventListener('<wbr>spice-port-event', function(event) {<br>
+ console.log('SPICE port', event.detail.channel.portName, 'event data:', event.detail.spiceEvent);<br>
+ });<br>
+<br>
connect();<br>
</script><br>
<br>
diff --git a/spicemsg.js b/spicemsg.js<br>
index db6625a..3619996 100644<br>
--- a/spicemsg.js<br>
+++ b/spicemsg.js<br>
@@ -21,7 +21,7 @@<br>
/*----------------------------<wbr>------------------------------<wbr>------------------<br>
** Spice messages<br>
** This file contains classes for passing messages to and from<br>
-** a spice server. This file should arguably be generated from<br>
+** a spice server. This file should arguably be generated from<br>
** spice.proto, but it was instead put together by hand.<br>
**----------------------------<wbr>------------------------------<wbr>----------------*/<br>
function SpiceLinkHeader(a, at)<br>
@@ -63,7 +63,7 @@ SpiceLinkHeader.prototype =<br>
dv.setUint32(at, this.size, true); at += 4;<br>
},<br>
buffer_size: function()<br>
- {<br>
+ {<br>
return 16;<br>
},<br>
}<br>
@@ -938,7 +938,7 @@ function SpiceMsgcMousePosition(sc, e)<br>
this.x = e.clientX - sc.display.surfaces[sc.<wbr>display.primary_surface].<wbr>canvas.offsetLeft + scrollLeft;<br>
this.y = e.clientY - sc.display.surfaces[sc.<wbr>display.primary_surface].<wbr>canvas.offsetTop + scrollTop;<br>
sc.mousex = this.x;<br>
- sc.mousey = this.y;<br>
+ sc.mousey = this.y;<br>
}<br>
else<br>
{<br>
@@ -1278,3 +1278,21 @@ SpiceMsgDisplayInvalList.<wbr>prototype =<br>
}<br>
},<br>
}<br>
+<br>
+function SpiceMsgPortInit(a, at)<br>
+{<br>
+ this.from_buffer(a,at);<br>
+};<br>
+<br>
+SpiceMsgPortInit.prototype =<br>
+{<br>
+ from_buffer: function (a, at)<br>
+ {<br>
+ at = at || 0;<br>
+ var dv = new SpiceDataView(a);<br>
+ var namesize = dv.getUint32(at, true); at += 4;<br>
+ var offset = dv.getUint32(at, true); at += 4;<br>
+ this.opened = dv.getUint8(at, true); at += 1;<br>
+ <a href="http://this.name" rel="noreferrer" target="_blank">this.name</a> = a.slice(offset, offset + namesize - 1);<br>
+ }<br>
+}<br>
diff --git a/utils.js b/utils.js<br>
index 9093a24..a22d0ae 100644<br>
--- a/utils.js<br>
+++ b/utils.js<br>
@@ -100,6 +100,13 @@ function hexdump_buffer(a)<br>
}<br>
<br>
/*----------------------------<wbr>------------------------------<wbr>------------------<br>
+** Convert arraybuffer to string<br>
+**---------------------------<wbr>------------------------------<wbr>-----------------*/<br>
+function arraybuffer_to_str(buf) {<br>
+ return String.fromCharCode.apply(<wbr>null, new Uint16Array(buf));<br>
+}<br>
+<br>
+/*---------------------------<wbr>------------------------------<wbr>-------------------<br>
** Converting keycodes to AT scancodes is very hard.<br>
** luckly there are some resources on the web and in the Xorg driver that help<br>
** us figure out what browser dependent keycodes match to what scancodes.<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.3<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span>Oliver Gutierrez<br>Associate Software Engineer - Desktop Management tools<br>Red Hat</span></div></div>
</div>