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 * * -> CLOSED (dispose() called).
27 * Do not re-order these values without updating fallback_signal_strategy.js.
29 remoting.SignalStrategy.State = {
38 remoting.SignalStrategy.prototype.dispose = function() {};
41 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on
44 remoting.SignalStrategy.prototype.setIncomingStanzaCallback =
45 function(onIncomingStanzaCallback) {};
48 * @param {string} server
49 * @param {string} username
50 * @param {string} authToken
52 remoting.SignalStrategy.prototype.connect =
53 function(server, username, authToken) {
57 * Sends a message. Can be called only in CONNECTED state.
58 * @param {string} message
60 remoting.SignalStrategy.prototype.sendMessage = function(message) {};
62 /** @return {remoting.SignalStrategy.State} Current state */
63 remoting.SignalStrategy.prototype.getState = function() {};
65 /** @return {remoting.Error} Error when in FAILED state. */
66 remoting.SignalStrategy.prototype.getError = function() {};
68 /** @return {string} Current JID when in CONNECTED state. */
69 remoting.SignalStrategy.prototype.getJid = function() {};
72 * Creates the appropriate signal strategy for the current environment.
73 * @param {function(remoting.SignalStrategy.State): void} onStateChangedCallback
74 * @return {remoting.SignalStrategy} New signal strategy object.
76 remoting.SignalStrategy.create = function(onStateChangedCallback) {
77 // Only use XMPP when TCP API is available and TLS support is enabled. That's
78 // not the case for V1 app (socket API is available only to platform apps)
79 // and for Chrome releases before 38.
80 if (chrome.socket && chrome.socket.secure) {
82 * @param {function(remoting.SignalStrategy.State): void} onStateChanged
84 var xmppFactory = function(onStateChanged) {
85 return new remoting.XmppConnection(onStateChanged);
89 * @param {function(remoting.SignalStrategy.State): void} onStateChanged
91 var wcsFactory = function(onStateChanged) {
92 return new remoting.WcsAdapter(onStateChanged);
96 * @param {remoting.FallbackSignalStrategy.Progress} progress
98 var progressCallback = function(progress) {
99 console.log('FallbackSignalStrategy progress: ' + progress);
102 return new remoting.FallbackSignalStrategy(
103 xmppFactory, wcsFactory, onStateChangedCallback, progressCallback);
106 return new remoting.WcsAdapter(onStateChangedCallback);