1 /* Copyright (c) 2012 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.
8 * A class that provides an interface to a WCS connection.
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
16 /** @type {remoting.Wcs} */
21 * @param {remoting.WcsIqClient} wcsIqClient The WCS client.
22 * @param {string} token An OAuth2 access token.
23 * @param {function(string): void} onReady Called with the WCS client's JID.
25 remoting
.Wcs = function(wcsIqClient
, token
, onReady
) {
28 * @private {remoting.WcsIqClient}
30 this.wcsIqClient_
= wcsIqClient
;
33 * The OAuth2 access token.
39 * The function called when the WCS client has received a full JID.
40 * @private {?function(string): void}
42 this.onReady_
= onReady
;
45 * The full JID of the WCS client.
48 this.clientFullJid_
= '';
51 * A function called when an IQ stanza is received.
52 * @param {string} stanza The IQ stanza.
55 this.onIq_ = function(stanza
) {};
57 // Handle messages from the WcsIqClient.
58 this.wcsIqClient_
.setOnMessage(this.onMessage_
.bind(this));
60 // Start the WcsIqClient.
61 this.wcsIqClient_
.connectChannel();
65 * Passes an access token to the WcsIqClient, if the token has been updated.
67 * @param {string} tokenNew A (possibly updated) access token.
68 * @return {void} Nothing.
70 remoting
.Wcs
.prototype.updateAccessToken = function(tokenNew
) {
71 if (tokenNew
!= this.token_
) {
72 this.token_
= tokenNew
;
73 this.wcsIqClient_
.updateAccessToken(this.token_
);
78 * Handles a message coming from the WcsIqClient.
80 * @param {Array<string>} msg The message.
81 * @return {void} Nothing.
84 remoting
.Wcs
.prototype.onMessage_ = function(msg
) {
87 } else if (msg
[0] == 'cfj') {
88 this.clientFullJid_
= msg
[1];
89 console
.log('Received JID: ' + this.clientFullJid_
);
91 this.onReady_(this.clientFullJid_
);
98 * Gets the full JID of the WCS client.
100 * @return {string} The full JID.
102 remoting
.Wcs
.prototype.getJid = function() {
103 return this.clientFullJid_
;
107 * Sends an IQ stanza.
109 * @param {string} stanza An IQ stanza.
110 * @return {void} Nothing.
112 remoting
.Wcs
.prototype.sendIq = function(stanza
) {
113 this.wcsIqClient_
.sendIq(stanza
);
117 * Sets the function called when an IQ stanza is received.
119 * @param {function(string): void} onIq The function called when an IQ stanza
121 * @return {void} Nothing.
123 remoting
.Wcs
.prototype.setOnIq = function(onIq
) {