-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassroom.htm
More file actions
231 lines (216 loc) · 12.7 KB
/
Classroom.htm
File metadata and controls
231 lines (216 loc) · 12.7 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en" ng-app="classroomApp" class="no-js" ng-controller="MainController">
<!--
Copyright (C) 2015, Manuel Meitinger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<title ng-bind-template="{{settings.title}}"></title>
<script src="https://code.jquery.com/jquery-1.11.3.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
'use strict';
var viewers = {};
angular.module('classroomApp', [])
.constant('Resolutions', [
{ w: 16, h: 9 },
{ w: 8, h: 5 },
{ w: 5, h: 4 },
{ w: 4, h: 3 },
{ w: 1, h: 1 }
])
.constant('ConnectionState', {
Disconnected: 1,
Connecting: 2,
Establishing: 3,
Connected: 4
})
.constant('DisconnectReasons', {
'0': 'No information is available.',
'1': 'Local disconnection.',
'2': 'Remote disconnection by user.',
'3': 'Remote disconnection by server.',
'260': 'DNS name lookup failure.',
'262': 'Out of memory.',
'264': 'Connection timed out.',
'516': 'Windows Sockets connect failed.',
'518': 'Out of memory.',
'520': 'Host not found error.',
'772': 'Windows Sockets send call failed.',
'774': 'Out of memory.',
'776': 'Invalid IP address specified.',
'1028': 'Windows Sockets recv call failed.',
'1030': 'Invalid security data.',
'1032': 'Internal error.',
'1286': 'Invalid encryption method specified.',
'1288': 'DNS lookup failed.',
'1540': 'Windows Sockets gethostbyname call failed.',
'1542': 'Invalid server security data.',
'1544': 'Internal timer error.',
'1796': 'Time-out occurred.',
'1798': 'Failed to unpack server certificate.',
'2052': 'Bad IP address specified.',
'2056': 'License negotiation failed.',
'2310': 'Internal security error.',
'2308': 'Socket closed.',
'2312': 'Licensing time-out.',
'2566': 'Internal security error.',
'2822': 'Encryption error.',
'3078': 'Decryption error.',
'3080': 'Decompression error.'
})
.controller('MainController', function ($scope, $window, $interval, Resolutions) {
$scope.Resolutions = Resolutions;
// create a clock
$scope.currentTime = new Date();
var clock = $interval(function () { $scope.currentTime = new Date(); }, 1000);
$scope.$on('$destroy', function () {
$interval.cancel(clock);
});
// use jQuery to load the settings because $http fails on local files
$scope.settings = null;
var settingsUrl = $window.location.search ? $window.location.search.substring(1) : $window.location.pathname + ".json";
$.getJSON(settingsUrl)
.done(function (data, textStatus, jqXHR) {
$scope.$apply(function () { $scope.settings = data });
})
.fail(function (jqXHR, textStatus, errorThrown) {
alert(settingsUrl + ': ' + errorThrown.message);
});
})
.controller('ViewerController', function ($scope, $document, $window, $element, $timeout, $log, $http, ConnectionState, DisconnectReasons) {
$scope.ConnectionState = ConnectionState;
// define the state variables
$scope.state = ConnectionState.Disconnected;
$scope.connection = null;
$scope.lastConnect = new Date();
$scope.lastError = null;
$scope.hovered = false;
$scope.isInfoShown = function () {
return $scope.hovered || $scope.state < ConnectionState.Establishing;
};
$scope.interact = function () {
$window.open($scope.computer + '/interact', '_blank', 'resizable=yes');
}
// initialize the viewer
var viewer = $element.find('object')[0];
viewer.SmartSizing = true;
// helper to shutdown the connection and schedule a reconnect
var endConnection = function (error) {
$scope.state = ConnectionState.Disconnected;
$scope.connection = null;
$scope.lastConnect = new Date();
$scope.lastError = error;
try { viewer.Disconnect(); }
catch (e) { }
$timeout(connect, $scope.settings.reconnect * 1000);
}
// connection helper
var connect = function () {
// only reconnect if disconnected
if ($scope.state != ConnectionState.Disconnected)
return;
// set the state, clear the last error and get the connection data
$scope.state = ConnectionState.Connecting;
$scope.lastError = null;
$http.get($scope.computer + '/connect', { withCredentials: true })
.then(function (response) {
// make sure we are still connecting
if ($scope.state != ConnectionState.Connecting)
return;
// set the new state and connection data
$scope.state = ConnectionState.Establishing;
$scope.connection = response.data;
// wait for the object to be shown and apparently some race condition
$timeout(function () {
// make sure we're still establishing the same connection before calling connect
if ($scope.state != ConnectionState.Establishing || $scope.connection != response.data)
return;
try { viewer.Connect(response.data.ConnectionString, response.data.AttendeeName, ''); }
catch (e) {
endConnection(e.message);
}
}, 500);
}, function (response) {
// make sure we are still connecting before ending this attempt
if ($scope.state != ConnectionState.Connecting)
return;
endConnection(response.statusText ? response.statusText : 'Connect error.');
});
};
// request view control when the connection is established
viewers['connectionEstablished' + $scope.$index] = function () {
$scope.$apply(function () {
if ($scope.state != ConnectionState.Establishing)
throw new Error('OnConnectionEstablished in state ' + $scope.state);
$scope.state = ConnectionState.Connected;
}, false);
};
// reset the state and try again if the connection failed
viewers['connectionFailed' + $scope.$index] = function () {
$scope.$apply(function () {
if ($scope.state != ConnectionState.Establishing)
throw new Error('OnConnectionFailed in state ' + $scope.state);
endConnection('Connection failed.');
});
};
viewers['connectionTerminated' + $scope.$index] = function (disconnectReason, extendedInfo) {
$scope.$apply(function () {
if ($scope.state != ConnectionState.Connected)
throw new Error('OnConnectionTerminated in state ' + $scope.state);
endConnection(DisconnectReasons[disconnectReason]);
});
};
// connect when ready
$document.ready(connect);
});
-->
</script>
</head>
<body style="padding: 0; margin: 0; font-family: Verdana, Geneva, sans-serif;">
<div style="overflow: auto;" ng-show="settings">
<input type="range" ng-model="settings.columns" min="1" max="10" style="width: 80%; padding: 0;" />
<select ng-model="settings.ratio" ng-options="(res.h/res.w) as (res.w+':'+res.h) for res in Resolutions" style="width: 15%; padding: 0; float: right;">
</select>
</div>
<div style="clear: both;">
<div ng-controller="ViewerController" ng-mouseenter="hovered = true" ng-mouseleave="hovered = false" ng-repeat="computer in settings.computers" style="float: left;" ng-style="{'width':(100/settings.columns)+'%','height':((100/settings.columns)*settings.ratio)+'vw'}">
<object id="computer{{$index}}" ng-hide="isInfoShown()" classid="clsid:32be5ed2-5c86-480f-a914-0ff8885a1b3f" width="100%" height="100%" style="margin: 0; padding: 0;"></object>
<script type="text/javascript" for="computer{{$index}}" event="OnConnectionEstablished()" ng-bind-template="{{'viewers.connectionEstablished'+$index+'();'}}"></script>
<script type="text/javascript" for="computer{{$index}}" event="OnConnectionFailed()" ng-bind-template="{{'viewers.connectionFailed'+$index+'();'}}"></script>
<script type="text/javascript" for="computer{{$index}}" event="OnConnectionTerminated(disconnectReason, extendedInfo)" ng-bind-template="{{'viewers.connectionTerminated'+$index+'(disconnectReason,extendedInfo);'}}"></script>
<script type="text/javascript" for="computer{{$index}}" event="OnConnectionAuthenticated()" ng-bind-template="{{'computer'+$index+'.RequestControl(2);'}}"></script>
<div ng-show="isInfoShown()" style="width: 100%; height: 100%; text-align: center; color: #000; background: #ccc; border: 1px solid black; box-sizing: border-box;">
<div style="position: relative; width: 100%; height: 20%; font-size: small; overflow: hidden;">
<span ng-show="state == ConnectionState.Disconnected">Disconnected. Retry in <b>{{settings.reconnect - ((currentTime - lastConnect) / 1000) | number: 0}}</b> seconds...</span>
<span ng-show="state == ConnectionState.Connecting">Retrieving connection data...</span>
<span ng-show="state == ConnectionState.Establishing">Establishing connection...</span>
<span ng-show="state == ConnectionState.Connected">Connected.</span>
</div>
<div style="position: relative; width: 100%; height: 60%; font-size: medium; overflow: hidden;">
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);">
<span ng-hide="connection"><b>{{computer}}</b></span>
<span ng-show="connection"><b>{{connection.DomainName}}</b><br /><b>{{connection.UserName}}</b><br />@<br /><b>{{connection.MachineName}}</b></span>
</div>
</div>
<div style="position: relative; width: 100%; height: 20%; font-size: small; color: #900; overflow: hidden;">
<span ng-show="lastError">{{lastError}}</span>
<button ng-show="connection" ng-click="interact()">Interact</button>
</div>
</div>
</div>
</div>
</body>
</html>