| 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 10 matching lines...) Expand all Loading... |
| 21 /** @private */ | 21 /** @private */ |
| 22 this.onStateChangedCallback_ = onStateChangedCallback; | 22 this.onStateChangedCallback_ = onStateChangedCallback; |
| 23 /** @type {?function(Element):void} @private */ | 23 /** @type {?function(Element):void} @private */ |
| 24 this.onIncomingStanzaCallback_ = null; | 24 this.onIncomingStanzaCallback_ = null; |
| 25 /** @private */ | 25 /** @private */ |
| 26 this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED; | 26 this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED; |
| 27 /** @private */ | 27 /** @private */ |
| 28 this.jid_ = ''; | 28 this.jid_ = ''; |
| 29 /** @private */ | 29 /** @private */ |
| 30 this.error_ = remoting.Error.NONE; | 30 this.error_ = remoting.Error.NONE; |
| 31 } | 31 }; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on | 34 * @param {?function(Element):void} onIncomingStanzaCallback Callback to call on |
| 35 * incoming messages. | 35 * incoming messages. |
| 36 */ | 36 */ |
| 37 remoting.WcsAdapter.prototype.setIncomingStanzaCallback = | 37 remoting.WcsAdapter.prototype.setIncomingStanzaCallback = |
| 38 function(onIncomingStanzaCallback) { | 38 function(onIncomingStanzaCallback) { |
| 39 this.onIncomingStanzaCallback_ = onIncomingStanzaCallback; | 39 this.onIncomingStanzaCallback_ = onIncomingStanzaCallback; |
| 40 } | 40 }; |
| 41 | 41 |
| 42 remoting.WcsAdapter.prototype.connect = function(server, authToken) { | 42 remoting.WcsAdapter.prototype.connect = function(server, authToken) { |
| 43 remoting.wcsSandbox.setOnIq(this.onIncomingStanza_.bind(this)); | 43 remoting.wcsSandbox.setOnIq(this.onIncomingStanza_.bind(this)); |
| 44 | 44 |
| 45 remoting.wcsSandbox.connect(this.onWcsConnected_.bind(this), | 45 remoting.wcsSandbox.connect(this.onWcsConnected_.bind(this), |
| 46 this.onError_.bind(this)); | 46 this.onError_.bind(this)); |
| 47 } | 47 }; |
| 48 | 48 |
| 49 /** @return {remoting.SignalStrategy.State} Current state */ | 49 /** @return {remoting.SignalStrategy.State} Current state */ |
| 50 remoting.WcsAdapter.prototype.getState = function() { | 50 remoting.WcsAdapter.prototype.getState = function() { |
| 51 return this.state_; | 51 return this.state_; |
| 52 } | 52 }; |
| 53 | 53 |
| 54 /** @return {remoting.Error} Error when in FAILED state. */ | 54 /** @return {remoting.Error} Error when in FAILED state. */ |
| 55 remoting.WcsAdapter.prototype.getError = function() { | 55 remoting.WcsAdapter.prototype.getError = function() { |
| 56 return this.error_; | 56 return this.error_; |
| 57 } | 57 }; |
| 58 | 58 |
| 59 /** @return {string} Current JID when in CONNECTED state. */ | 59 /** @return {string} Current JID when in CONNECTED state. */ |
| 60 remoting.WcsAdapter.prototype.getJid = function() { | 60 remoting.WcsAdapter.prototype.getJid = function() { |
| 61 return this.jid_; | 61 return this.jid_; |
| 62 } | 62 }; |
| 63 |
| 64 /** @return {remoting.SignalStrategy.Type} The signal strategy type. */ |
| 65 remoting.WcsAdapter.prototype.getType = function() { |
| 66 return remoting.SignalStrategy.Type.WCS; |
| 67 }; |
| 63 | 68 |
| 64 remoting.WcsAdapter.prototype.dispose = function() { | 69 remoting.WcsAdapter.prototype.dispose = function() { |
| 65 this.setState_(remoting.SignalStrategy.State.CLOSED); | 70 this.setState_(remoting.SignalStrategy.State.CLOSED); |
| 66 remoting.wcsSandbox.setOnIq(null); | 71 remoting.wcsSandbox.setOnIq(null); |
| 67 } | 72 }; |
| 68 | 73 |
| 69 /** @param {string} message */ | 74 /** @param {string} message */ |
| 70 remoting.WcsAdapter.prototype.sendMessage = function(message) { | 75 remoting.WcsAdapter.prototype.sendMessage = function(message) { |
| 71 // Extract the session id, so we can close the session later. | 76 // Extract the session id, so we can close the session later. |
| 72 // HACK: Add 'x' prefix to the IDs of the outgoing messages to make sure that | 77 // HACK: Add 'x' prefix to the IDs of the outgoing messages to make sure that |
| 73 // stanza IDs used by host and client do not match. This is necessary to | 78 // stanza IDs used by host and client do not match. This is necessary to |
| 74 // workaround bug in the signaling endpoint used by chromoting. | 79 // workaround bug in the signaling endpoint used by chromoting. |
| 75 // TODO(sergeyu): Remove this hack once the server-side bug is fixed. | 80 // TODO(sergeyu): Remove this hack once the server-side bug is fixed. |
| 76 var parser = new DOMParser(); | 81 var parser = new DOMParser(); |
| 77 var iqNode = parser.parseFromString(message, 'text/xml').firstChild; | 82 var iqNode = parser.parseFromString(message, 'text/xml').firstChild; |
| 78 var type = iqNode.getAttribute('type'); | 83 var type = iqNode.getAttribute('type'); |
| 79 if (type == 'set') { | 84 if (type == 'set') { |
| 80 var id = iqNode.getAttribute('id'); | 85 var id = iqNode.getAttribute('id'); |
| 81 iqNode.setAttribute('id', 'x' + id); | 86 iqNode.setAttribute('id', 'x' + id); |
| 82 message = (new XMLSerializer()).serializeToString(iqNode); | 87 message = (new XMLSerializer()).serializeToString(iqNode); |
| 83 } | 88 } |
| 84 | 89 |
| 85 // Send the stanza. | 90 // Send the stanza. |
| 86 remoting.wcsSandbox.sendIq(message); | 91 remoting.wcsSandbox.sendIq(message); |
| 87 } | 92 }; |
| 93 |
| 94 /** |
| 95 * @param {remoting.LogToServer} logToServer The LogToServer instance for the |
| 96 * connection. |
| 97 */ |
| 98 remoting.WcsAdapter.prototype.sendConnectionSetupResults = |
| 99 function(logToServer) { |
| 100 }; |
| 88 | 101 |
| 89 /** @param {string} jid */ | 102 /** @param {string} jid */ |
| 90 remoting.WcsAdapter.prototype.onWcsConnected_ = function(jid) { | 103 remoting.WcsAdapter.prototype.onWcsConnected_ = function(jid) { |
| 91 this.jid_ = jid; | 104 this.jid_ = jid; |
| 92 this.setState_(remoting.SignalStrategy.State.CONNECTED); | 105 this.setState_(remoting.SignalStrategy.State.CONNECTED); |
| 93 } | 106 }; |
| 94 | 107 |
| 95 /** @param {string} stanza */ | 108 /** @param {string} stanza */ |
| 96 remoting.WcsAdapter.prototype.onIncomingStanza_ = function(stanza) { | 109 remoting.WcsAdapter.prototype.onIncomingStanza_ = function(stanza) { |
| 97 var parser = new DOMParser(); | 110 var parser = new DOMParser(); |
| 98 var parsed = parser.parseFromString(stanza, 'text/xml').firstChild; | 111 var parsed = parser.parseFromString(stanza, 'text/xml').firstChild; |
| 99 | 112 |
| 100 // HACK: Remove 'x' prefix added to the id in sendMessage(). | 113 // HACK: Remove 'x' prefix added to the id in sendMessage(). |
| 101 try { | 114 try { |
| 102 var type = parsed.getAttribute('type'); | 115 var type = parsed.getAttribute('type'); |
| 103 var id = parsed.getAttribute('id'); | 116 var id = parsed.getAttribute('id'); |
| 104 if (type != 'set' && id.charAt(0) == 'x') { | 117 if (type != 'set' && id.charAt(0) == 'x') { |
| 105 parsed.setAttribute('id', id.substr(1)); | 118 parsed.setAttribute('id', id.substr(1)); |
| 106 } | 119 } |
| 107 } catch (err) { | 120 } catch (err) { |
| 108 // Pass message as is when it is malformed. | 121 // Pass message as is when it is malformed. |
| 109 } | 122 } |
| 110 | 123 |
| 111 if (this.onIncomingStanzaCallback_) { | 124 if (this.onIncomingStanzaCallback_) { |
| 112 this.onIncomingStanzaCallback_(parsed); | 125 this.onIncomingStanzaCallback_(parsed); |
| 113 } | 126 } |
| 114 } | 127 }; |
| 115 | 128 |
| 116 /** @param {remoting.Error} error */ | 129 /** @param {remoting.Error} error */ |
| 117 remoting.WcsAdapter.prototype.onError_ = function(error) { | 130 remoting.WcsAdapter.prototype.onError_ = function(error) { |
| 118 this.error_ = error; | 131 this.error_ = error; |
| 119 this.setState_(remoting.SignalStrategy.State.FAILED); | 132 this.setState_(remoting.SignalStrategy.State.FAILED); |
| 120 } | 133 }; |
| 121 | 134 |
| 122 /** | 135 /** |
| 123 * @param {remoting.SignalStrategy.State} newState | 136 * @param {remoting.SignalStrategy.State} newState |
| 124 * @private | 137 * @private |
| 125 */ | 138 */ |
| 126 remoting.WcsAdapter.prototype.setState_ = function(newState) { | 139 remoting.WcsAdapter.prototype.setState_ = function(newState) { |
| 127 if (this.state_ != newState) { | 140 if (this.state_ != newState) { |
| 128 this.state_ = newState; | 141 this.state_ = newState; |
| 129 this.onStateChangedCallback_(this.state_); | 142 this.onStateChangedCallback_(this.state_); |
| 130 } | 143 } |
| 131 }; | 144 }; |
| OLD | NEW |