Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / webapp / base / js / chromoting_event.js
blob69e8a81e082f1b1931cd1cf1650f8da92340cf33
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.
29  *
30  * @param {remoting.ChromotingEvent.Type} type
31  *
32  * @constructor
33  * @struct
34  */
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.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;
100   }
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.ChromotingEvent} event
110  * @return {boolean}
111  */
112 remoting.ChromotingEvent.isEndOfSession = function(event) {
113   if (event.type !== remoting.ChromotingEvent.Type.SESSION_STATE) {
114     return false;
115   }
116   var endStates = [
117     remoting.ChromotingEvent.SessionState.CLOSED,
118     remoting.ChromotingEvent.SessionState.CONNECTION_DROPPED,
119     remoting.ChromotingEvent.SessionState.CONNECTION_FAILED,
120     remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED
121   ];
122   return endStates.indexOf(event.session_state) !== -1;
125 })();
128  * @enum {number}
129  */
130 remoting.ChromotingEvent.Type = {
131   SESSION_STATE: 1,
132   CONNECTION_STATISTICS: 2,
133   SESSION_ID_OLD: 3,
134   SESSION_ID_NEW: 4,
135   HEARTBEAT: 5,
136   HEARTBEAT_REJECTED: 6,
137   RESTART: 7,
138   HOST_STATUS: 8,
139   SIGNAL_STRATEGY_PROGRESS: 9
142 /** @enum {number} */
143 remoting.ChromotingEvent.Role = {
144   CLIENT: 0,
145   HOST: 1
148 /** @enum {number} */
149 remoting.ChromotingEvent.Os = {
150   LINUX: 1,
151   CHROMEOS: 2,
152   MAC: 3,
153   WINDOWS: 4,
154   OTHER: 5,
155   ANDROID: 6,
156   IOS: 7
159 /** @enum {number} */
160 remoting.ChromotingEvent.SessionState = {
161   UNKNOWN: 1,
162   CREATED: 2,
163   BAD_PLUGIN_VERSION: 3,
164   UNKNOWN_PLUGIN_ERROR: 4,
165   CONNECTING: 5,
166   INITIALIZING: 6,
167   CONNECTED: 7,
168   CLOSED: 8,
169   CONNECTION_FAILED: 9,
170   UNDEFINED: 10,
171   PLUGIN_DISABLED: 11,
172   CONNECTION_DROPPED: 12,
173   CONNECTION_CANCELED: 13,
174   AUTHENTICATED: 14
177 /** @enum {number} */
178 remoting.ChromotingEvent.ConnectionType = {
179   DIRECT: 1,
180   STUN: 2,
181   RELAY: 3
184 /** @enum {number} */
185 remoting.ChromotingEvent.ConnectionError = {
186   NONE: 1,
187   HOST_OFFLINE: 2,
188   SESSION_REJECTED: 3,
189   INCOMPATIBLE_PROTOCOL: 4,
190   NETWORK_FAILURE: 5,
191   UNKNOWN_ERROR: 6,
192   INVALID_ACCESS_CODE: 7,
193   MISSING_PLUGIN: 8,
194   AUTHENTICATION_FAILED: 9,
195   ERROR_BAD_PLUGIN_VERSION: 10,
196   HOST_OVERLOAD: 11,
197   P2P_FAILURE: 12,
198   UNEXPECTED: 13,
199   CLIENT_SUSPENDED: 14
202 /** @enum {number} */
203 remoting.ChromotingEvent.Mode = {
204   IT2ME: 1,
205   ME2ME: 2,
206   LGAPP: 3
209 /** @enum {number} */
210 remoting.ChromotingEvent.SignalStrategyType = {
211   XMPP: 1,
212   WCS: 2
215 /** @enum {number} */
216 remoting.ChromotingEvent.SignalStrategyProgress = {
217   SUCCEEDED: 1,
218   FAILED: 2,
219   TIMED_OUT: 3,
220   SUCCEEDED_LATE: 4,
221   FAILED_LATE: 5