1 // Copyright 2015 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 // MM ,M9 .gP"Ya ,6"Yb. ,M""bMM `7MMpMMMb.pMMMb. .gP"Ya
8 // MMmmdM9 ,M' Yb 8) MM ,AP MM MM MM MM ,M' Yb
9 // MM YM. 8M"""""" ,pm9MM 8MI MM MM MM MM 8M""""""
10 // MM `Mb.YM. , 8M MM `Mb MM MM MM MM YM. ,
11 // .JMML. .JMM.`Mbmmd' `Moo9^Yo.`Wbmd"MML..JMML JMML JMML.`Mbmmd'
13 // This file defines a JavaScript struct that corresponds to
14 // logs/proto/chromoting/chromoting_extensions.proto
16 // Please keep the two files in sync!
19 /** @suppress {duplicate} */
20 var remoting
= remoting
|| {};
27 * The members in this struct is used as the JSON payload in outgoing XHRs
28 * so they must match the member definitions in chromoting_extensions.proto.
30 * @param {remoting.ChromotingEvent.Type} type
35 remoting
.ChromotingEvent = function(type
) {
36 /** @type {remoting.ChromotingEvent.Type} */
38 /** @private {remoting.ChromotingEvent.Os} */
40 /** @private {string} */
42 /** @private {string} */
44 /** @private {string} */
48 /** @private {string} */
50 /** @type {remoting.ChromotingEvent.SessionState} */
52 /** @private {remoting.ChromotingEvent.ConnectionType} */
54 /** @private {string} */
58 /** @type {remoting.ChromotingEvent.Role} */
60 /** @type {remoting.ChromotingEvent.ConnectionError} */
61 this.connection_error
;
63 this.session_duration
;
75 this.roundtrip_latency
;
76 /** @type {remoting.ChromotingEvent.Mode} */
78 /** @type {remoting.ChromotingEvent.SignalStrategyType} */
79 this.signal_strategy_type
;
80 /** @type {remoting.ChromotingEvent.SignalStrategyProgress} */
81 this.signal_strategy_progress
;
87 remoting
.ChromotingEvent
.prototype.init_ = function() {
89 var systemInfo
= remoting
.getSystemInfo();
90 this.cpu
= systemInfo
.cpu
;
91 this.os_version
= systemInfo
.osVersion
;
92 if (systemInfo
.osName
=== remoting
.Os
.WINDOWS
) {
93 this.os
= remoting
.ChromotingEvent
.Os
.WINDOWS
;
94 } else if (systemInfo
.osName
=== remoting
.Os
.LINUX
) {
95 this.os
= remoting
.ChromotingEvent
.Os
.LINUX
;
96 } else if (systemInfo
.osName
=== remoting
.Os
.MAC
) {
97 this.os
= remoting
.ChromotingEvent
.Os
.MAC
;
98 } else if (systemInfo
.osName
=== remoting
.Os
.CHROMEOS
) {
99 this.os
= remoting
.ChromotingEvent
.Os
.CHROMEOS
;
101 this.browser_version
= systemInfo
.chromeVersion
;
104 this.webapp_version
= chrome
.runtime
.getManifest().version
;
105 this.application_id
= chrome
.runtime
.id
;
109 * @param {remoting.ClientSession.State} state
110 * @param {remoting.Error} error
112 remoting
.ChromotingEvent
.prototype.setSessionState = function(state
, error
) {
113 this.connection_error
= toConnectionError(error
);
114 this.session_state
= toSessionState(state
);
118 * @param {remoting.SignalStrategy.Type} type
119 * @param {remoting.FallbackSignalStrategy.Progress} progress
121 remoting
.ChromotingEvent
.prototype.setSignalStategyProgress
=
122 function(type
, progress
) {
123 this.signal_strategy_progress
= toSignalStrategyProgress(progress
);
124 this.signal_strategy_type
= toSignalStrategyType(type
);
128 * @param {string} type
130 remoting
.ChromotingEvent
.prototype.setConnectionType = function(type
) {
131 this.connection_type
= toConnectionType(type
);
135 * @param {remoting.ChromotingEvent} event
138 remoting
.ChromotingEvent
.isEndOfSession = function(event
) {
139 if (event
.type
!== remoting
.ChromotingEvent
.Type
.SESSION_STATE
) {
143 remoting
.ChromotingEvent
.SessionState
.CLOSED
,
144 remoting
.ChromotingEvent
.SessionState
.CONNECTION_DROPPED
,
145 remoting
.ChromotingEvent
.SessionState
.CONNECTION_FAILED
,
146 remoting
.ChromotingEvent
.SessionState
.CONNECTION_CANCELED
148 return endStates
.indexOf(event
.session_state
) !== -1;
152 * TODO(kelvinp): Consolidate the two enums (crbug.com/504200)
153 * @param {remoting.ClientSession.State} state
154 * @return {remoting.ChromotingEvent.SessionState}
156 function toSessionState(state
) {
157 var SessionState
= remoting
.ChromotingEvent
.SessionState
;
159 case remoting
.ClientSession
.State
.UNKNOWN
:
160 return SessionState
.UNKNOWN
;
161 case remoting
.ClientSession
.State
.INITIALIZING
:
162 return SessionState
.INITIALIZING
;
163 case remoting
.ClientSession
.State
.CONNECTING
:
164 return SessionState
.CONNECTING
;
165 case remoting
.ClientSession
.State
.AUTHENTICATED
:
166 return SessionState
.AUTHENTICATED
;
167 case remoting
.ClientSession
.State
.CONNECTED
:
168 return SessionState
.CONNECTED
;
169 case remoting
.ClientSession
.State
.CLOSED
:
170 return SessionState
.CLOSED
;
171 case remoting
.ClientSession
.State
.FAILED
:
172 return SessionState
.CONNECTION_FAILED
;
173 case remoting
.ClientSession
.State
.CONNECTION_DROPPED
:
174 return SessionState
.CONNECTION_DROPPED
;
175 case remoting
.ClientSession
.State
.CONNECTION_CANCELED
:
176 return SessionState
.CONNECTION_CANCELED
;
178 throw new Error('Unknown session state : ' + state
);
183 * @param {remoting.Error} error
184 * @return {remoting.ChromotingEvent.ConnectionError}
186 function toConnectionError(error
) {
187 var ConnectionError
= remoting
.ChromotingEvent
.ConnectionError
;
188 switch (error
.getTag()) {
189 case remoting
.Error
.Tag
.NONE
:
190 return ConnectionError
.NONE
;
191 case remoting
.Error
.Tag
.INVALID_ACCESS_CODE
:
192 return ConnectionError
.INVALID_ACCESS_CODE
;
193 case remoting
.Error
.Tag
.MISSING_PLUGIN
:
194 return ConnectionError
.MISSING_PLUGIN
;
195 case remoting
.Error
.Tag
.AUTHENTICATION_FAILED
:
196 return ConnectionError
.AUTHENTICATION_FAILED
;
197 case remoting
.Error
.Tag
.HOST_IS_OFFLINE
:
198 return ConnectionError
.HOST_OFFLINE
;
199 case remoting
.Error
.Tag
.INCOMPATIBLE_PROTOCOL
:
200 return ConnectionError
.INCOMPATIBLE_PROTOCOL
;
201 case remoting
.Error
.Tag
.BAD_PLUGIN_VERSION
:
202 return ConnectionError
.ERROR_BAD_PLUGIN_VERSION
;
203 case remoting
.Error
.Tag
.NETWORK_FAILURE
:
204 return ConnectionError
.NETWORK_FAILURE
;
205 case remoting
.Error
.Tag
.HOST_OVERLOAD
:
206 return ConnectionError
.HOST_OVERLOAD
;
207 case remoting
.Error
.Tag
.P2P_FAILURE
:
208 return ConnectionError
.P2P_FAILURE
;
209 case remoting
.Error
.Tag
.CLIENT_SUSPENDED
:
210 return ConnectionError
.CLIENT_SUSPENDED
;
211 case remoting
.Error
.Tag
.UNEXPECTED
:
212 return ConnectionError
.UNEXPECTED
;
214 throw new Error('Unknown error Tag : ' + error
.getTag());
219 * @param {remoting.SignalStrategy.Type} type
220 * @return {remoting.ChromotingEvent.SignalStrategyType}
222 function toSignalStrategyType(type
) {
224 case remoting
.SignalStrategy
.Type
.XMPP
:
225 return remoting
.ChromotingEvent
.SignalStrategyType
.XMPP
;
226 case remoting
.SignalStrategy
.Type
.WCS
:
227 return remoting
.ChromotingEvent
.SignalStrategyType
.WCS
;
229 throw new Error('Unknown signal strategy type : ' + type
);
234 * @param {remoting.FallbackSignalStrategy.Progress} progress
235 * @return {remoting.ChromotingEvent.SignalStrategyProgress}
237 function toSignalStrategyProgress(progress
) {
238 var Progress
= remoting
.FallbackSignalStrategy
.Progress
;
240 case Progress
.SUCCEEDED
:
241 return remoting
.ChromotingEvent
.SignalStrategyProgress
.SUCCEEDED
;
242 case Progress
.FAILED
:
243 return remoting
.ChromotingEvent
.SignalStrategyProgress
.FAILED
;
244 case Progress
.TIMED_OUT
:
245 return remoting
.ChromotingEvent
.SignalStrategyProgress
.TIMED_OUT
;
246 case Progress
.SUCCEEDED_LATE
:
247 return remoting
.ChromotingEvent
.SignalStrategyProgress
.SUCCEEDED_LATE
;
248 case Progress
.FAILED_LATE
:
249 return remoting
.ChromotingEvent
.SignalStrategyProgress
.FAILED_LATE
;
251 throw new Error('Unknown signal strategy progress :=' + progress
);
256 * @param {string} type
257 * @return {remoting.ChromotingEvent.ConnectionType}
259 function toConnectionType(type
) {
262 return remoting
.ChromotingEvent
.ConnectionType
.DIRECT
;
264 return remoting
.ChromotingEvent
.ConnectionType
.STUN
;
266 return remoting
.ChromotingEvent
.ConnectionType
.RELAY
;
268 throw new Error('Unknown ConnectionType :=' + type
);
277 remoting
.ChromotingEvent
.Type
= {
279 CONNECTION_STATISTICS
: 2,
283 HEARTBEAT_REJECTED
: 6,
286 SIGNAL_STRATEGY_PROGRESS
: 9
289 /** @enum {number} */
290 remoting
.ChromotingEvent
.Role
= {
295 /** @enum {number} */
296 remoting
.ChromotingEvent
.Os
= {
306 /** @enum {number} */
307 remoting
.ChromotingEvent
.SessionState
= {
310 BAD_PLUGIN_VERSION
: 3,
311 UNKNOWN_PLUGIN_ERROR
: 4,
316 CONNECTION_FAILED
: 9,
319 CONNECTION_DROPPED
: 12,
320 CONNECTION_CANCELED
: 13,
324 /** @enum {number} */
325 remoting
.ChromotingEvent
.ConnectionType
= {
331 /** @enum {number} */
332 remoting
.ChromotingEvent
.ConnectionError
= {
336 INCOMPATIBLE_PROTOCOL
: 4,
339 INVALID_ACCESS_CODE
: 7,
341 AUTHENTICATION_FAILED
: 9,
342 ERROR_BAD_PLUGIN_VERSION
: 10,
349 /** @enum {number} */
350 remoting
.ChromotingEvent
.Mode
= {
356 /** @enum {number} */
357 remoting
.ChromotingEvent
.SignalStrategyType
= {
362 /** @enum {number} */
363 remoting
.ChromotingEvent
.SignalStrategyProgress
= {