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.
7 * Class handling user-facing aspects of the client session.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
16 * @param {HTMLElement} container
17 * @param {remoting.ConnectionInfo} connectionInfo
19 * @extends {base.EventSourceImpl}
20 * @implements {base.Disposable}
22 remoting.DesktopConnectedView = function(container, connectionInfo) {
24 /** @private {HTMLElement} */
25 this.container_ = container;
27 /** @private {remoting.ClientPlugin} */
28 this.plugin_ = connectionInfo.plugin();
30 /** @private {remoting.ClientSession} */
31 this.session_ = connectionInfo.session();
34 this.host_ = connectionInfo.host();
36 /** @private {remoting.DesktopViewport} */
37 this.viewport_ = null;
39 /** private {remoting.ConnectedView} */
42 /** @private {remoting.VideoFrameRecorder} */
43 this.videoFrameRecorder_ = null;
45 /** private {base.Disposable} */
46 this.eventHooks_ = null;
49 this.stats_ = new remoting.ConnectionStats(
50 document.getElementById('statistics'), connectionInfo.plugin());
56 /** @return {void} Nothing. */
57 remoting.DesktopConnectedView.prototype.dispose = function() {
58 if (remoting.windowFrame) {
59 remoting.windowFrame.setDesktopConnectedView(null);
61 if (remoting.toolbar) {
62 remoting.toolbar.setDesktopConnectedView(null);
64 if (remoting.optionsMenu) {
65 remoting.optionsMenu.setDesktopConnectedView(null);
68 document.body.classList.remove('connected');
70 base.dispose(this.eventHooks_);
71 this.eventHooks_ = null;
73 base.dispose(this.viewport_);
74 this.viewport_ = null;
76 base.dispose(this.stats_);
81 * Get host display name.
85 remoting.DesktopConnectedView.prototype.getHostDisplayName = function() {
86 return this.host_.hostName;
90 * @return {boolean} True if shrink-to-fit is enabled; false otherwise.
92 remoting.DesktopConnectedView.prototype.getShrinkToFit = function() {
94 return this.viewport_.getShrinkToFit();
100 * @return {boolean} True if resize-to-client is enabled; false otherwise.
102 remoting.DesktopConnectedView.prototype.getResizeToClient = function() {
103 if (this.viewport_) {
104 return this.viewport_.getResizeToClient();
109 remoting.DesktopConnectedView.prototype.toggleStats = function() {
110 this.stats_.toggle();
114 * @return {boolean} True if the connection stats is visible; false otherwise.
116 remoting.DesktopConnectedView.prototype.isStatsVisible = function() {
117 return this.stats_.isVisible();
121 * @return {Element} The element that should host the plugin.
124 remoting.DesktopConnectedView.prototype.getPluginContainer_ = function() {
125 return this.container_.querySelector('.client-plugin-container');
128 /** @return {remoting.DesktopViewport} */
129 remoting.DesktopConnectedView.prototype.getViewportForTesting = function() {
130 return this.viewport_;
134 remoting.DesktopConnectedView.prototype.initPlugin_ = function() {
135 base.debug.assert(remoting.app instanceof remoting.DesktopRemoting);
136 var drApp = /** @type {remoting.DesktopRemoting} */ (remoting.app);
137 var mode = drApp.getConnectionMode();
139 // Show the Send Keys menu only if the plugin has the injectKeyEvent feature,
140 // and the Ctrl-Alt-Del button only in Me2Me mode.
141 if (!this.plugin_.hasFeature(
142 remoting.ClientPlugin.Feature.INJECT_KEY_EVENT)) {
143 var sendKeysElement = document.getElementById('send-keys-menu');
144 sendKeysElement.hidden = true;
145 } else if (mode == remoting.DesktopRemoting.Mode.IT2ME) {
146 var sendCadElement = document.getElementById('send-ctrl-alt-del');
147 sendCadElement.hidden = true;
152 * This is a callback that gets called when the window is resized.
154 * @return {void} Nothing.
157 remoting.DesktopConnectedView.prototype.onResize_ = function() {
158 if (this.viewport_) {
159 this.viewport_.onResize();
164 remoting.DesktopConnectedView.prototype.initUI_ = function() {
165 document.body.classList.add('connected');
167 this.view_ = new remoting.ConnectedView(
168 this.plugin_, this.container_,
169 this.container_.querySelector('.mouse-cursor-overlay'));
171 var scrollerElement = document.getElementById('scroller');
172 this.viewport_ = new remoting.DesktopViewport(
173 scrollerElement || document.body,
174 this.plugin_.hostDesktop(),
177 if (remoting.windowFrame) {
178 remoting.windowFrame.setDesktopConnectedView(this);
180 if (remoting.toolbar) {
181 remoting.toolbar.setDesktopConnectedView(this);
183 if (remoting.optionsMenu) {
184 remoting.optionsMenu.setDesktopConnectedView(this);
187 // Activate full-screen related UX.
188 this.eventHooks_ = new base.Disposables(
190 new base.EventHook(this.session_,
191 remoting.ClientSession.Events.videoChannelStateChanged,
192 this.view_.onConnectionReady.bind(this.view_)),
193 new base.DomEventHook(window, 'resize', this.onResize_.bind(this), false),
194 new remoting.Fullscreen.EventHook(this.onFullScreenChanged_.bind(this)));
195 this.onFullScreenChanged_(remoting.fullscreen.isActive());
199 * Set the shrink-to-fit and resize-to-client flags and save them if this is
200 * a Me2Me connection.
202 * @param {boolean} shrinkToFit True if the remote desktop should be scaled
203 * down if it is larger than the client window; false if scroll-bars
204 * should be added in this case.
205 * @param {boolean} resizeToClient True if window resizes should cause the
206 * host to attempt to resize its desktop to match the client window size;
207 * false to disable this behaviour for subsequent window resizes--the
208 * current host desktop size is not restored in this case.
209 * @return {void} Nothing.
211 remoting.DesktopConnectedView.prototype.setScreenMode =
212 function(shrinkToFit, resizeToClient) {
213 this.viewport_.setScreenMode(shrinkToFit, resizeToClient);
217 * Called when the full-screen status has changed, either via the
218 * remoting.Fullscreen class, or via a system event such as the Escape key
220 * @param {boolean=} fullscreen True if the app is entering full-screen mode;
221 * false if it is leaving it.
224 remoting.DesktopConnectedView.prototype.onFullScreenChanged_ = function (
226 if (this.viewport_) {
227 // When a window goes full-screen, a resize event is triggered, but the
228 // Fullscreen.isActive call is not guaranteed to return true until the
229 // full-screen event is triggered. In apps v2, the size of the window's
230 // client area is calculated differently in full-screen mode, so register
232 this.viewport_.onResize();
233 this.viewport_.enableBumpScroll(Boolean(fullscreen));
238 * Sends a Ctrl-Alt-Del sequence to the remoting client.
240 * @return {void} Nothing.
242 remoting.DesktopConnectedView.prototype.sendCtrlAltDel = function() {
243 console.log('Sending Ctrl-Alt-Del.');
244 this.plugin_.injectKeyCombination([0x0700e0, 0x0700e2, 0x07004c]);
248 * Sends a Print Screen keypress to the remoting client.
250 * @return {void} Nothing.
252 remoting.DesktopConnectedView.prototype.sendPrintScreen = function() {
253 console.log('Sending Print Screen.');
254 this.plugin_.injectKeyCombination([0x070046]);
258 * Sets and stores the key remapping setting for the current host. If set,
259 * these mappings override the defaults for the client platform.
261 * @param {string} remappings Comma-separated list of key remappings.
263 remoting.DesktopConnectedView.prototype.setRemapKeys = function(remappings) {
264 this.plugin_.setRemapKeys(remappings);
265 // Save the new remapping setting.
266 this.host_.options.remapKeys = remappings;
267 this.host_.options.save();
270 /** @param {remoting.VideoFrameRecorder} recorder */
271 remoting.DesktopConnectedView.prototype.setVideoFrameRecorder =
273 this.videoFrameRecorder_ = recorder;
277 * Returns true if the ClientSession can record video frames to a file.
280 remoting.DesktopConnectedView.prototype.canRecordVideo = function() {
281 return !!this.videoFrameRecorder_;
285 * Returns true if the ClientSession is currently recording video frames.
288 remoting.DesktopConnectedView.prototype.isRecordingVideo = function() {
289 if (!this.videoFrameRecorder_) {
292 return this.videoFrameRecorder_.isRecording();
296 * Starts or stops recording of video frames.
298 remoting.DesktopConnectedView.prototype.startStopRecording = function() {
299 if (this.videoFrameRecorder_) {
300 this.videoFrameRecorder_.startStopRecording();