OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; |
| 9 |
| 10 /** |
| 11 * Simplified SignalStrategy implementation that wraps an underlying signal |
| 12 * strategy and forwards messages when it is CONNECTED. It is used only to |
| 13 * log status messages during IT2Me connection setup, and only those methods |
| 14 * required for that are implemented. |
| 15 * |
| 16 * TODO(jamiewalch): Remove this class once a signal strategy is no longer |
| 17 * required for logging (crbug.com/497269). |
| 18 * |
| 19 * @constructor |
| 20 * @param {remoting.SignalStrategy} underlying The underlying implementation. |
| 21 * @implements {remoting.SignalStrategy} |
| 22 */ |
| 23 remoting.BufferedSignalStrategy = function(underlying) { |
| 24 /** @private */ |
| 25 this.underlying_ = underlying; |
| 26 /** @private {Array<string>} */ |
| 27 this.pendingMessages_ = []; |
| 28 |
| 29 this.underlying_.setStateChangedCallback(this.flush_.bind(this)); |
| 30 }; |
| 31 |
| 32 remoting.BufferedSignalStrategy.prototype.dispose = function() { |
| 33 this.underlying_.dispose(); |
| 34 }; |
| 35 |
| 36 /** |
| 37 * Sends a message. Can be called only in CONNECTED state. |
| 38 * @param {string} message |
| 39 */ |
| 40 remoting.BufferedSignalStrategy.prototype.sendMessage = function(message) { |
| 41 this.pendingMessages_.push(message); |
| 42 this.flush_(); |
| 43 }; |
| 44 |
| 45 /** |
| 46 * Send any messages accumulated during connection set-up. |
| 47 * |
| 48 * @param {remoting.LogToServer} logToServer The LogToServer instance for the |
| 49 * connection. |
| 50 */ |
| 51 remoting.BufferedSignalStrategy.prototype.sendConnectionSetupResults = |
| 52 function(logToServer) { |
| 53 this.underlying_.sendConnectionSetupResults(logToServer); |
| 54 }; |
| 55 |
| 56 /** |
| 57 * If the underlying implementation is connected, flush all pending messages. |
| 58 * @private |
| 59 */ |
| 60 remoting.BufferedSignalStrategy.prototype.flush_ = function() { |
| 61 if (this.underlying_.getState() !== remoting.SignalStrategy.State.CONNECTED) { |
| 62 return; |
| 63 } |
| 64 for (var i = 0; i < this.pendingMessages_.length; ++i) { |
| 65 this.underlying_.sendMessage(this.pendingMessages_[i]); |
| 66 } |
| 67 this.pendingMessages_ = []; |
| 68 }; |
| 69 |
| 70 |
| 71 // The following methods are not used by LogToServer and are not implemented. |
| 72 |
| 73 remoting.BufferedSignalStrategy.prototype.setStateChangedCallback = |
| 74 function(onStateChangedCallback) { |
| 75 base.debug.assert(false); |
| 76 }; |
| 77 |
| 78 remoting.BufferedSignalStrategy.prototype.setIncomingStanzaCallback = |
| 79 function(onIncomingStanzaCallback) { |
| 80 base.debug.assert(false); |
| 81 }; |
| 82 |
| 83 remoting.BufferedSignalStrategy.prototype.connect = |
| 84 function(server, username, authToken) { |
| 85 base.debug.assert(false); |
| 86 }; |
| 87 |
| 88 remoting.BufferedSignalStrategy.prototype.sendConnectionSetupResults = |
| 89 function(logToServer) { |
| 90 base.debug.assert(false); |
| 91 }; |
| 92 |
| 93 remoting.BufferedSignalStrategy.prototype.getState = function() { |
| 94 base.debug.assert(false); |
| 95 }; |
| 96 |
| 97 remoting.BufferedSignalStrategy.prototype.getError = function() { |
| 98 base.debug.assert(false); |
| 99 }; |
| 100 |
| 101 remoting.BufferedSignalStrategy.prototype.getJid = function() { |
| 102 base.debug.assert(false); |
| 103 }; |
| 104 |
| 105 remoting.BufferedSignalStrategy.prototype.getType = function() { |
| 106 base.debug.assert(false); |
| 107 }; |
OLD | NEW |