Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / base / js / chromoting_event.js
blob72652f5771b016d98c1ec16644eeffb3a2523007
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 /** @type {remoting.ChromotingEvent.SessionState} */
53 this.previous_session_state;
54 /** @type {remoting.ChromotingEvent.ConnectionType} */
55 this.connection_type;
56 /** @private {string} */
57 this.application_id;
58 /** @type {string} */
59 this.session_id;
60 /** @type {remoting.ChromotingEvent.Role} */
61 this.role;
62 /** @type {remoting.ChromotingEvent.ConnectionError} */
63 this.connection_error;
64 /** @type {number} */
65 this.session_duration;
66 /** @type {number} */
67 this.video_bandwidth;
68 /** @type {number} */
69 this.capture_latency;
70 /** @type {number} */
71 this.encode_latency;
72 /** @type {number} */
73 this.decode_latency;
74 /** @type {number} */
75 this.render_latency;
76 /** @type {number} */
77 this.roundtrip_latency;
78 /** @type {remoting.ChromotingEvent.Mode} */
79 this.mode;
80 /** @type {remoting.ChromotingEvent.SignalStrategyType} */
81 this.signal_strategy_type;
82 /** @type {remoting.ChromotingEvent.SignalStrategyProgress} */
83 this.signal_strategy_progress;
84 /** @type {?remoting.ChromotingEvent.XmppError} */
85 this.xmpp_error;
86 /** @type {remoting.ChromotingEvent.SessionEntryPoint} */
87 this.session_entry_point;
89 this.init_();
92 /** @private */
93 remoting.ChromotingEvent.prototype.init_ = function() {
94 // System Info.
95 var systemInfo = remoting.getSystemInfo();
96 this.cpu = systemInfo.cpu;
97 this.os_version = systemInfo.osVersion;
98 if (systemInfo.osName === remoting.Os.WINDOWS) {
99 this.os = remoting.ChromotingEvent.Os.WINDOWS;
100 } else if (systemInfo.osName === remoting.Os.LINUX) {
101 this.os = remoting.ChromotingEvent.Os.LINUX;
102 } else if (systemInfo.osName === remoting.Os.MAC) {
103 this.os = remoting.ChromotingEvent.Os.MAC;
104 } else if (systemInfo.osName === remoting.Os.CHROMEOS) {
105 this.os = remoting.ChromotingEvent.Os.CHROMEOS;
107 this.browser_version = systemInfo.chromeVersion;
109 // App Info.
110 this.webapp_version = chrome.runtime.getManifest().version;
111 this.application_id = chrome.runtime.id;
115 * @param {remoting.ChromotingEvent} event
116 * @return {boolean}
118 remoting.ChromotingEvent.isEndOfSession = function(event) {
119 if (event.type !== remoting.ChromotingEvent.Type.SESSION_STATE) {
120 return false;
122 var endStates = [
123 remoting.ChromotingEvent.SessionState.CLOSED,
124 remoting.ChromotingEvent.SessionState.CONNECTION_DROPPED,
125 remoting.ChromotingEvent.SessionState.CONNECTION_FAILED,
126 remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED
128 return endStates.indexOf(event.session_state) !== -1;
132 * This is declared as a separate structure to match the proto format
133 * on the cloud. The cloud will parse the raw stanza for more detailed
134 * fields, e.g. error condition, error type, jingle action, etc.
136 * @param {string} stanza
137 * @struct
138 * @constructor
140 remoting.ChromotingEvent.XmppError = function(stanza) {
141 /** @type {string} */
142 this.raw_stanza = stanza;
145 })();
148 * @enum {number}
150 remoting.ChromotingEvent.Type = {
151 SESSION_STATE: 1,
152 CONNECTION_STATISTICS: 2,
153 SESSION_ID_OLD: 3,
154 SESSION_ID_NEW: 4,
155 HEARTBEAT: 5,
156 HEARTBEAT_REJECTED: 6,
157 RESTART: 7,
158 HOST_STATUS: 8,
159 SIGNAL_STRATEGY_PROGRESS: 9
162 /** @enum {number} */
163 remoting.ChromotingEvent.Role = {
164 CLIENT: 0,
165 HOST: 1
168 /** @enum {number} */
169 remoting.ChromotingEvent.Os = {
170 LINUX: 1,
171 CHROMEOS: 2,
172 MAC: 3,
173 WINDOWS: 4,
174 OTHER: 5,
175 ANDROID: 6,
176 IOS: 7
179 /** @enum {number} */
180 remoting.ChromotingEvent.SessionState = {
181 UNKNOWN: 1, // deprecated.
182 CREATED: 2, // deprecated.
183 BAD_PLUGIN_VERSION: 3, // deprecated.
184 UNKNOWN_PLUGIN_ERROR: 4, // deprecated.
185 CONNECTING: 5,
186 INITIALIZING: 6, // deprecated.
187 CONNECTED: 7,
188 CLOSED: 8,
189 CONNECTION_FAILED: 9,
190 UNDEFINED: 10,
191 PLUGIN_DISABLED: 11, // deprecated.
192 CONNECTION_DROPPED: 12,
193 CONNECTION_CANCELED: 13,
194 AUTHENTICATED: 14,
195 STARTED: 15,
196 SIGNALING: 16,
197 CREATING_PLUGIN: 17,
200 /** @enum {number} */
201 remoting.ChromotingEvent.SessionEntryPoint = {
202 CONNECT_BUTTON: 1,
203 RECONNECT_BUTTON: 2,
204 AUTO_RECONNECT_ON_CONNECTION_DROPPED: 3,
205 AUTO_RECONNECT_ON_HOST_OFFLINE: 4
208 /** @enum {number} */
209 remoting.ChromotingEvent.ConnectionType = {
210 DIRECT: 1,
211 STUN: 2,
212 RELAY: 3
215 /** @enum {number} */
216 remoting.ChromotingEvent.ConnectionError = {
217 NONE: 1,
218 HOST_OFFLINE: 2,
219 SESSION_REJECTED: 3,
220 INCOMPATIBLE_PROTOCOL: 4,
221 NETWORK_FAILURE: 5,
222 UNKNOWN_ERROR: 6,
223 INVALID_ACCESS_CODE: 7,
224 MISSING_PLUGIN: 8,
225 AUTHENTICATION_FAILED: 9,
226 ERROR_BAD_PLUGIN_VERSION: 10,
227 HOST_OVERLOAD: 11,
228 P2P_FAILURE: 12,
229 UNEXPECTED: 13,
230 CLIENT_SUSPENDED: 14
233 /** @enum {number} */
234 remoting.ChromotingEvent.Mode = {
235 IT2ME: 1,
236 ME2ME: 2,
237 LGAPP: 3
240 /** @enum {number} */
241 remoting.ChromotingEvent.SignalStrategyType = {
242 XMPP: 1,
243 WCS: 2
246 /** @enum {number} */
247 remoting.ChromotingEvent.SignalStrategyProgress = {
248 SUCCEEDED: 1,
249 FAILED: 2,
250 TIMED_OUT: 3,
251 SUCCEEDED_LATE: 4,
252 FAILED_LATE: 5