OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** | 10 /** |
11 * Abstract interface for various signaling mechanisms. | 11 * Abstract interface for various signaling mechanisms. |
12 * | 12 * |
13 * @interface | 13 * @interface |
14 * @extends {base.Disposable} | 14 * @extends {base.Disposable} |
15 */ | 15 */ |
16 remoting.SignalStrategy = function() {}; | 16 remoting.SignalStrategy = function() {}; |
17 | 17 |
18 /** | 18 /** |
19 * @enum {number} SignalStrategy states. Possible state transitions: | 19 * @enum {number} SignalStrategy states. Possible state transitions: |
20 * NOT_CONNECTED -> CONNECTING (connect() called). | 20 * NOT_CONNECTED -> CONNECTING (connect() called). |
21 * CONNECTING -> HANDSHAKE (connected successfully). | 21 * CONNECTING -> HANDSHAKE (connected successfully). |
22 * HANDSHAKE -> CONNECTED (authenticated successfully). | 22 * HANDSHAKE -> CONNECTED (authenticated successfully). |
23 * CONNECTING -> FAILED (connection failed). | 23 * CONNECTING -> FAILED (connection failed). |
24 * HANDSHAKE -> FAILED (authentication failed). | 24 * HANDSHAKE -> FAILED (authentication failed). |
25 * * -> CLOSED (dispose() called). | 25 * * -> CLOSED (dispose() called). |
| 26 * |
| 27 * Do not re-order these values without updating fallback_signal_strategy.js. |
26 */ | 28 */ |
27 remoting.SignalStrategy.State = { | 29 remoting.SignalStrategy.State = { |
28 NOT_CONNECTED: 0, | 30 NOT_CONNECTED: 0, |
29 CONNECTING: 1, | 31 CONNECTING: 1, |
30 HANDSHAKE: 2, | 32 HANDSHAKE: 2, |
31 CONNECTED: 3, | 33 CONNECTED: 3, |
32 FAILED: 4, | 34 FAILED: 4, |
33 CLOSED: 5 | 35 CLOSED: 5 |
34 }; | 36 }; |
35 | 37 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 /** | 71 /** |
70 * Creates the appropriate signal strategy for the current environment. | 72 * Creates the appropriate signal strategy for the current environment. |
71 * @param {function(remoting.SignalStrategy.State): void} onStateChangedCallback | 73 * @param {function(remoting.SignalStrategy.State): void} onStateChangedCallback |
72 * @return {remoting.SignalStrategy} New signal strategy object. | 74 * @return {remoting.SignalStrategy} New signal strategy object. |
73 */ | 75 */ |
74 remoting.SignalStrategy.create = function(onStateChangedCallback) { | 76 remoting.SignalStrategy.create = function(onStateChangedCallback) { |
75 // Only use XMPP when TCP API is available and TLS support is enabled. That's | 77 // Only use XMPP when TCP API is available and TLS support is enabled. That's |
76 // not the case for V1 app (socket API is available only to platform apps) | 78 // not the case for V1 app (socket API is available only to platform apps) |
77 // and for Chrome releases before 38. | 79 // and for Chrome releases before 38. |
78 if (chrome.socket && chrome.socket.secure) { | 80 if (chrome.socket && chrome.socket.secure) { |
79 return new remoting.XmppConnection(onStateChangedCallback); | 81 /** |
| 82 * @param {function(remoting.SignalStrategy.State): void} onStateChanged |
| 83 */ |
| 84 var xmppFactory = function(onStateChanged) { |
| 85 return new remoting.XmppConnection(onStateChanged); |
| 86 }; |
| 87 |
| 88 /** |
| 89 * @param {function(remoting.SignalStrategy.State): void} onStateChanged |
| 90 */ |
| 91 var wcsFactory = function(onStateChanged) { |
| 92 return new remoting.WcsAdapter(onStateChanged); |
| 93 }; |
| 94 |
| 95 /** |
| 96 * @param {remoting.FallbackSignalStrategy.Progress} progress |
| 97 */ |
| 98 var progressCallback = function(progress) { |
| 99 console.log('FallbackSignalStrategy progress: ' + progress); |
| 100 }; |
| 101 |
| 102 return new remoting.FallbackSignalStrategy( |
| 103 xmppFactory, wcsFactory, onStateChangedCallback, progressCallback); |
| 104 |
80 } else { | 105 } else { |
81 return new remoting.WcsAdapter(onStateChangedCallback); | 106 return new remoting.WcsAdapter(onStateChangedCallback); |
82 } | 107 } |
83 }; | 108 }; |
OLD | NEW |