Chromium Code Reviews| 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 /** |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 */ | 28 */ |
| 29 remoting.SignalStrategy.State = { | 29 remoting.SignalStrategy.State = { |
| 30 NOT_CONNECTED: 0, | 30 NOT_CONNECTED: 0, |
| 31 CONNECTING: 1, | 31 CONNECTING: 1, |
| 32 HANDSHAKE: 2, | 32 HANDSHAKE: 2, |
| 33 CONNECTED: 3, | 33 CONNECTED: 3, |
| 34 FAILED: 4, | 34 FAILED: 4, |
| 35 CLOSED: 5 | 35 CLOSED: 5 |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 /** | |
| 39 * @enum {string} SignalStrategy types. Do not add to these values without | |
| 40 * updating the corresponding enum in chromoting_extensions.proto. | |
| 41 */ | |
| 42 remoting.SignalStrategy.Type = { | |
| 43 XMPP: 'xmpp', | |
| 44 WCS: 'wcs' | |
| 45 }; | |
| 46 | |
| 38 remoting.SignalStrategy.prototype.dispose = function() {}; | 47 remoting.SignalStrategy.prototype.dispose = function() {}; |
| 39 | 48 |
| 40 /** | 49 /** |
| 41 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on | 50 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on |
| 42 * incoming messages. | 51 * incoming messages. |
| 43 */ | 52 */ |
| 44 remoting.SignalStrategy.prototype.setIncomingStanzaCallback = | 53 remoting.SignalStrategy.prototype.setIncomingStanzaCallback = |
| 45 function(onIncomingStanzaCallback) {}; | 54 function(onIncomingStanzaCallback) {}; |
| 46 | 55 |
| 47 /** | 56 /** |
| 48 * @param {string} server | 57 * @param {string} server |
| 49 * @param {string} username | 58 * @param {string} username |
| 50 * @param {string} authToken | 59 * @param {string} authToken |
| 51 */ | 60 */ |
| 52 remoting.SignalStrategy.prototype.connect = | 61 remoting.SignalStrategy.prototype.connect = |
| 53 function(server, username, authToken) { | 62 function(server, username, authToken) { |
| 54 }; | 63 }; |
| 55 | 64 |
| 56 /** | 65 /** |
| 57 * Sends a message. Can be called only in CONNECTED state. | 66 * Sends a message. Can be called only in CONNECTED state. |
| 58 * @param {string} message | 67 * @param {string} message |
| 59 */ | 68 */ |
| 60 remoting.SignalStrategy.prototype.sendMessage = function(message) {}; | 69 remoting.SignalStrategy.prototype.sendMessage = function(message) {}; |
| 61 | 70 |
| 71 /** | |
| 72 * Send any messages accumulated during connection set-up. | |
| 73 * | |
| 74 * @param {remoting.LogToServer} logToServer The LogToServer instance for the | |
| 75 * connection. | |
| 76 */ | |
| 77 remoting.SignalStrategy.prototype.sendConnectionSetupResults = | |
| 78 function(logToServer) { | |
| 79 }; | |
| 80 | |
| 62 /** @return {remoting.SignalStrategy.State} Current state */ | 81 /** @return {remoting.SignalStrategy.State} Current state */ |
| 63 remoting.SignalStrategy.prototype.getState = function() {}; | 82 remoting.SignalStrategy.prototype.getState = function() {}; |
| 64 | 83 |
| 65 /** @return {remoting.Error} Error when in FAILED state. */ | 84 /** @return {remoting.Error} Error when in FAILED state. */ |
| 66 remoting.SignalStrategy.prototype.getError = function() {}; | 85 remoting.SignalStrategy.prototype.getError = function() {}; |
| 67 | 86 |
| 68 /** @return {string} Current JID when in CONNECTED state. */ | 87 /** @return {string} Current JID when in CONNECTED state. */ |
| 69 remoting.SignalStrategy.prototype.getJid = function() {}; | 88 remoting.SignalStrategy.prototype.getJid = function() {}; |
| 70 | 89 |
| 90 /** @return {remoting.SignalStrategy.Type} The signal strategy type. */ | |
| 91 remoting.SignalStrategy.prototype.getType = function() {}; | |
|
Jamie
2015/01/21 19:41:08
I'm not crazy about this design, since it means th
| |
| 92 | |
| 71 /** | 93 /** |
| 72 * Creates the appropriate signal strategy for the current environment. | 94 * Creates the appropriate signal strategy for the current environment. |
| 73 * @param {function(remoting.SignalStrategy.State): void} onStateChangedCallback | 95 * @param {function(remoting.SignalStrategy.State): void} onStateChangedCallback |
| 74 * @return {remoting.SignalStrategy} New signal strategy object. | 96 * @return {remoting.SignalStrategy} New signal strategy object. |
| 75 */ | 97 */ |
| 76 remoting.SignalStrategy.create = function(onStateChangedCallback) { | 98 remoting.SignalStrategy.create = function(onStateChangedCallback) { |
| 77 // Only use XMPP when TCP API is available and TLS support is enabled. That's | 99 // 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) | 100 // not the case for V1 app (socket API is available only to platform apps) |
| 79 // and for Chrome releases before 38. | 101 // and for Chrome releases before 38. |
| 80 if (chrome.socket && chrome.socket.secure) { | 102 if (chrome.socket && chrome.socket.secure) { |
| 81 /** | 103 /** |
| 82 * @param {function(remoting.SignalStrategy.State): void} onStateChanged | 104 * @param {function(remoting.SignalStrategy.State): void} onStateChanged |
| 83 */ | 105 */ |
| 84 var xmppFactory = function(onStateChanged) { | 106 var xmppFactory = function(onStateChanged) { |
| 85 return new remoting.XmppConnection(onStateChanged); | 107 return new remoting.XmppConnection(onStateChanged); |
| 86 }; | 108 }; |
| 87 | 109 |
| 88 /** | 110 /** |
| 89 * @param {function(remoting.SignalStrategy.State): void} onStateChanged | 111 * @param {function(remoting.SignalStrategy.State): void} onStateChanged |
| 90 */ | 112 */ |
| 91 var wcsFactory = function(onStateChanged) { | 113 var wcsFactory = function(onStateChanged) { |
| 92 return new remoting.WcsAdapter(onStateChanged); | 114 return new remoting.WcsAdapter(onStateChanged); |
| 93 }; | 115 }; |
| 94 | 116 |
| 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( | 117 return new remoting.FallbackSignalStrategy( |
| 103 xmppFactory, wcsFactory, onStateChangedCallback, progressCallback); | 118 xmppFactory, wcsFactory, onStateChangedCallback); |
| 104 | 119 |
| 105 } else { | 120 } else { |
| 106 return new remoting.WcsAdapter(onStateChangedCallback); | 121 return new remoting.WcsAdapter(onStateChangedCallback); |
| 107 } | 122 } |
| 108 }; | 123 }; |
| OLD | NEW |