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 * If the underlying implementation is connected, flush all pending messages.
49 remoting
.BufferedSignalStrategy
.prototype.flush_ = function() {
50 if (this.underlying_
.getState() !== remoting
.SignalStrategy
.State
.CONNECTED
) {
53 for (var i
= 0; i
< this.pendingMessages_
.length
; ++i
) {
54 this.underlying_
.sendMessage(this.pendingMessages_
[i
]);
56 this.pendingMessages_
= [];
60 // The following methods are not used by LogToServer and are not implemented.
62 remoting
.BufferedSignalStrategy
.prototype.setStateChangedCallback
=
63 function(onStateChangedCallback
) {
64 console
.error('Unexpected setStateChangedCallback().');
67 remoting
.BufferedSignalStrategy
.prototype.setIncomingStanzaCallback
=
68 function(onIncomingStanzaCallback
) {
69 console
.error('Unexpected setIncomingStanzaCallback().');
72 remoting
.BufferedSignalStrategy
.prototype.connect
=
73 function(server
, username
, authToken
) {
74 console
.error('Unexpected connect().');
77 remoting
.BufferedSignalStrategy
.prototype.getState = function() {
78 console
.error('Unexpected getState().');
81 remoting
.BufferedSignalStrategy
.prototype.getError = function() {
82 console
.error('Unexpected getError().');
85 remoting
.BufferedSignalStrategy
.prototype.getJid = function() {
86 console
.error('Unexpected getJid().');
89 remoting
.BufferedSignalStrategy
.prototype.getType = function() {
90 console
.error('Unexpected getType().');