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 | 63 |
64 remoting.WcsAdapter.prototype.dispose = function() { | 64 remoting.WcsAdapter.prototype.dispose = function() { |
65 this.setState_(remoting.SignalStrategy.State.CLOSED); | 65 this.setState_(remoting.SignalStrategy.State.CLOSED); |
66 remoting.wcsSandbox.setOnIq(null); | 66 remoting.wcsSandbox.setOnIq(null); |
67 } | 67 }; |
68 | 68 |
69 /** @param {string} message */ | 69 /** @param {string} message */ |
70 remoting.WcsAdapter.prototype.sendMessage = function(message) { | 70 remoting.WcsAdapter.prototype.sendMessage = function(message) { |
71 // Extract the session id, so we can close the session later. | 71 // 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 | 72 // 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 | 73 // stanza IDs used by host and client do not match. This is necessary to |
74 // workaround bug in the signaling endpoint used by chromoting. | 74 // workaround bug in the signaling endpoint used by chromoting. |
75 // TODO(sergeyu): Remove this hack once the server-side bug is fixed. | 75 // TODO(sergeyu): Remove this hack once the server-side bug is fixed. |
76 var parser = new DOMParser(); | 76 var parser = new DOMParser(); |
77 var iqNode = parser.parseFromString(message, 'text/xml').firstChild; | 77 var iqNode = parser.parseFromString(message, 'text/xml').firstChild; |
78 var type = iqNode.getAttribute('type'); | 78 var type = iqNode.getAttribute('type'); |
79 if (type == 'set') { | 79 if (type == 'set') { |
80 var id = iqNode.getAttribute('id'); | 80 var id = iqNode.getAttribute('id'); |
81 iqNode.setAttribute('id', 'x' + id); | 81 iqNode.setAttribute('id', 'x' + id); |
82 message = (new XMLSerializer()).serializeToString(iqNode); | 82 message = (new XMLSerializer()).serializeToString(iqNode); |
83 } | 83 } |
84 | 84 |
85 // Send the stanza. | 85 // Send the stanza. |
86 remoting.wcsSandbox.sendIq(message); | 86 remoting.wcsSandbox.sendIq(message); |
87 } | 87 }; |
| 88 |
| 89 /** |
| 90 * @param {remoting.LogToServer} logToServer The LogToServer instance for the |
| 91 * connection. |
| 92 */ |
| 93 remoting.WcsAdapter.prototype.sendConnectionSetupResults = |
| 94 function(logToServer) { |
| 95 }; |
88 | 96 |
89 /** @param {string} jid */ | 97 /** @param {string} jid */ |
90 remoting.WcsAdapter.prototype.onWcsConnected_ = function(jid) { | 98 remoting.WcsAdapter.prototype.onWcsConnected_ = function(jid) { |
91 this.jid_ = jid; | 99 this.jid_ = jid; |
92 this.setState_(remoting.SignalStrategy.State.CONNECTED); | 100 this.setState_(remoting.SignalStrategy.State.CONNECTED); |
93 } | 101 }; |
94 | 102 |
95 /** @param {string} stanza */ | 103 /** @param {string} stanza */ |
96 remoting.WcsAdapter.prototype.onIncomingStanza_ = function(stanza) { | 104 remoting.WcsAdapter.prototype.onIncomingStanza_ = function(stanza) { |
97 var parser = new DOMParser(); | 105 var parser = new DOMParser(); |
98 var parsed = parser.parseFromString(stanza, 'text/xml').firstChild; | 106 var parsed = parser.parseFromString(stanza, 'text/xml').firstChild; |
99 | 107 |
100 // HACK: Remove 'x' prefix added to the id in sendMessage(). | 108 // HACK: Remove 'x' prefix added to the id in sendMessage(). |
101 try { | 109 try { |
102 var type = parsed.getAttribute('type'); | 110 var type = parsed.getAttribute('type'); |
103 var id = parsed.getAttribute('id'); | 111 var id = parsed.getAttribute('id'); |
104 if (type != 'set' && id.charAt(0) == 'x') { | 112 if (type != 'set' && id.charAt(0) == 'x') { |
105 parsed.setAttribute('id', id.substr(1)); | 113 parsed.setAttribute('id', id.substr(1)); |
106 } | 114 } |
107 } catch (err) { | 115 } catch (err) { |
108 // Pass message as is when it is malformed. | 116 // Pass message as is when it is malformed. |
109 } | 117 } |
110 | 118 |
111 if (this.onIncomingStanzaCallback_) { | 119 if (this.onIncomingStanzaCallback_) { |
112 this.onIncomingStanzaCallback_(parsed); | 120 this.onIncomingStanzaCallback_(parsed); |
113 } | 121 } |
114 } | 122 }; |
115 | 123 |
116 /** @param {remoting.Error} error */ | 124 /** @param {remoting.Error} error */ |
117 remoting.WcsAdapter.prototype.onError_ = function(error) { | 125 remoting.WcsAdapter.prototype.onError_ = function(error) { |
118 this.error_ = error; | 126 this.error_ = error; |
119 this.setState_(remoting.SignalStrategy.State.FAILED); | 127 this.setState_(remoting.SignalStrategy.State.FAILED); |
120 } | 128 }; |
121 | 129 |
122 /** | 130 /** |
123 * @param {remoting.SignalStrategy.State} newState | 131 * @param {remoting.SignalStrategy.State} newState |
124 * @private | 132 * @private |
125 */ | 133 */ |
126 remoting.WcsAdapter.prototype.setState_ = function(newState) { | 134 remoting.WcsAdapter.prototype.setState_ = function(newState) { |
127 if (this.state_ != newState) { | 135 if (this.state_ != newState) { |
128 this.state_ = newState; | 136 this.state_ = newState; |
129 this.onStateChangedCallback_(this.state_); | 137 this.onStateChangedCallback_(this.state_); |
130 } | 138 } |
131 }; | 139 }; |
OLD | NEW |