OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
7 | 7 |
8 (function() { | 8 (function() { |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** | 12 /** |
13 * This class provides common functionality to Me2MeActivity and It2MeActivity, | 13 * This class provides common functionality to Me2MeActivity and It2MeActivity, |
14 * e.g. constructing the relevant UX, and delegate the custom handling of the | 14 * e.g. constructing the relevant UX, and delegate the custom handling of the |
15 * session state changes to the |parentActivity|. | 15 * session state changes to the |parentActivity|. |
16 * | 16 * |
17 * @param {remoting.Activity} parentActivity | 17 * @param {remoting.Activity} parentActivity |
18 * @implements {remoting.ClientSession.EventHandler} | 18 * @implements {remoting.ClientSession.EventHandler} |
19 * @implements {base.Disposable} | 19 * @implements {base.Disposable} |
20 * @constructor | 20 * @constructor |
21 */ | 21 */ |
22 remoting.DesktopRemotingActivity = function(parentActivity) { | 22 remoting.DesktopRemotingActivity = function(parentActivity) { |
23 /** @private */ | 23 /** @private */ |
24 this.parentActivity_ = parentActivity; | 24 this.parentActivity_ = parentActivity; |
25 /** @private {remoting.DesktopConnectedView} */ | 25 /** @private {remoting.DesktopConnectedView} */ |
26 this.connectedView_ = null; | 26 this.connectedView_ = null; |
| 27 /** @private {remoting.ClientSession} */ |
| 28 this.session_ = null; |
| 29 }; |
| 30 |
| 31 remoting.DesktopRemotingActivity.prototype.stop = function() { |
| 32 if (this.session_) { |
| 33 this.session_.disconnect(remoting.Error.none()); |
| 34 console.log('Disconnected.'); |
| 35 } |
27 }; | 36 }; |
28 | 37 |
29 /** | 38 /** |
30 * @param {remoting.ConnectionInfo} connectionInfo | 39 * @param {remoting.ConnectionInfo} connectionInfo |
31 */ | 40 */ |
32 remoting.DesktopRemotingActivity.prototype.onConnected = | 41 remoting.DesktopRemotingActivity.prototype.onConnected = |
33 function(connectionInfo) { | 42 function(connectionInfo) { |
34 remoting.setMode(remoting.AppMode.IN_SESSION); | 43 remoting.setMode(remoting.AppMode.IN_SESSION); |
35 if (!base.isAppsV2()) { | 44 if (!base.isAppsV2()) { |
36 remoting.toolbar.center(); | 45 remoting.toolbar.center(); |
37 remoting.toolbar.preview(); | 46 remoting.toolbar.preview(); |
38 } | 47 } |
39 | 48 |
| 49 this.session_ = connectionInfo.session(); |
| 50 |
40 this.connectedView_ = new remoting.DesktopConnectedView( | 51 this.connectedView_ = new remoting.DesktopConnectedView( |
41 document.getElementById('client-container'), connectionInfo); | 52 document.getElementById('client-container'), connectionInfo); |
42 | 53 |
43 // By default, under ChromeOS, remap the right Control key to the right | 54 // By default, under ChromeOS, remap the right Control key to the right |
44 // Win / Cmd key. | 55 // Win / Cmd key. |
45 if (remoting.platformIsChromeOS()) { | 56 if (remoting.platformIsChromeOS()) { |
46 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); | 57 connectionInfo.plugin().setRemapKeys('0x0700e4>0x0700e7'); |
47 } | 58 } |
48 | 59 |
49 if (connectionInfo.session().hasCapability( | 60 if (connectionInfo.session().hasCapability( |
50 remoting.ClientSession.Capability.VIDEO_RECORDER)) { | 61 remoting.ClientSession.Capability.VIDEO_RECORDER)) { |
51 var recorder = new remoting.VideoFrameRecorder(); | 62 var recorder = new remoting.VideoFrameRecorder(); |
52 connectionInfo.plugin().extensions().register(recorder); | 63 connectionInfo.plugin().extensions().register(recorder); |
53 this.connectedView_.setVideoFrameRecorder(recorder); | 64 this.connectedView_.setVideoFrameRecorder(recorder); |
54 } | 65 } |
55 | 66 |
56 this.parentActivity_.onConnected(connectionInfo); | 67 this.parentActivity_.onConnected(connectionInfo); |
57 }; | 68 }; |
58 | 69 |
59 remoting.DesktopRemotingActivity.prototype.onDisconnected = function() { | 70 remoting.DesktopRemotingActivity.prototype.onDisconnected = function() { |
60 this.parentActivity_.onDisconnected(); | 71 this.parentActivity_.onDisconnected(); |
61 base.dispose(this.connectedView_); | 72 this.dispose(); |
62 this.connectedView_ = null; | |
63 }; | 73 }; |
64 | 74 |
65 /** | 75 /** |
66 * @param {!remoting.Error} error | 76 * @param {!remoting.Error} error |
67 */ | 77 */ |
68 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = | 78 remoting.DesktopRemotingActivity.prototype.onConnectionFailed = |
69 function(error) { | 79 function(error) { |
70 this.parentActivity_.onConnectionFailed(error); | 80 this.parentActivity_.onConnectionFailed(error); |
71 }; | 81 }; |
72 | 82 |
73 /** | 83 /** |
74 * @param {!remoting.Error} error The error to be localized and displayed. | 84 * @param {!remoting.Error} error The error to be localized and displayed. |
75 */ | 85 */ |
76 remoting.DesktopRemotingActivity.prototype.onError = function(error) { | 86 remoting.DesktopRemotingActivity.prototype.onError = function(error) { |
77 console.error('Connection failed: ' + error.toString()); | 87 console.error('Connection failed: ' + error.toString()); |
78 | 88 |
79 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { | 89 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
80 remoting.setMode(remoting.AppMode.HOME); | 90 remoting.setMode(remoting.AppMode.HOME); |
81 remoting.handleAuthFailureAndRelaunch(); | 91 remoting.handleAuthFailureAndRelaunch(); |
82 return; | 92 return; |
83 } | 93 } |
84 | 94 |
85 this.parentActivity_.onError(error); | 95 this.parentActivity_.onError(error); |
86 | 96 |
87 base.dispose(this.connectedView_); | 97 this.dispose(); |
88 this.connectedView_ = null; | |
89 }; | 98 }; |
90 | 99 |
91 remoting.DesktopRemotingActivity.prototype.dispose = function() { | 100 remoting.DesktopRemotingActivity.prototype.dispose = function() { |
92 base.dispose(this.connectedView_); | 101 base.dispose(this.connectedView_); |
93 this.connectedView_ = null; | 102 this.connectedView_ = null; |
| 103 this.session_ = null; |
94 }; | 104 }; |
95 | 105 |
96 /** @return {remoting.DesktopConnectedView} */ | 106 /** @return {remoting.DesktopConnectedView} */ |
97 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { | 107 remoting.DesktopRemotingActivity.prototype.getConnectedView = function() { |
98 return this.connectedView_; | 108 return this.connectedView_; |
99 }; | 109 }; |
100 | 110 |
101 })(); | 111 })(); |
OLD | NEW |