1 // Copyright (c) 2012 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 * Functions related to the 'client screen' for Chromoting.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
16 * @type {remoting.ClientSession} The client session object, set once the
17 * connector has invoked its onOk callback.
19 remoting.clientSession = null;
22 * @type {remoting.DesktopConnectedView} The client session object, set once the
23 * connector has invoked its onOk callback.
25 remoting.desktopConnectedView = null;
28 * Update the remoting client layout in response to a resize event.
30 * @return {void} Nothing.
32 remoting.onResize = function() {
33 if (remoting.desktopConnectedView) {
34 remoting.desktopConnectedView.onResize();
39 * Handle changes in the visibility of the window, for example by pausing video.
41 * @return {void} Nothing.
43 remoting.onVisibilityChanged = function() {
44 if (remoting.desktopConnectedView) {
45 remoting.desktopConnectedView.pauseVideo(
46 ('hidden' in document) ? document.hidden : document.webkitHidden);
51 * Disconnect the remoting client.
53 * @return {void} Nothing.
55 remoting.disconnect = function() {
56 if (!remoting.clientSession) {
59 remoting.clientSession.disconnect(remoting.Error.NONE);
60 console.log('Disconnected.');
64 * Callback function called when the state of the client plugin changes. The
65 * current and previous states are available via the |state| member variable.
67 * @param {remoting.ClientSession.StateEvent=} state
69 function onClientStateChange_(state) {
70 switch (state.current) {
71 case remoting.ClientSession.State.CLOSED:
72 console.log('Connection closed by host');
73 if (remoting.desktopConnectedView.getMode() ==
74 remoting.DesktopConnectedView.Mode.IT2ME) {
75 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME);
76 remoting.hangoutSessionEvents.raiseEvent(
77 remoting.hangoutSessionEvents.sessionStateChanged,
78 remoting.ClientSession.State.CLOSED);
80 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME);
82 remoting.app.onDisconnected();
85 case remoting.ClientSession.State.FAILED:
86 var error = remoting.clientSession.getError();
87 console.error('Client plugin reported connection failed: ' + error);
89 error = remoting.Error.UNEXPECTED;
91 remoting.app.onError(error);
95 console.error('Unexpected client plugin state: ' + state.current);
96 // This should only happen if the web-app and client plugin get out of
97 // sync, so MISSING_PLUGIN is a suitable error.
98 remoting.app.onError(remoting.Error.MISSING_PLUGIN);
102 remoting.clientSession.removeEventListener('stateChanged',
103 onClientStateChange_);
104 remoting.clientSession.cleanup();
105 remoting.clientSession = null;
106 remoting.desktopConnectedView = null;
110 * Timer callback to update the statistics panel.
112 function updateStatistics_() {
113 if (!remoting.clientSession ||
114 remoting.clientSession.getState() !=
115 remoting.ClientSession.State.CONNECTED) {
118 var perfstats = remoting.clientSession.getPerfStats();
119 remoting.stats.update(perfstats);
120 remoting.clientSession.logStatistics(perfstats);
121 // Update the stats once per second.
122 window.setTimeout(updateStatistics_, 1000);