<div dir="ltr">This patch has not been pushed yet. Is there any problem?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 5, 2016 at 8:06 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>
it looks good to me :)<br>
<br>
Acked-by: Pavel Grunt <<a href="mailto:pgrunt@redhat.com">pgrunt@redhat.com</a>><br>
<br>
Thanks,<br>
Pavel<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, 2016-10-03 at 14:09 +0200, Oliver Gutierrez wrote:<br>
> ---<br>
>  enums.js        |  9 ++++++<br>
>  main.js         |  3 ++<br>
>  port.js         | 85<br>
> ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++++++++++++<br>
>  spice.html      | 13 +++++++++<br>
>  spice_auto.html | 13 +++++++++<br>
>  spicemsg.js     | 18 ++++++++++++<br>
>  utils.js        |  7 +++++<br>
>  7 files changed, 148 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     <wbr>      = 105;<br>
>  var SPICE_MSG_PLAYBACK_MUTE       <wbr>      = 106;<br>
>  var SPICE_MSG_PLAYBACK_LATENCY    <wbr>      = 107;<br>
>  <br>
> +var SPICE_MSG_SPICEVMC_DATA       <wbr>      = 101;<br>
> +var SPICE_MSG_PORT_INIT           <wbr>      = 201;<br>
> +var SPICE_MSG_PORT_EVENT          <wbr>      = 202;<br>
> +var SPICE_MSG_END_PORT            <wbr>      = 203;<br>
> +<br>
> +var SPICE_MSGC_SPICEVMC_DATA      <wbr>      = 101;<br>
> +var SPICE_MSGC_PORT_EVENT         <wbr>      = 201;<br>
> +var SPICE_MSGC_END_PORT           <wbr>      = 202;<br>
> +<br>
>  var SPICE_PLAYBACK_CAP_CELT_0_5_1 <wbr>      = 0;<br>
>  var SPICE_PLAYBACK_CAP_VOLUME     <wbr>      = 1;<br>
>  var SPICE_PLAYBACK_CAP_LATENCY    <wbr>      = 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<br>
> = 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 == SPICE_CHANNEL_PORT)<br>
> +                this.ports.<wbr>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>
> +                         <wbr>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 as<br>
> published by<br>
> +   the Free Software Foundation, either version 3 of the License,<br>
> 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<br>
> License<br>
> +   along with spice-html5.  If not, see <<a href="http://www.gnu.org/license" rel="noreferrer" target="_blank">http://www.gnu.org/license</a><br>
> s/>.<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 received<br>
> 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(<wbr>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(<wbr>event);<br>
> +        return true;<br>
> +    }<br>
> +    else<br>
> +    {<br>
> +        DEBUG > 0 && console.log('SPICE port: SPICE message type<br>
> not recognized:', msg)<br>
> +    }<br>
> +<br>
> +    return false;<br>
> +};<br>
> diff --git a/spice.html b/spice.html<br>
> index c473678..d4c9962 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,18 @@<br>
>                  }<br>
>              }<br>
>  <br>
> +            /* SPICE port event listeners<br>
> +            window.<wbr>addEventListener('spice-port-<wbr>data',<br>
> function(event) {<br>
> +                // Here we convert data to text, but really we can<br>
> obtain binary data also<br>
> +                var msg_text = arraybuffer_to_str(new<br>
> Uint8Array(event.detail.data))<wbr>;<br>
> +                DEBUG > 0 && console.log('SPICE port',<br>
> event.detail.channel.portName, 'message text:', msg_text);<br>
> +            });<br>
> +<br>
> +            window.<wbr>addEventListener('spice-port-<wbr>event',<br>
> function(event) {<br>
> +                DEBUG > 0 && console.log('SPICE port',<br>
> event.detail.channel.portName, 'event data:',<br>
> event.detail.spiceEvent);<br>
> +            });<br>
> +            */<br>
> +<br>
>          </script><br>
>  <br>
>      </head><br>
> diff --git a/spice_auto.html b/spice_auto.html<br>
> index 1179ebe..2f04fc9 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,18 @@<br>
>                  }<br>
>              }<br>
>  <br>
> +            /* SPICE port event listeners<br>
> +            window.<wbr>addEventListener('spice-port-<wbr>data',<br>
> function(event) {<br>
> +                // Here we convert data to text, but really we can<br>
> obtain binary data also<br>
> +                var msg_text = arraybuffer_to_str(new<br>
> Uint8Array(event.detail.data))<wbr>;<br>
> +                DEBUG > 0 && console.log('SPICE port',<br>
> event.detail.channel.portName, 'message text:', msg_text);<br>
> +            });<br>
> +<br>
> +            window.<wbr>addEventListener('spice-port-<wbr>event',<br>
> function(event) {<br>
> +                DEBUG > 0 && console.log('SPICE port',<br>
> event.detail.channel.portName, 'event data:',<br>
> event.detail.spiceEvent);<br>
> +            });<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>
</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>