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 * Abstract interface for various signaling mechanisms.
14 * @extends {base.Disposable}
16 remoting.SignalStrategy = function() {};
19 * @enum {number} SignalStrategy states. Possible state transitions:
20 * NOT_CONNECTED -> CONNECTING (connect() called).
21 * CONNECTING -> HANDSHAKE (connected successfully).
22 * HANDSHAKE -> CONNECTED (authenticated successfully).
23 * CONNECTING -> FAILED (connection failed).
24 * HANDSHAKE -> FAILED (authentication failed).
25 * CONNECTED -> FAILED (connection was terminated).
26 * * -> CLOSED (dispose() called).
28 * Do not re-order these values without updating fallback_signal_strategy.js.
30 remoting.SignalStrategy.State = {
40 * @enum {string} SignalStrategy types. Do not add to these values without
41 * updating the corresponding enum in chromoting_extensions.proto.
43 remoting.SignalStrategy.Type = {
48 remoting.SignalStrategy.prototype.dispose = function() {};
51 * @param {function(remoting.SignalStrategy.State):void} onStateChangedCallback
52 * Callback to call on state change.
54 remoting.SignalStrategy.prototype.setStateChangedCallback =
55 function(onStateChangedCallback) {};
58 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
61 remoting.SignalStrategy.prototype.setIncomingStanzaCallback =
62 function(onIncomingStanzaCallback) {};
65 * @param {string} server
66 * @param {string} username
67 * @param {string} authToken
69 remoting.SignalStrategy.prototype.connect =
70 function(server, username, authToken) {
74 * Sends a message. Can be called only in CONNECTED state.
75 * @param {string} message
77 remoting.SignalStrategy.prototype.sendMessage = function(message) {};
80 * Send any messages accumulated during connection set-up.
82 * @param {remoting.Logger} logger The logger instance for the
85 remoting.SignalStrategy.prototype.sendConnectionSetupResults =
89 /** @return {remoting.SignalStrategy.State} Current state */
90 remoting.SignalStrategy.prototype.getState = function() {};
92 /** @return {!remoting.Error} Error when in FAILED state. */
93 remoting.SignalStrategy.prototype.getError = function() {};
95 /** @return {string} Current JID when in CONNECTED state. */
96 remoting.SignalStrategy.prototype.getJid = function() {};
98 /** @return {remoting.SignalStrategy.Type} The signal strategy type. */
99 remoting.SignalStrategy.prototype.getType = function() {};
102 * Creates the appropriate signal strategy for the current environment.
103 * @return {remoting.SignalStrategy} New signal strategy object.
105 remoting.SignalStrategy.create = function() {
106 // Only use XMPP when TCP API is available and TLS support is enabled. That's
107 // not the case for V1 app (socket API is available only to platform apps)
108 // and for Chrome releases before 38.
109 if (chrome.sockets && chrome.sockets.tcp && chrome.sockets.tcp.secure) {
111 * @param {remoting.FallbackSignalStrategy.Progress} progress
113 var progressCallback = function(progress) {
114 console.log('FallbackSignalStrategy progress: ' + progress);
117 return new remoting.FallbackSignalStrategy(
118 new remoting.DnsBlackholeChecker(new remoting.XmppConnection()),
119 new remoting.WcsAdapter());
121 return new remoting.WcsAdapter();