Chromium Code Reviews| Index: remoting/webapp/me2mom/log_to_server.js |
| diff --git a/remoting/webapp/me2mom/log_to_server.js b/remoting/webapp/me2mom/log_to_server.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e65260b4ccbf7402ddf45e68e8d5e05d5640baea |
| --- /dev/null |
| +++ b/remoting/webapp/me2mom/log_to_server.js |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview |
| + * Module for sending log entries to the server. |
| + */ |
| + |
| +'use strict'; |
| + |
| +/** @suppress {duplicate} */ |
| +var remoting = remoting || {}; |
| + |
| +/** |
| + * @constructor |
| + */ |
| +remoting.LogToServer = function() { |
| + /** @type Array.<string> */ this.pendingEntries = []; |
| +}; |
| + |
| +/** |
| + * Logs a client session state change. |
| + * |
| + * @param {remoting.ClientSession.State} state |
| + * @param {remoting.ClientSession.ConnectionError} connectionError |
| + */ |
| +remoting.LogToServer.prototype.logClientSessionStateChange = |
| + function(state, connectionError) { |
| + var entry = remoting.ServerLogEntry.prototype.makeClientSessionStateChange( |
|
Jamie
2011/11/11 19:08:40
If this is effectively a static function, there's
|
| + state, connectionError); |
| + entry.addHostFields(); |
| + entry.addChromeVersionField(); |
| + entry.addWebappVersionField(); |
| + this.log(entry); |
| +}; |
| + |
| +/** |
| + * Sends a log entry to the server. |
| + * |
| + * @private |
| + * @param {remoting.ServerLogEntry} entry |
| + */ |
| +remoting.LogToServer.prototype.log = function(entry) { |
| + // Store a stanza for the entry |
| + this.pendingEntries.push(entry.toStanza()); |
| + // Stop if there's no connection to the server. |
| + if (!remoting.wcs) { |
| + return; |
| + } |
| + // Send all pending entries to the server. |
| + var stanza = '<cli:iq to="remoting@bot.talk.google.com" type="set" ' + |
| + 'xmlns:cli="jabber:client"><gr:log xmlns:gr="google:remoting">'; |
| + while (this.pendingEntries.length > 0) { |
| + stanza += /** @type string */ this.pendingEntries.shift(); |
| + } |
| + stanza += '</gr:log></cli:iq>'; |
| + remoting.debug.logIq(true, stanza); |
| + remoting.wcs.sendIq(stanza); |
| +}; |