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) {};
79 /** @return {remoting.SignalStrategy.State} Current state */
80 remoting.SignalStrategy.prototype.getState = function() {};
82 /** @return {!remoting.Error} Error when in FAILED state. */
83 remoting.SignalStrategy.prototype.getError = function() {};
85 /** @return {string} Current JID when in CONNECTED state. */
86 remoting.SignalStrategy.prototype.getJid = function() {};
88 /** @return {remoting.SignalStrategy.Type} The signal strategy type. */
89 remoting.SignalStrategy.prototype.getType = function() {};
92 * Creates the appropriate signal strategy for the current environment.
93 * @return {remoting.SignalStrategy} New signal strategy object.
95 remoting.SignalStrategy.create = function() {
96 // Only use XMPP when TCP API is available and TLS support is enabled. That's
97 // not the case for V1 app (socket API is available only to platform apps)
98 // and for Chrome releases before 38.
99 if (chrome.sockets && chrome.sockets.tcp && chrome.sockets.tcp.secure) {
101 * @param {remoting.FallbackSignalStrategy.Progress} progress
103 var progressCallback = function(progress) {
104 console.log('FallbackSignalStrategy progress: ' + progress);
107 return new remoting.FallbackSignalStrategy(
108 new remoting.DnsBlackholeChecker(new remoting.XmppConnection()),
109 new remoting.WcsAdapter());
111 return new remoting.WcsAdapter();