<div dir="ltr"><div><div><div>Here is an small guide to test this for the ones that want to check it faster:<br><br></div>Add a spiceport to a virtual machine adding this under devices in the XML<br><br><channel type='spiceport'><br>      <source channel='org.freedesktop.FleetCommander.0'/><br>      <target type='virtio' name='org.freedesktop.FleetCommander.0'/><br>      <address type='virtio-serial' controller='0' bus='0' port='2'/><br>    </channel><br><br><br></div>Boot machine, Connect to it as usual using spice-html5 and as root:<br><br></div><div>echo "CHILI" > /dev/virtio-ports/org.freedesktop.FleetCommander.0<br><br></div><div>In the browser console yo sould see the events for opening the port, the message and the port closing.<br><br></div><div>If in a week or so there is no other feedback then I will contact you Jeremy.<br><br></div><div>Thanks and cheers!<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 28, 2016 at 10:10 PM, Jeremy White <span dir="ltr"><<a href="mailto:jwhite@codeweavers.com" target="_blank">jwhite@codeweavers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Looks good to me.  I don't have the time to test this myself, so 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 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>
<div><div class="h5"><br>
On 09/27/2016 10:29 AM, Oliver Gutierrez wrote:<br>
> ---<br>
>  enums.js        |  9 ++++++<br>
>  main.js         |  3 ++<br>
>  port.js         | 85 ++++++++++++++++++++++++++++++<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           = 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 @@ 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 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', 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 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', 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 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>
> +**  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>
><br>
<br>
</div></div>______________________________<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>
</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>