diff options
author | Pavel Grunt <pgrunt@redhat.com> | 2015-01-14 17:44:38 +0100 |
---|---|---|
committer | Jeremy White <jwhite@codeweavers.com> | 2015-01-15 08:58:36 -0600 |
commit | 1a4a98938a1ff44789e3a81ad115f4dd86cfee15 (patch) | |
tree | e49dd0efa59c64f03aa1b88f4690dd324a75d35c | |
parent | 6a68399a239f54b96f42e22fe08b46c7125ecf54 (diff) |
Send agent messages only when have agent tokens
Messages that were not sent are stored in the queue.
They will be sent later when the client receives more agent tokens.
-rw-r--r-- | main.js | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -55,6 +55,7 @@ function SpiceMainConn() SpiceConn.apply(this, arguments); + this.agent_msg_queue = []; } SpiceMainConn.prototype = Object.create(SpiceConn.prototype); @@ -160,6 +161,7 @@ SpiceMainConn.prototype.process_channel_message = function(msg) { var tokens = new SpiceMsgMainAgentTokens(msg.data); this.agent_tokens += tokens.num_tokens; + this.send_agent_message_queue(); return true; } @@ -203,18 +205,36 @@ SpiceMainConn.prototype.stop = function(msg) this.extra_channels = undefined; } -SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y) +SpiceMainConn.prototype.send_agent_message_queue = function(message) { - if (this.agent_connected > 0) + if (!this.agent_connected) + return; + + if (message) + this.agent_msg_queue.push(message); + + while (this.agent_tokens > 0 && this.agent_msg_queue.length > 0) { - var monitors_config = new VDAgentMonitorsConfig(flags, width, height, depth, x, y); - var agent_data = new SpiceMsgcMainAgentData(VD_AGENT_MONITORS_CONFIG, monitors_config); - var mr = new SpiceMiniData(); - mr.build_msg(SPICE_MSGC_MAIN_AGENT_DATA, agent_data); + var mr = this.agent_msg_queue.shift(); this.send_msg(mr); + this.agent_tokens--; } } +SpiceMainConn.prototype.send_agent_message = function(type, message) +{ + var agent_data = new SpiceMsgcMainAgentData(type, message); + var mr = new SpiceMiniData(); + mr.build_msg(SPICE_MSGC_MAIN_AGENT_DATA, agent_data); + this.send_agent_message_queue(mr); +} + +SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y) +{ + var monitors_config = new VDAgentMonitorsConfig(flags, width, height, depth, x, y); + this.send_agent_message(VD_AGENT_MONITORS_CONFIG, monitors_config); +} + SpiceMainConn.prototype.connect_agent = function() { this.agent_connected = true; |