-
Notifications
You must be signed in to change notification settings - Fork 8
/
client_screen.js
123 lines (110 loc) · 3.56 KB
/
client_screen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Functions related to the 'client screen' for Chromoting.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @type {remoting.ClientSession} The client session object, set once the
* connector has invoked its onOk callback.
*/
remoting.clientSession = null;
/**
* @type {remoting.DesktopConnectedView} The client session object, set once the
* connector has invoked its onOk callback.
*/
remoting.desktopConnectedView = null;
/**
* Update the remoting client layout in response to a resize event.
*
* @return {void} Nothing.
*/
remoting.onResize = function() {
if (remoting.desktopConnectedView) {
remoting.desktopConnectedView.onResize();
}
};
/**
* Handle changes in the visibility of the window, for example by pausing video.
*
* @return {void} Nothing.
*/
remoting.onVisibilityChanged = function() {
if (remoting.desktopConnectedView) {
remoting.desktopConnectedView.pauseVideo(
('hidden' in document) ? document.hidden : document.webkitHidden);
}
};
/**
* Disconnect the remoting client.
*
* @return {void} Nothing.
*/
remoting.disconnect = function() {
if (!remoting.clientSession) {
return;
}
remoting.clientSession.disconnect(remoting.Error.NONE);
console.log('Disconnected.');
};
/**
* Callback function called when the state of the client plugin changes. The
* current and previous states are available via the |state| member variable.
*
* @param {remoting.ClientSession.StateEvent=} state
*/
function onClientStateChange_(state) {
switch (state.current) {
case remoting.ClientSession.State.CLOSED:
console.log('Connection closed by host');
if (remoting.desktopConnectedView.getMode() ==
remoting.DesktopConnectedView.Mode.IT2ME) {
remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME);
remoting.hangoutSessionEvents.raiseEvent(
remoting.hangoutSessionEvents.sessionStateChanged,
remoting.ClientSession.State.CLOSED);
} else {
remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
}
remoting.app.onDisconnected();
break;
case remoting.ClientSession.State.FAILED:
var error = remoting.clientSession.getError();
console.error('Client plugin reported connection failed: ' + error);
if (error == null) {
error = remoting.Error.UNEXPECTED;
}
remoting.app.onError(error);
break;
default:
console.error('Unexpected client plugin state: ' + state.current);
// This should only happen if the web-app and client plugin get out of
// sync, so MISSING_PLUGIN is a suitable error.
remoting.app.onError(remoting.Error.MISSING_PLUGIN);
break;
}
remoting.clientSession.removeEventListener('stateChanged',
onClientStateChange_);
remoting.clientSession.cleanup();
remoting.clientSession = null;
remoting.desktopConnectedView = null;
}
/**
* Timer callback to update the statistics panel.
*/
function updateStatistics_() {
if (!remoting.clientSession ||
remoting.clientSession.getState() !=
remoting.ClientSession.State.CONNECTED) {
return;
}
var perfstats = remoting.clientSession.getPerfStats();
remoting.stats.update(perfstats);
remoting.clientSession.logStatistics(perfstats);
// Update the stats once per second.
window.setTimeout(updateStatistics_, 1000);
}