Convert cacheinvalidation_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / remoting / webapp / base / js / chromoting_event.js
blob7dae88f2aa323cef993663b829b12380ec3c7f2f
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.
5 // `7MM"""Mq. `7MM
6 // MM `MM. MM
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 || {};
22 (function() {
24 'use strict';
26 /**
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
32 * @constructor
33 * @struct
35 remoting.ChromotingEvent = function(type) {
36 /** @type {remoting.ChromotingEvent.Type} */
37 this.type = type;
38 /** @private {remoting.ChromotingEvent.Os} */
39 this.os;
40 /** @private {string} */
41 this.os_version;
42 /** @private {string} */
43 this.browser_version;
44 /** @private {string} */
45 this.webapp_version;
46 /** @type {string} */
47 this.host_version;
48 /** @private {string} */
49 this.cpu;
50 /** @type {remoting.ChromotingEvent.SessionState} */
51 this.session_state;
52 /** @private {remoting.ChromotingEvent.ConnectionType} */
53 this.connection_type;
54 /** @private {string} */
55 this.application_id;
56 /** @type {string} */
57 this.session_id;
58 /** @type {remoting.ChromotingEvent.Role} */
59 this.role;
60 /** @type {remoting.ChromotingEvent.ConnectionError} */
61 this.connection_error;
62 /** @type {number} */
63 this.session_duration;
64 /** @type {number} */
65 this.video_bandwidth;
66 /** @type {number} */
67 this.capture_latency;
68 /** @type {number} */
69 this.encode_latency;
70 /** @type {number} */
71 this.decode_latency;
72 /** @type {number} */
73 this.render_latency;
74 /** @type {number} */
75 this.roundtrip_latency;
76 /** @type {remoting.ChromotingEvent.Mode} */
77 this.mode;
78 /** @type {remoting.ChromotingEvent.SignalStrategyType} */
79 this.signal_strategy_type;
80 /** @type {remoting.ChromotingEvent.SignalStrategyProgress} */
81 this.signal_strategy_progress;
83 this.init_();
86 /** @private */
87 remoting.ChromotingEvent.prototype.init_ = function() {
88 // System Info.
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;
103 // App Info.
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
136 * @return {boolean}
138 remoting.ChromotingEvent.isEndOfSession = function(event) {
139 if (event.type !== remoting.ChromotingEvent.Type.SESSION_STATE) {
140 return false;
142 var endStates = [
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;
158 switch(state) {
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;
177 default:
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;
213 default:
214 throw new Error('Unknown error Tag : ' + error.getTag());
219 * @param {remoting.SignalStrategy.Type} type
220 * @return {remoting.ChromotingEvent.SignalStrategyType}
222 function toSignalStrategyType(type) {
223 switch (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;
228 default:
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;
239 switch (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;
250 default:
251 throw new Error('Unknown signal strategy progress :=' + progress);
256 * @param {string} type
257 * @return {remoting.ChromotingEvent.ConnectionType}
259 function toConnectionType(type) {
260 switch (type) {
261 case 'direct':
262 return remoting.ChromotingEvent.ConnectionType.DIRECT;
263 case 'stun':
264 return remoting.ChromotingEvent.ConnectionType.STUN;
265 case 'relay':
266 return remoting.ChromotingEvent.ConnectionType.RELAY;
267 default:
268 throw new Error('Unknown ConnectionType :=' + type);
272 })();
275 * @enum {number}
277 remoting.ChromotingEvent.Type = {
278 SESSION_STATE: 1,
279 CONNECTION_STATISTICS: 2,
280 SESSION_ID_OLD: 3,
281 SESSION_ID_NEW: 4,
282 HEARTBEAT: 5,
283 HEARTBEAT_REJECTED: 6,
284 RESTART: 7,
285 HOST_STATUS: 8,
286 SIGNAL_STRATEGY_PROGRESS: 9
289 /** @enum {number} */
290 remoting.ChromotingEvent.Role = {
291 CLIENT: 0,
292 HOST: 1
295 /** @enum {number} */
296 remoting.ChromotingEvent.Os = {
297 LINUX: 1,
298 CHROMEOS: 2,
299 MAC: 3,
300 WINDOWS: 4,
301 OTHER: 5,
302 ANDROID: 6,
303 IOS: 7
306 /** @enum {number} */
307 remoting.ChromotingEvent.SessionState = {
308 UNKNOWN: 1,
309 CREATED: 2,
310 BAD_PLUGIN_VERSION: 3,
311 UNKNOWN_PLUGIN_ERROR: 4,
312 CONNECTING: 5,
313 INITIALIZING: 6,
314 CONNECTED: 7,
315 CLOSED: 8,
316 CONNECTION_FAILED: 9,
317 UNDEFINED: 10,
318 PLUGIN_DISABLED: 11,
319 CONNECTION_DROPPED: 12,
320 CONNECTION_CANCELED: 13,
321 AUTHENTICATED: 14
324 /** @enum {number} */
325 remoting.ChromotingEvent.ConnectionType = {
326 DIRECT: 1,
327 STUN: 2,
328 RELAY: 3
331 /** @enum {number} */
332 remoting.ChromotingEvent.ConnectionError = {
333 NONE: 1,
334 HOST_OFFLINE: 2,
335 SESSION_REJECTED: 3,
336 INCOMPATIBLE_PROTOCOL: 4,
337 NETWORK_FAILURE: 5,
338 UNKNOWN_ERROR: 6,
339 INVALID_ACCESS_CODE: 7,
340 MISSING_PLUGIN: 8,
341 AUTHENTICATION_FAILED: 9,
342 ERROR_BAD_PLUGIN_VERSION: 10,
343 HOST_OVERLOAD: 11,
344 P2P_FAILURE: 12,
345 UNEXPECTED: 13,
346 CLIENT_SUSPENDED: 14
349 /** @enum {number} */
350 remoting.ChromotingEvent.Mode = {
351 IT2ME: 1,
352 ME2ME: 2,
353 LGAPP: 3
356 /** @enum {number} */
357 remoting.ChromotingEvent.SignalStrategyType = {
358 XMPP: 1,
359 WCS: 2
362 /** @enum {number} */
363 remoting.ChromotingEvent.SignalStrategyProgress = {
364 SUCCEEDED: 1,
365 FAILED: 2,
366 TIMED_OUT: 3,
367 SUCCEEDED_LATE: 4,
368 FAILED_LATE: 5