<div dir="ltr"><div><div><div><div><div><div>Hi Pavel,<br><br></div>The Uint8Array is an event. i don't know if there are more events than port opened or port closed. The value 0 is sent when the port device file is opened in the VM side and the 1 is sent when in the VM side you close device file, so I left it as is because I don't know if there are other possible events that can be handled by the user.<br><br></div>About the format for the data arriving in the port you're right. We can leave it "as-is".<br><br></div>I will change the console messages for printing just the events and that we received data to avoid browser locking. Also will add a DEBUG > 0 && for showing them only when debugging.<br><br></div>Finally I will put the code as a coment then. :)<br><br></div>Thanks. Will send the last commit again in a few.<br><br></div>Cheers!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 10:51 AM, Pavel Grunt <span dir="ltr"><<a href="mailto:pgrunt@redhat.com" target="_blank">pgrunt@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Oliver,<br>
<br>
I tested it (in FF) and it works nicely, I just have minor comments:<br>
in the console:<br>
SPICE port com.spice.fc.1 event data: Uint8Array { 0=0}<br>
SPICE port com.spice.fc.1 message text: CHILI<br>
SPICE port com.spice.fc.1 event data: Uint8Array { 0=1}<br>
<br>
1) what is the Uint8Array - it has just one value (port opened ?), a<br>
boolean could be more clear<br>
<br>
2) there is no guarantee that data are text, i think it would be<br>
better to have it as Uint8Array<br>
<br>
3) not sure if it is a good idea to print to console by default,<br>
consider someone does:<br>
dd=if=/dev/urandom of=/dev/virtio-ports/port ...<br>
it could block the browser<br>
<br>
<br>
The code handling the event in the html files could be just an comment<br>
(to server as an example for somebody implementing something on top of<br>
the port channel)<br>
<br>
Thanks for the contribution,<br>
Pavel<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, 2016-09-29 at 08:59 +0200, Oliver Gutierrez wrote:<br>
> Here is an small guide to test this for the ones that want to check<br>
> it faster:<br>
><br>
> Add a spiceport to a virtual machine adding this under devices in<br>
> the XML<br>
><br>
> <channel type='spiceport'><br>
> <source channel='org.freedesktop.<wbr>FleetCommander.0'/><br>
> <target type='virtio'<br>
> name='org.freedesktop.<wbr>FleetCommander.0'/><br>
> <address type='virtio-serial' controller='0' bus='0'<br>
> port='2'/><br>
> </channel><br>
><br>
><br>
> Boot machine, Connect to it as usual using spice-html5 and as root:<br>
><br>
> echo "CHILI" > /dev/virtio-ports/org.<wbr>freedesktop.FleetCommander.0<br>
><br>
> In the browser console yo sould see the events for opening the port,<br>
> the message and the port closing.<br>
><br>
> If in a week or so there is no other feedback then I will contact<br>
> you Jeremy.<br>
><br>
> Thanks and cheers!<br>
><br>
> On Wed, Sep 28, 2016 at 10:10 PM, Jeremy White <jwhite@codeweavers.c<br>
> om> wrote:<br>
> > Looks good to me. I don't have the time to test this myself, so<br>
> > I'll<br>
> > leave this open for others to kibitz for now.<br>
> ><br>
> > I don't think it will do harm, so if no one else expresses an<br>
> > opinion<br>
> > after a while, you can probably nudge me into pushing it.<br>
> ><br>
> > Reviewed-by: Jeremy White <<a href="mailto:jwhite@codeweavers.com">jwhite@codeweavers.com</a>><br>
> ><br>
> > Cheers,<br>
> ><br>
> > Jeremy<br>
> ><br>
> > On 09/27/2016 10:29 AM, Oliver Gutierrez wrote:<br>
> > > ---<br>
> > > enums.js | 9 ++++++<br>
> > > main.js | 3 ++<br>
> > > port.js | 85<br>
> > ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++++++++++++<br>
> > > spice.html | 10 +++++++<br>
> > > spice_auto.html | 10 +++++++<br>
> > > spicemsg.js | 18 ++++++++++++<br>
> > > utils.js | 7 +++++<br>
> > > 7 files changed, 142 insertions(+)<br>
> > > create mode 100644 port.js<br>
> > ><br>
> > > diff --git a/enums.js b/enums.js<br>
> > > index 301fea0..b6e013c 100644<br>
> > > --- a/enums.js<br>
> > > +++ b/enums.js<br>
> > > @@ -166,6 +166,15 @@ var SPICE_MSG_PLAYBACK_VOLUME =<br>
> > 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>
> > > diff --git a/main.js b/main.js<br>
> > > index 874a038..2d8a1ff 100644<br>
> > > --- a/main.js<br>
> > > +++ b/main.js<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 @@<br>
> > SpiceMainConn.prototype.<wbr>process_channel_message = function(msg)<br>
> > > this.cursor = new SpiceCursorConn(conn);<br>
> > > else if (chans.channels[i].type ==<br>
> > SPICE_CHANNEL_PLAYBACK)<br>
> > > this.cursor = new SpicePlaybackConn(conn);<br>
> > > + else if (chans.channels[i].type ==<br>
> > 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<br>
> > modify<br>
> > > + it under the terms of the GNU Lesser General Public License<br>
> > as published by<br>
> > > + the Free Software Foundation, either version 3 of the<br>
> > License, or<br>
> > > + (at your option) any later version.<br>
> > > +<br>
> > > + spice-html5 is distributed in the hope that it will be<br>
> > useful,<br>
> > > + but WITHOUT ANY WARRANTY; without even the implied warranty<br>
> > of<br>
> > > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See<br>
> > the<br>
> > > + GNU Lesser General Public License for more details.<br>
> > > +<br>
> > > + You should have received a copy of the GNU Lesser General<br>
> > Public License<br>
> > > + along with spice-html5. If not, see <<a href="http://www.gnu.org/lic" rel="noreferrer" target="_blank">http://www.gnu.org/lic</a><br>
> > enses/>.<br>
> > > +*/<br>
> > > +<br>
> > > +/*---------------------------<wbr>------------------------------<wbr>----<br>
> > ---------------<br>
> > > +** SpicePortConn<br>
> > > +** Drive the Spice Port Channel<br>
> > > +**---------------------------<wbr>------------------------------<wbr>----<br>
> > -------------*/<br>
> > > +function SpicePortConn()<br>
> > > +{<br>
> > > + DEBUG > 0 && console.log('SPICE port: created SPICE port<br>
> > 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<br>
> > 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',<br>
> > this.portName, 'initialized');<br>
> > > + return true;<br>
> > > + }<br>
> > > +<br>
> > > + DEBUG > 0 && console.log('SPICE port: Port',<br>
> > 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<br>
> > 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<br>
> > 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<br>
> > type not recognized:', msg)<br>
> > > + }<br>
> > > +<br>
> > > + return false;<br>
> > > +};<br>
> > > diff --git a/spice.html b/spice.html<br>
> > > index c473678..f736c59 100644<br>
> > > --- a/spice.html<br>
> > > +++ b/spice.html<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>
> > > @@ -142,6 +143,15 @@<br>
> > > }<br>
> > > }<br>
> > ><br>
> > > + window.addEventListener('<wbr>spice-port-data',<br>
> > function(event) {<br>
> > > + var msg_text = arraybuffer_to_str(new<br>
> > Uint8Array(event.detail.data))<wbr>;<br>
> > > + console.log('SPICE port',<br>
> > event.detail.channel.portName, 'message text:', msg_text);<br>
> > > + });<br>
> > > +<br>
> > > + window.addEventListener('<wbr>spice-port-event',<br>
> > function(event) {<br>
> > > + console.log('SPICE port',<br>
> > event.detail.channel.portName, 'event data:',<br>
> > event.detail.spiceEvent);<br>
> > > + });<br>
> > > +<br>
> > > </script><br>
> > ><br>
> > > </head><br>
> > > diff --git a/spice_auto.html b/spice_auto.html<br>
> > > index 1179ebe..304655c 100644<br>
> > > --- a/spice_auto.html<br>
> > > +++ b/spice_auto.html<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',<br>
> > function(event) {<br>
> > > + var msg_text = arraybuffer_to_str(new<br>
> > Uint8Array(event.detail.data))<wbr>;<br>
> > > + console.log('SPICE port',<br>
> > event.detail.channel.portName, 'message text:', msg_text);<br>
> > > + });<br>
> > > +<br>
> > > + window.addEventListener('<wbr>spice-port-event',<br>
> > function(event) {<br>
> > > + console.log('SPICE port',<br>
> > event.detail.channel.portName, 'event data:',<br>
> > event.detail.spiceEvent);<br>
> > > + });<br>
> > > +<br>
> > > connect();<br>
> > > </script><br>
> > ><br>
> > > diff --git a/spicemsg.js b/spicemsg.js<br>
> > > index 0321cc7..3619996 100644<br>
> > > --- a/spicemsg.js<br>
> > > +++ b/spicemsg.js<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>
> > ---------------<br>
> > > +** Convert arraybuffer to string<br>
> > > +**---------------------------<wbr>------------------------------<wbr>----<br>
> > -------------*/<br>
> > > +function arraybuffer_to_str(buf) {<br>
> > > + return String.fromCharCode.apply(<wbr>null, new Uint16Array(buf));<br>
> > > +}<br>
> > > +<br>
> > > +/*---------------------------<wbr>------------------------------<wbr>----<br>
> > ---------------<br>
> > > ** Converting keycodes to AT scancodes is very hard.<br>
> > > ** luckly there are some resources on the web and in the Xorg<br>
> > driver that help<br>
> > > ** us figure out what browser dependent keycodes match to what<br>
> > scancodes.<br>
> > ><br>
> ><br>
> > ______________________________<wbr>_________________<br>
> > Spice-devel mailing list<br>
> > <a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.<wbr>org</a><br>
> > <a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/spice-devel</a><br>
> ><br>
><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> Spice-devel mailing list<br>
> <a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.<wbr>org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/spice-devel</a><br>
><br>
</div></div></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>