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.
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
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.
16 * TODO(jamiewalch): Remove this class once a signal strategy is no longer
17 * required for logging (crbug.com/497269).
20 * @param {remoting.SignalStrategy} underlying The underlying implementation.
21 * @implements {remoting.SignalStrategy}
23 remoting.BufferedSignalStrategy = function(underlying) {
25 this.underlying_ = underlying;
26 /** @private {Array<string>} */
27 this.pendingMessages_ = [];
29 this.underlying_.setStateChangedCallback(this.flush_.bind(this));
32 remoting.BufferedSignalStrategy.prototype.dispose = function() {
33 this.underlying_.dispose();
37 * Sends a message. Can be called only in CONNECTED state.
38 * @param {string} message
40 remoting.BufferedSignalStrategy.prototype.sendMessage = function(message) {
41 this.pendingMessages_.push(message);
46 * Send any messages accumulated during connection set-up.
48 * @param {remoting.Logger} logger The Logger instance for the connection.
50 remoting.BufferedSignalStrategy.prototype.sendConnectionSetupResults =
52 this.underlying_.sendConnectionSetupResults(logger);
56 * If the underlying implementation is connected, flush all pending messages.
59 remoting.BufferedSignalStrategy.prototype.flush_ = function() {
60 if (this.underlying_.getState() !== remoting.SignalStrategy.State.CONNECTED) {
63 for (var i = 0; i < this.pendingMessages_.length; ++i) {
64 this.underlying_.sendMessage(this.pendingMessages_[i]);
66 this.pendingMessages_ = [];
70 // The following methods are not used by LogToServer and are not implemented.
72 remoting.BufferedSignalStrategy.prototype.setStateChangedCallback =
73 function(onStateChangedCallback) {
74 console.error('Unexpected setStateChangedCallback().');
77 remoting.BufferedSignalStrategy.prototype.setIncomingStanzaCallback =
78 function(onIncomingStanzaCallback) {
79 console.error('Unexpected setIncomingStanzaCallback().');
82 remoting.BufferedSignalStrategy.prototype.connect =
83 function(server, username, authToken) {
84 console.error('Unexpected connect().');
87 remoting.BufferedSignalStrategy.prototype.getState = function() {
88 console.error('Unexpected getState().');
91 remoting.BufferedSignalStrategy.prototype.getError = function() {
92 console.error('Unexpected getError().');
95 remoting.BufferedSignalStrategy.prototype.getJid = function() {
96 console.error('Unexpected getJid().');
99 remoting.BufferedSignalStrategy.prototype.getType = function() {
100 console.error('Unexpected getType().');